Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builds for windows and macOS #1648

Merged
merged 8 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,48 @@ jobs:

test-pypi:
needs: lint
name: test-${{ matrix.tox-env }} (Python${{ matrix.python-version }})
name: ${{ matrix.tox-env }} (Python${{ matrix.python-version }}, ${{ matrix.os }})
if: |
contains(github.event.pull_request.labels.*.name, 'approved') ||
(github.event.review.state == 'approved') ||
(github.event_name == 'push')
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Windows builds
- tox-env: py39-prefetch-coverage
python-version: "3.9"
markers: -m 'not slow'
os: windows-latest
# macOS builds
- tox-env: py310-coverage
python-version: "3.10"
markers: -m 'not slow'
os: macos-latest
# Linux builds
- tox-env: py39-coverage-sbck
python-version: "3.9"
markers: -m 'not slow'
os: ubuntu-latest
- tox-env: py310-coverage # No markers -- includes slow tests
python-version: "3.10"
os: ubuntu-latest
- tox-env: py311-coverage-sbck
python-version: "3.11"
markers: -m 'not slow'
os: ubuntu-latest
- tox-env: py312-coverage-numba
python-version: "3.12"
markers: -m 'not slow'
os: ubuntu-latest
- tox-env: notebooks_doctests
python-version: "3.10"
os: ubuntu-latest
- tox-env: offline-prefetch
python-version: "3.11"
markers: -m 'not slow and not requires_internet'
os: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
Expand Down Expand Up @@ -168,7 +185,7 @@ jobs:
python -m tox -e ${{ matrix.tox-env }} -- ${{ matrix.markers }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: run-{{ matrix.tox-env }}
COVERALLS_FLAG_NAME: run-{{ matrix.tox-env }}-{{ matrix.os }}
COVERALLS_PARALLEL: true
COVERALLS_SERVICE_NAME: github

Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Bug fixes
* Fix the daily case `freq='D'` of ``xclim.stats.preprocess_standardized_index`` (:issue:`1602` :pull:`1607`).
* Several spelling mistakes have been corrected within the documentation and codebase. (:pull:`1576`).
* Added missing ``xclim.ensembles.robustness_fractions`` and ``xclim.ensembles.robistness_categoris`` in api doc section. (:pull:`1630`).
* Fixed an issue that can occur when fetching the testing data and running tests on Windows systems. Adapted a few existing tests for Windows support. (:pull:`1648`).

Internal changes
^^^^^^^^^^^^^^^^
Expand All @@ -64,6 +65,8 @@ Internal changes
* Some small adjustments to code organization to address `pylint` errors.
* `dev` formatting tools (`black`, `blackdoc`, `isort`) are now pinned to their `pre-commit` hook version equivalents in both ``pyproject.toml`` and ``tox.ini``. (:pull:`1626`).
* `black`, `isort`, and `pyupgrade` code formatters no longer target Python3.8 coding style conventions. (:pull:`1565`).
* The GitHub Workflows now include builds to run tests against both Windows and MacOS. (:pull:`1648`).
* `prefetch` is now available as a `tox` environment modifier in order to download the testing data before launching `pytest` (e.g. `py3x-prefetch`). This is . (:pull:`1648`).

v0.47.0 (2023-12-01)
--------------------
Expand Down
17 changes: 13 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import re
import shutil
import sys
import time
import warnings
from datetime import datetime as dt
Expand Down Expand Up @@ -474,16 +475,24 @@ def gather_session_data(threadsafe_data_dir, worker_id, xdoctest_namespace):
):
if helpers.PREFETCH_TESTING_DATA:
print("`XCLIM_PREFETCH_TESTING_DATA` set. Prefetching testing data...")
if worker_id in "master":
if sys.platform == "win32":
raise OSError(
"UNIX-style file-locking is not supported on Windows. "
"Consider running `$ xclim prefetch_testing_data` to download testing data."
)
elif worker_id in ["master"]:
helpers.populate_testing_data(branch=helpers.TESTDATA_BRANCH)
else:
_default_cache_dir.mkdir(exist_ok=True, parents=True)
test_data_being_written = FileLock(_default_cache_dir.joinpath(".lock"))
with test_data_being_written as fl:
lockfile = _default_cache_dir.joinpath(".lock")
test_data_being_written = FileLock(lockfile)
with test_data_being_written:
# This flag prevents multiple calls from re-attempting to download testing data in the same pytest run
helpers.populate_testing_data(branch=helpers.TESTDATA_BRANCH)
_default_cache_dir.joinpath(".data_written").touch()
fl.acquire()
with test_data_being_written.acquire():
if lockfile.exists():
lockfile.unlink()
shutil.copytree(_default_cache_dir, threadsafe_data_dir)
helpers.generate_atmos(threadsafe_data_dir)
xdoctest_namespace.update(helpers.add_example_file_paths(threadsafe_data_dir))
Expand Down
7 changes: 6 additions & 1 deletion tests/test_testing_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import platform
import sys
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -100,7 +101,11 @@ def test_md5_sum(self):
test_data = Path(__file__).parent / "data"
callendar = test_data / "callendar_1938.txt"
md5_sum = utilities.file_md5_checksum(callendar)
assert md5_sum == "9a5d9f94d76d4f9d9b7aaadbe8cbf541" # noqa
if sys.platform == "win32":
# Windows has a different line ending (CR-LF) than Unix (LF)
assert md5_sum == "38083271c2d4c85dea6bd6baf23d34de" # noqa
else:
assert md5_sum == "9a5d9f94d76d4f9d9b7aaadbe8cbf541" # noqa


class TestReleaseSupportFuncs:
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ commands_pre =
python -m pip list
xclim show_version_info
python -m pip check
xclim --help
commands =
prefetch: xclim prefetch_testing_data
doctest: pytest --no-cov --rootdir=tests/ --xdoctest xclim
pytest {posargs}
commands_post =
Expand Down