From 5e401229316ef043766473e5cc3e3fe5bf338b78 Mon Sep 17 00:00:00 2001 From: blalterman Date: Thu, 5 Nov 2026 06:23:50 -0500 Subject: [PATCH 1/8] ci: test on Windows in PR CI and the release platform matrix Add a test-windows job to continuous-integration.yml that runs the test suite on windows-latest (Python 3.12) for every pull request, and report its result in ci-summary. Lint, import layering, and the release build stay on the Linux validate job, which is unchanged. Add windows-latest to publish.yml's platform-matrix and run its steps under bash so the same scripts work on every runner. PyHC standard #4 asks packages to support all major operating systems. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/continuous-integration.yml | 35 ++++++++++++++++++-- .github/workflows/publish.yml | 8 +++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1801a13a0..fccdaf22a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -70,9 +70,39 @@ jobs: python -m build --outdir dist python scripts/check_release_artifacts.py dist + # Test suite on Windows (PyHC standard #4: support all major operating systems). + # Lint, import layering, and the release build stay on the Linux validate job. + test-windows: + runs-on: windows-latest + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v7 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: pip + cache-dependency-path: pyproject.toml + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -e ".[dev]" + # tests/test_release_artifacts.py builds with --no-isolation and needs these + python -m pip install build setuptools_scm wheel + + - name: Run core tests + run: | + pytest --tb=short --disable-warnings tests/ + # Summary job ci-summary: - needs: [validate] + needs: [validate, test-windows] runs-on: ubuntu-latest if: always() @@ -85,8 +115,9 @@ jobs: echo "" echo "Job Results:" echo "- Quick Validation: ${{ needs.validate.result }}" + echo "- Windows Tests: ${{ needs.test-windows.result }}" echo "" - if [[ "${{ needs.validate.result }}" == "success" ]]; then + if [[ "${{ needs.validate.result }}" == "success" && "${{ needs.test-windows.result }}" == "success" ]]; then echo "✅ PR validation passed - ready for review" else echo "❌ PR validation failed - requires fixes" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4f1d920f8..debadc5cc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,15 +21,19 @@ on: type: boolean jobs: - # Release gate: the full suite on every declared Python, on Linux and macOS. + # Release gate: the full suite on every declared Python, on Linux, macOS, and Windows. # build-and-publish needs it, so nothing is built or uploaded unless every cell passes. platform-matrix: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ['3.12', '3.13', '3.14'] fail-fast: false + # Every run step is bash, so the same scripts work on the Windows runner. + defaults: + run: + shell: bash steps: - uses: actions/checkout@v7 From 1fe32d9353476dca2843a467377a9fdff40389eb Mon Sep 17 00:00:00 2001 From: blalterman Date: Thu, 5 Nov 2026 06:39:44 -0500 Subject: [PATCH 2/8] test: read repository files as UTF-8 in test_declared_versions On Windows the default encoding is cp1252, so reading workflows that contain emoji raised UnicodeDecodeError. Co-Authored-By: Claude Opus 5.5 --- tests/test_declared_versions.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/test_declared_versions.py b/tests/test_declared_versions.py index af27771b0..232012c0c 100644 --- a/tests/test_declared_versions.py +++ b/tests/test_declared_versions.py @@ -30,7 +30,9 @@ def _requires_python(): - pyproject = tomllib.loads((REPO_ROOT / "pyproject.toml").read_text()) + pyproject = tomllib.loads( + (REPO_ROOT / "pyproject.toml").read_text(encoding="utf-8") + ) return pyproject["project"]["requires-python"] @@ -62,25 +64,29 @@ def declared_python_versions(): """Return ``(site, version)`` for every Python version the repo declares.""" found = [] - pyproject = tomllib.loads((REPO_ROOT / "pyproject.toml").read_text()) + pyproject = tomllib.loads( + (REPO_ROOT / "pyproject.toml").read_text(encoding="utf-8") + ) for c in pyproject["project"]["classifiers"]: m = re.fullmatch(r"Programming Language :: Python :: (3\.\d+)", c) if m: found.append(("pyproject.toml: classifiers", m.group(1))) - tox = (REPO_ROOT / "tox.ini").read_text() + tox = (REPO_ROOT / "tox.ini").read_text(encoding="utf-8") envlist = re.search(r"^envlist\s*=\s*(.+)$", tox, re.MULTILINE).group(1) for major, minor in re.findall(r"py(\d)(\d+)", envlist): found.append(("tox.ini: envlist", f"{major}.{minor}")) - rtd = yaml.safe_load((REPO_ROOT / ".readthedocs.yaml").read_text()) + rtd = yaml.safe_load((REPO_ROOT / ".readthedocs.yaml").read_text(encoding="utf-8")) found.append( (".readthedocs.yaml: build.tools.python", str(rtd["build"]["tools"]["python"])) ) for wf in sorted((REPO_ROOT / ".github" / "workflows").glob("*.yml")): _workflow_versions( - yaml.safe_load(wf.read_text()), f".github/workflows/{wf.name}", found + yaml.safe_load(wf.read_text(encoding="utf-8")), + f".github/workflows/{wf.name}", + found, ) return found From 779a6f59ac3503305fa7219c7bd733fa8b030c2d Mon Sep 17 00:00:00 2001 From: blalterman Date: Thu, 5 Nov 2026 06:42:11 -0500 Subject: [PATCH 3/8] test: make four tests portable to Windows - test_commit_message_hook: resolve bash with shutil.which. A bare "bash" makes Windows search System32 before PATH and run the WSL launcher, which cannot open the Windows path to the message file. - test_cache: also point USERPROFILE at the fake home. Path.home() on Windows reads USERPROFILE and ignores HOME. - test_elemental_abundance: compare the path to Path("C/N-OV-H") rather than checking str(path) for a forward slash, which Windows renders as a backslash. The path is the same on every OS. - test_p0_contract: keep SYSTEMROOT in the python -O probe's environment, which Windows processes need to start, and assert on the return code with the child's stderr as the message instead of hiding it behind check=True. Co-Authored-By: Claude Opus 5.5 --- tests/fitfunctions/test_p0_contract.py | 9 +++++++-- tests/plotting/labels/test_elemental_abundance.py | 4 ++-- tests/solar_activity/test_cache.py | 4 +++- tests/test_commit_message_hook.py | 12 +++++++++--- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/fitfunctions/test_p0_contract.py b/tests/fitfunctions/test_p0_contract.py index 1d35a8584..8e1138520 100644 --- a/tests/fitfunctions/test_p0_contract.py +++ b/tests/fitfunctions/test_p0_contract.py @@ -13,6 +13,7 @@ import contextlib import inspect import logging +import os import re import subprocess import sys @@ -244,13 +245,17 @@ def test_insufficient_data_check_survives_python_O(tmp_path): " print('no error')\n" ) root = Path(solarwindpy.__file__).resolve().parents[1] + env = {"PYTHONPATH": str(root), "PATH": ""} + # Windows processes need SYSTEMROOT to start, e.g. to load system DLLs. + if "SYSTEMROOT" in os.environ: + env["SYSTEMROOT"] = os.environ["SYSTEMROOT"] out = subprocess.run( [sys.executable, "-O", str(script)], capture_output=True, text=True, - env={"PYTHONPATH": str(root), "PATH": ""}, - check=True, + env=env, ) + assert out.returncode == 0, out.stderr assert out.stdout.strip() == "raised", out.stdout + out.stderr diff --git a/tests/plotting/labels/test_elemental_abundance.py b/tests/plotting/labels/test_elemental_abundance.py index 1db3762ba..5dff6f052 100644 --- a/tests/plotting/labels/test_elemental_abundance.py +++ b/tests/plotting/labels/test_elemental_abundance.py @@ -165,8 +165,8 @@ def test_path_special_characters(self): warnings.simplefilter("ignore") abundance = ElementalAbundance("C/N", "H", photospheric=False) path = abundance.path - # Path should contain separator - assert "C/N-OV-H" in str(path) + # The "/" in the species becomes a path separator on every OS. + assert path == Path("C/N-OV-H") class TestElementalAbundanceSetMethods: diff --git a/tests/solar_activity/test_cache.py b/tests/solar_activity/test_cache.py index d9219fc0b..8bf22ec9b 100644 --- a/tests/solar_activity/test_cache.py +++ b/tests/solar_activity/test_cache.py @@ -266,7 +266,8 @@ def snapshot(): def test_a_first_run_on_a_clean_home_creates_the_cache(tmp_path, monkeypatch): """With no cache folder yet, the first fetch creates ``~/.cache/solarwindpy``. - Chosen input: HOME is an empty directory under ``tmp_path`` and + Chosen input: HOME (USERPROFILE on Windows) is an empty directory under + ``tmp_path`` and ``XDG_CACHE_HOME`` is unset, so astropy (8 or later) resolves the default location and must create every level of it. @@ -285,6 +286,7 @@ def test_a_first_run_on_a_clean_home_creates_the_cache(tmp_path, monkeypatch): home = tmp_path / "home" home.mkdir() monkeypatch.setenv("HOME", str(home)) + monkeypatch.setenv("USERPROFILE", str(home)) # Path.home() on Windows monkeypatch.delenv("XDG_CACHE_HOME", raising=False) expected = home / ".cache" / "solarwindpy" assert get_cache_dir_path("solarwindpy", ensure_exists=False) == expected diff --git a/tests/test_commit_message_hook.py b/tests/test_commit_message_hook.py index ba84e54e1..bf880143d 100644 --- a/tests/test_commit_message_hook.py +++ b/tests/test_commit_message_hook.py @@ -2,6 +2,7 @@ # Supersedes: none """The commit-msg hook accepts every Conventional Commits form the project uses.""" +import shutil import subprocess from pathlib import Path @@ -12,12 +13,17 @@ ) +# Resolve bash on PATH. A bare "bash" makes Windows search System32 before +# PATH and run the WSL launcher, which cannot see this Windows path. +BASH = shutil.which("bash") + + def _check(tmp_path, message): + if BASH is None: + pytest.skip("bash is not on PATH") msg = tmp_path / "COMMIT_EDITMSG" msg.write_text(message) - return subprocess.run( - ["bash", str(SCRIPT), str(msg)], capture_output=True - ).returncode + return subprocess.run([BASH, str(SCRIPT), str(msg)], capture_output=True).returncode @pytest.mark.parametrize( From 7ba37ed6c11a2721b659a640c94402386a8e45c7 Mon Sep 17 00:00:00 2001 From: blalterman Date: Thu, 5 Nov 2026 06:53:37 -0500 Subject: [PATCH 4/8] test: let the python -O probe inherit the environment The probe ran with a hand-built environment of PYTHONPATH and PATH (plus SYSTEMROOT after the previous fix). On Windows, Path.home() needs USERPROFILE, and astropy calls it on import, so the child failed with "RuntimeError: Could not determine home directory." Inherit os.environ and override only PYTHONPATH, so the probe still imports this checkout. Co-Authored-By: Claude Opus 5.5 --- tests/fitfunctions/test_p0_contract.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/fitfunctions/test_p0_contract.py b/tests/fitfunctions/test_p0_contract.py index 8e1138520..1932ae892 100644 --- a/tests/fitfunctions/test_p0_contract.py +++ b/tests/fitfunctions/test_p0_contract.py @@ -245,10 +245,9 @@ def test_insufficient_data_check_survives_python_O(tmp_path): " print('no error')\n" ) root = Path(solarwindpy.__file__).resolve().parents[1] - env = {"PYTHONPATH": str(root), "PATH": ""} - # Windows processes need SYSTEMROOT to start, e.g. to load system DLLs. - if "SYSTEMROOT" in os.environ: - env["SYSTEMROOT"] = os.environ["SYSTEMROOT"] + # Inherit the environment: Windows needs SYSTEMROOT to start a process and + # USERPROFILE for Path.home(), which astropy calls on import. + env = {**os.environ, "PYTHONPATH": str(root)} out = subprocess.run( [sys.executable, "-O", str(script)], capture_output=True, From ca52f19d67e44cf472b7cded88d5a98c41c375b3 Mon Sep 17 00:00:00 2001 From: blalterman Date: Thu, 5 Nov 2026 07:09:47 -0500 Subject: [PATCH 5/8] test(solar_activity): age must not depend on when the clock is read DataLoader.age computes now() - ctime, and ctime reads now() again after looking up the cache, so age falls short by the time between the two reads. This is why test_age_is_the_time_since_the_cache_was_written failed by microseconds on Linux (7.5 us) and Windows (0.3 us). The new test fakes the clock to advance one minute per read, which makes the shortfall deterministic. Marked xfail(strict=True, raises=AgeShortError) until the fix lands. Verified: xfails as committed; with the fix applied transiently it fails as XPASS(strict); with an unrelated assert False injected it is reported FAILED, not xfailed. Co-Authored-By: Claude Opus 5.5 --- tests/solar_activity/test_base.py | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/solar_activity/test_base.py b/tests/solar_activity/test_base.py index 923ee189d..a0c324292 100644 --- a/tests/solar_activity/test_base.py +++ b/tests/solar_activity/test_base.py @@ -260,6 +260,44 @@ def test_age_is_the_time_since_the_cache_was_written(remote): assert pd.Timedelta(days=5) <= loader.age < pd.Timedelta(days=5, minutes=1) +class AgeShortError(AssertionError): + """``age`` came out shorter than the cached copy's age.""" + + +@pytest.mark.xfail( + strict=True, + raises=AgeShortError, + reason="DataLoader.age (solar_activity/base.py) reads the clock before " + "ctime reads it again, so age falls short by the time between the reads; " + "expected 'age ... is shorter than five days'; remove this marker when " + "age is a single reading of the cached copy's age", +) +def test_age_does_not_depend_on_when_the_clock_is_read(remote, monkeypatch): + """``age`` is the cached copy's age, however the wall clock moves while it is read. + + Chosen input: the cached copy is moved five days back, then the clock + (``pd.Timestamp.now``, a clock boundary) is faked to advance one minute on + every read. An age assembled from two clock reads comes out a minute + short; the cached copy is still at least five days old. + + ON FAILURE: the code is wrong. + """ + CacheLoader.DOWNLOADED.to_csv(remote) + loader = CacheLoader("daily", remote.as_uri()) + loader.load_data() + backdate(loader.url, 5) + clock = {"now": pd.Timestamp.now()} + + def advancing_now(tz=None): + clock["now"] += pd.Timedelta(minutes=1) + return clock["now"] + + monkeypatch.setattr(pd.Timestamp, "now", staticmethod(advancing_now)) + age = loader.age + if age < pd.Timedelta(days=5): + raise AgeShortError(f"age {age} is shorter than five days") + + def test_load_data_downloads_again_when_the_cache_is_stale(remote): """A cached copy older than ``max_age`` is replaced by a new download. From 42f9f922a195990c3e60e96e49605a66846120f4 Mon Sep 17 00:00:00 2001 From: blalterman Date: Thu, 5 Nov 2026 07:12:09 -0500 Subject: [PATCH 6/8] fix(solar_activity): read DataLoader.age from the cache in one step age returned now() - ctime, and ctime looked up the cache and read now() again, so age fell short by the time between the two reads. age now returns the cached copy's age directly (cache.cached_age), and the time since 1970 when nothing is cached, as before. Before: test_age_does_not_depend_on_when_the_clock_is_read xfailed (AgeShortError: age one minute short under a clock advancing a minute per read). After: it passes, the xfail marker is removed, and the solar_activity tests pass (322 passed, 8 skipped). Co-Authored-By: Claude Opus 5.5 --- src/solarwindpy/solar_activity/base.py | 7 ++++++- tests/solar_activity/test_base.py | 8 -------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/solarwindpy/solar_activity/base.py b/src/solarwindpy/solar_activity/base.py index 1aaf00e20..fcd22005d 100644 --- a/src/solarwindpy/solar_activity/base.py +++ b/src/solarwindpy/solar_activity/base.py @@ -191,7 +191,12 @@ def ctime(self): @property def age(self): r"""Time since :attr:`ctime`.""" - return pd.Timestamp.now() - self.ctime + # One reading of the cached copy's age. Subtracting ctime from a + # separate now() falls short by the time spent computing ctime. + age = cache.cached_age(self.url) + if age is None: + return pd.Timestamp.now() - pd.to_datetime(0) + return age def set_key(self, key): r"""Set :attr:`key`.""" diff --git a/tests/solar_activity/test_base.py b/tests/solar_activity/test_base.py index a0c324292..d8b8a980c 100644 --- a/tests/solar_activity/test_base.py +++ b/tests/solar_activity/test_base.py @@ -264,14 +264,6 @@ class AgeShortError(AssertionError): """``age`` came out shorter than the cached copy's age.""" -@pytest.mark.xfail( - strict=True, - raises=AgeShortError, - reason="DataLoader.age (solar_activity/base.py) reads the clock before " - "ctime reads it again, so age falls short by the time between the reads; " - "expected 'age ... is shorter than five days'; remove this marker when " - "age is a single reading of the cached copy's age", -) def test_age_does_not_depend_on_when_the_clock_is_read(remote, monkeypatch): """``age`` is the cached copy's age, however the wall clock moves while it is read. From 7c4715006ca7d3659428d99f948f90ec5e52ef34 Mon Sep 17 00:00:00 2001 From: blalterman Date: Thu, 5 Nov 2026 07:23:54 -0500 Subject: [PATCH 7/8] ci: fail ci-summary when a job fails; time-limit the Windows job ci-summary printed "validation failed" but always exited 0, so it showed green while validate or test-windows were red. It now exits 1 on failure. test-windows gets timeout-minutes: 30 (the suite takes about 2 minutes), so a hung test fails fast instead of running for GitHub's 6-hour default. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/continuous-integration.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index fccdaf22a..e61a89f73 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -74,6 +74,9 @@ jobs: # Lint, import layering, and the release build stay on the Linux validate job. test-windows: runs-on: windows-latest + # The suite takes about 2 minutes here; bound a hung test well below + # GitHub's 6-hour default. + timeout-minutes: 30 defaults: run: shell: bash @@ -121,4 +124,5 @@ jobs: echo "✅ PR validation passed - ready for review" else echo "❌ PR validation failed - requires fixes" + exit 1 fi From 99858565778e3cef2a45e04dedec0aed4225560e Mon Sep 17 00:00:00 2001 From: blalterman Date: Thu, 5 Nov 2026 07:30:34 -0500 Subject: [PATCH 8/8] ci(publish): use setup-python's pip cache; run the artifact test The platform-matrix cached ~/.cache/pip, which is pip's cache only on Linux, so the cache did nothing on macOS and Windows. Use setup-python's cache: pip, which finds the right directory on each OS. Install build, setuptools_scm and wheel so tests/test_release_artifacts.py runs in the release gate instead of skipping on every OS. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index debadc5cc..d224c43a7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,14 +43,10 @@ jobs: - uses: actions/setup-python@v7 with: python-version: ${{ matrix.python-version }} - - - uses: actions/cache@v6 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} - restore-keys: | - ${{ runner.os }}-pip-${{ matrix.python-version }}- - ${{ runner.os }}-pip- + # setup-python finds pip's cache directory on each OS; ~/.cache/pip + # is not it on macOS or Windows. + cache: pip + cache-dependency-path: pyproject.toml - name: Install system dependencies (Linux) if: runner.os == 'Linux' @@ -66,6 +62,9 @@ jobs: run: | python -m pip install --upgrade pip pip install -e ".[dev]" + # tests/test_release_artifacts.py builds with --no-isolation and + # skips without these, so install them to run it in the release gate. + pip install build setuptools_scm wheel - name: Run comprehensive tests run: |