From 72d00db1a5ee6959d4c2472f8c486e12cfd5fe55 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Fri, 16 Oct 2026 13:16:50 -0700 Subject: [PATCH 1/3] fix: use workspace harness in Python version matrix --- .github/workflows/python_matrix.yml | 66 ++++++++++++------------- tests/test_python_matrix_workflow.py | 73 ++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 36 deletions(-) diff --git a/.github/workflows/python_matrix.yml b/.github/workflows/python_matrix.yml index 7ac828a5..c3b25f77 100644 --- a/.github/workflows/python_matrix.yml +++ b/.github/workflows/python_matrix.yml @@ -44,6 +44,8 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install libraries (single combined install — all 5 local) + env: + PYTHON_VERSION: ${{ matrix.python-version }} run: | python -m pip install --upgrade pip wheel # Pass all 5 libs in ONE pip invocation so the resolver knows about @@ -52,12 +54,16 @@ jobs: # and pip backtracks through the entire PyPI release history of # autogalaxy looking for one whose nautilus-sampler pin matches # the local autolens — which never matches because PyPI is stale. + optional="" + if [ "$PYTHON_VERSION" = "3.12" ]; then + optional="[optional]" + fi pip install \ -e ./PyAutoNerves \ - -e "./PyAutoArray[optional]" \ + -e "./PyAutoArray${optional}" \ -e ./PyAutoFit \ -e ./PyAutoGalaxy \ - -e "./PyAutoLens[optional]" + -e "./PyAutoLens${optional}" pip install pytest pytest-cov # Show final installed versions for diagnosis pip list | grep -iE "^(autonerves|autoarray|autofit|autogalaxy|autolens|jax|numpy|scipy|nautilus)" @@ -81,13 +87,14 @@ jobs: - { repo: PyAutoLabs/autogalaxy_workspace, path: autogalaxy_workspace } - { repo: PyAutoLabs/autolens_workspace, path: autolens_workspace } env: - PYAUTO_TEST_MODE: "1" - PYAUTO_SMALL_DATASETS: "1" - PYAUTO_FAST_PLOTS: "1" NUMBA_CACHE_DIR: /tmp/numba_cache MPLCONFIGDIR: /tmp/matplotlib JAX_ENABLE_X64: "True" steps: + - name: Checkout Hands harness + uses: actions/checkout@v4 + with: + path: PyAutoHands - uses: actions/checkout@v4 with: { repository: PyAutoLabs/PyAutoNerves, path: PyAutoNerves } - uses: actions/checkout@v4 @@ -103,41 +110,28 @@ jobs: - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Install libraries (single combined install — all 5 local) + - name: Install workspace smoke environment + env: + PYTHON_VERSION: ${{ matrix.python-version }} + WORKSPACE_PATH: ${{ matrix.workspace.path }} run: | python -m pip install --upgrade pip wheel - pip install \ - -e ./PyAutoNerves \ - -e "./PyAutoArray[optional]" \ - -e "./PyAutoFit[optional]" \ - -e ./PyAutoGalaxy \ - -e "./PyAutoLens[optional]" - pip install numba - pip list | grep -iE "^(autonerves|autoarray|autofit|autogalaxy|autolens|jax|numpy|scipy|nautilus)" + python -m pip install pyyaml + bash "$WORKSPACE_PATH/.github/scripts/smoke_install.sh" - name: Run smoke tests + env: + WORKSPACE_PATH: ${{ matrix.workspace.path }} + PYTHONPATH: ${{ github.workspace }}/PyAutoHands/autohands run: | - cd ${{ matrix.workspace.path }} - if [ ! -f smoke_tests.txt ]; then - echo "No smoke_tests.txt found in ${{ matrix.workspace.path }} -- skipping" - exit 0 - fi - fail=0 - while IFS= read -r script || [ -n "$script" ]; do - [ -z "$script" ] && continue - case "$script" in \#*) continue ;; esac - echo "::group::$script" - if python "scripts/$script"; then - echo "PASS: $script" - else - echo "FAIL: $script" - fail=$((fail + 1)) - fi - echo "::endgroup::" - done < smoke_tests.txt - if [ "$fail" -gt 0 ]; then - echo "$fail smoke test(s) failed" - exit 1 - fi + cd "$WORKSPACE_PATH" + python .github/scripts/run_smoke.py --report-dir test-results + - name: Upload smoke report + if: always() + uses: actions/upload-artifact@v4 + with: + name: python-matrix-${{ matrix.workspace.path }}-${{ matrix.python-version }} + path: ${{ matrix.workspace.path }}/test-results/ + if-no-files-found: warn summary: runs-on: ubuntu-latest diff --git a/tests/test_python_matrix_workflow.py b/tests/test_python_matrix_workflow.py index 3b055bed..d7ada157 100644 --- a/tests/test_python_matrix_workflow.py +++ b/tests/test_python_matrix_workflow.py @@ -1,4 +1,8 @@ from pathlib import Path +import json +import os +import subprocess +import sys import yaml @@ -123,3 +127,72 @@ def test_declared_session_deps_are_the_ones_the_code_actually_reaches_for(): declared = _declared_session_deps() assert "pillow" in declared, "generate_markdown imports PIL" assert "ipynb-py-convert" in declared, "build_util shells out to it" + + +def _matrix_step(job, name): + return next(s for s in load_workflow()["jobs"][job]["steps"] if s.get("name") == name) + + +def test_matrix_smoke_uses_workspace_profile_and_branch_harness(): + job = load_workflow()["jobs"]["smoke_tests"] + assert not {"PYAUTO_TEST_MODE", "PYAUTO_SMALL_DATASETS", "PYAUTO_FAST_PLOTS"} & job["env"].keys() + checkout = _matrix_step("smoke_tests", "Checkout Hands harness") + assert checkout["with"] == {"path": "PyAutoHands"} + runner = _matrix_step("smoke_tests", "Run smoke tests") + assert runner["env"]["PYTHONPATH"] == "${{ github.workspace }}/PyAutoHands/autohands" + assert "continue-on-error" not in runner + upload = _matrix_step("smoke_tests", "Upload smoke report") + assert upload["if"] == "always()" + assert "matrix.workspace.path" in upload["with"]["name"] + assert "matrix.python-version" in upload["with"]["name"] + + +def test_matrix_harness_runs_in_workspace_and_propagates_failure(tmp_path): + workspace = tmp_path / "workspace with spaces" + scripts = workspace / ".github" / "scripts" + scripts.mkdir(parents=True) + (scripts / "run_smoke.py").write_text( + "import os, pathlib, sys\n" + "assert pathlib.Path.cwd().name == 'workspace with spaces'\n" + "assert sys.argv[1:] == ['--report-dir', 'test-results']\n" + "assert os.environ['PYTHONPATH'].endswith('/PyAutoHands/autohands')\n" + "pathlib.Path('test-results').mkdir(exist_ok=True)\n" + "sys.exit(int(os.environ['RUNNER_RC']))\n" + ) + env = dict(os.environ, WORKSPACE_PATH=str(workspace), + PYTHONPATH=str(tmp_path / "PyAutoHands/autohands")) + env["PATH"] = str(Path(sys.executable).parent) + os.pathsep + env["PATH"] + for rc in (0, 7): + env["RUNNER_RC"] = str(rc) + run = subprocess.run(["bash", "-e", "-c", _matrix_step("smoke_tests", "Run smoke tests")["run"]], + cwd=tmp_path, env=env, capture_output=True, text=True) + assert run.returncode == rc, run.stderr + assert (workspace / "test-results").is_dir() + + +def test_unit_optional_extras_follow_python_version(tmp_path): + bindir = tmp_path / "bin" + bindir.mkdir() + # Record argv while executing the actual workflow shell; no install occurs. + stub = f"#!{sys.executable}\n" + ( + "import json, os, sys\n" + "with open(os.environ['PIP_LOG'], 'a') as f: f.write(json.dumps(sys.argv[1:]) + '\\n')\n" + "if 'list' in sys.argv: print('autofit 9999.0.0')\n" + ) + for name in ("pip", "python"): + path = bindir / name + path.write_text(stub) + path.chmod(0o755) + step = _matrix_step("unit_tests", "Install libraries (single combined install — all 5 local)") + assert step["env"]["PYTHON_VERSION"] == "${{ matrix.python-version }}" + for version in ("3.12", "3.13", "3.14"): + log = tmp_path / f"{version}.jsonl" + env = dict(os.environ, PATH=str(bindir) + os.pathsep + os.environ["PATH"], + PYTHON_VERSION=version, PIP_LOG=str(log)) + subprocess.run(["bash", "-e", "-c", step["run"]], cwd=tmp_path, env=env, check=True, capture_output=True) + calls = [json.loads(line) for line in log.read_text().splitlines()] + install = next(c for c in calls if "-e" in c) + optional = "[optional]" if version == "3.12" else "" + for repo in ("PyAutoArray", "PyAutoLens"): + assert f"./{repo}{optional}" in install + assert install.count("-e") == 5 From 148afbdc9df411b31631e9f82477569815b68f15 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Fri, 16 Oct 2026 13:18:33 -0700 Subject: [PATCH 2/3] test: keep matrix assertions free of instance names --- tests/test_python_matrix_workflow.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_python_matrix_workflow.py b/tests/test_python_matrix_workflow.py index d7ada157..5b2731b3 100644 --- a/tests/test_python_matrix_workflow.py +++ b/tests/test_python_matrix_workflow.py @@ -192,7 +192,6 @@ def test_unit_optional_extras_follow_python_version(tmp_path): subprocess.run(["bash", "-e", "-c", step["run"]], cwd=tmp_path, env=env, check=True, capture_output=True) calls = [json.loads(line) for line in log.read_text().splitlines()] install = next(c for c in calls if "-e" in c) - optional = "[optional]" if version == "3.12" else "" - for repo in ("PyAutoArray", "PyAutoLens"): - assert f"./{repo}{optional}" in install + extras = [arg for arg in install if arg.endswith("[optional]")] + assert len(extras) == (2 if version == "3.12" else 0) assert install.count("-e") == 5 From a016d4952780bd143f69ffbdda54996d76163ece Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Fri, 16 Oct 2026 13:46:41 -0700 Subject: [PATCH 3/3] fix: install unit matrix numba and Zeus dependencies on all Python versions --- .github/workflows/python_matrix.yml | 4 +++- tests/test_python_matrix_workflow.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python_matrix.yml b/.github/workflows/python_matrix.yml index c3b25f77..e9302c3c 100644 --- a/.github/workflows/python_matrix.yml +++ b/.github/workflows/python_matrix.yml @@ -58,7 +58,9 @@ jobs: if [ "$PYTHON_VERSION" = "3.12" ]; then optional="[optional]" fi - pip install \ + # Unit tests exercise numba inversions and Zeus on every supported + # Python. Keep these outside the broad extras (tfp/dm-tree constraint). + pip install numba zeus-mcmc==2.5.4 \ -e ./PyAutoNerves \ -e "./PyAutoArray${optional}" \ -e ./PyAutoFit \ diff --git a/tests/test_python_matrix_workflow.py b/tests/test_python_matrix_workflow.py index 5b2731b3..222c7e0a 100644 --- a/tests/test_python_matrix_workflow.py +++ b/tests/test_python_matrix_workflow.py @@ -195,3 +195,5 @@ def test_unit_optional_extras_follow_python_version(tmp_path): extras = [arg for arg in install if arg.endswith("[optional]")] assert len(extras) == (2 if version == "3.12" else 0) assert install.count("-e") == 5 + assert "numba" in install + assert "zeus-mcmc==2.5.4" in install