diff --git a/.github/workflows/integration-test-r.yml b/.github/workflows/integration-test-r.yml index 6cbb97d..0603c77 100644 --- a/.github/workflows/integration-test-r.yml +++ b/.github/workflows/integration-test-r.yml @@ -15,6 +15,10 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +defaults: + run: + shell: bash + jobs: test: strategy: diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 906f7ba..fecc0fd 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -12,36 +12,37 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +defaults: + run: + shell: bash + jobs: + get-packages: + runs-on: ubuntu-slim + outputs: + packages: ${{ steps.get-packages.outputs.packages }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + filter: blob:none + - name: Get packages to tes + id: get-packages + run: | + PKGS=$(cat packages.json | jq -c) + echo "packages=$PKGS" | tee $GITHUB_OUTPUT + test: + needs: get-packages strategy: fail-fast: false matrix: python: ["3.13", "3.14"] is_pre: [true, false] - package: - # extras should be a comma seperated list of strings, like `extras: "lazy,accelerated"` - # The 'test' extra is always installed - - {name: "mudata", extras: ""} - - {name: "spatialdata", extras: ""} - - {name: "scirpy", extras: ""} - - {name: "muon", extras: ""} - - {name: "scanpy", extras: "scanpy2"} - - {name: "squidpy", extras: ""} - - {name: "scvi-tools", extras: "optional"} - - {name: "pertpy", extras: "de,tcoda"} - - {name: "decoupler", extras: ""} - - {name: "SnapATAC2", extras: ""} - - {name: "rapids-singlecell", extras: "rapids-cu13", gpu: true} - - {name: "liana", extras: "extras"} - - {name: "PyDESeq2", extras: ""} + package: ${{ fromJSON(needs.get-packages.outputs.packages) }} exclude: - { python: "3.13", is_pre: true } - defaults: - run: - shell: bash -leo pipefail {0} - runs-on: ${{ matrix.package.gpu && format('cirun-aws-gpu--{0}', github.run_id) || 'ubuntu-latest' }} steps: @@ -86,29 +87,13 @@ jobs: with: workspaces: ${{ matrix.package.name }} - - name: Install toml parsers - run: | - uv pip install --system toml-cli - - - name: Install AnnData and scverse package + - name: Install scverse package and dependencies env: UV_EXTRA_INDEX_URL: ${{ matrix.package.gpu && 'https://pypi.nvidia.com' || '' }} - run: | - EXTRAS="" - GROUP="" - if toml get 'dependency-groups.test' --toml-path pyproject.toml > /dev/null; then - GROUP="--group test" - if [ -n "${{ matrix.package.extras }}" ]; then - EXTRAS="${{ matrix.package.extras }}" - fi - else - if [ -n "${{ matrix.package.extras }}" ]; then - EXTRAS="test,${{ matrix.package.extras }}" - else - EXTRAS="test" - fi - fi - uv pip install ${{ matrix.is_pre && '--prerelease allow' || '' }} --compile --system ".[$EXTRAS]" git+https://github.com/scverse/anndata -c ../integration-testing/constraints.txt ${{ matrix.is_pre && '--override ../integration-testing/overrides.txt' || ''}} $GROUP -v + PACKAGE: ${{ matrix.package.name }} + EXTRAS: ${{ toJSON(matrix.package.extras) }} + IS_PRE: ${{ matrix.is_pre }} + run: python ../integration-testing/scripts/install.py working-directory: ${{ matrix.package.name }} - name: Set failure type for install @@ -162,7 +147,6 @@ jobs: - name: Re-enable workflow env: GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN || github.token }} - shell: sh run: | for WORKFLOW in integration-test.yml integration-test-r.yml; do gh api --verbose -X PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/${WORKFLOW}/enable" diff --git a/overrides.txt b/overrides.txt deleted file mode 100644 index 789f724..0000000 --- a/overrides.txt +++ /dev/null @@ -1 +0,0 @@ -pandas>=3 \ No newline at end of file diff --git a/packages.json b/packages.json new file mode 100644 index 0000000..934591d --- /dev/null +++ b/packages.json @@ -0,0 +1,15 @@ +[ + {"name": "mudata"}, + {"name": "spatialdata"}, + {"name": "scirpy"}, + {"name": "muon"}, + {"name": "scanpy", "extras": ["scanpy2"]}, + {"name": "squidpy"}, + {"name": "scvi-tools", "extras": ["optional"]}, + {"name": "pertpy", "extras": ["de", "tcoda"]}, + {"name": "decoupler"}, + {"name": "SnapATAC2"}, + {"name": "rapids-singlecell", "extras": ["rapids-cu13"], "gpu": true}, + {"name": "liana", "extras": ["extras"]}, + {"name": "PyDESeq2"} +] diff --git a/scripts/install.py b/scripts/install.py new file mode 100644 index 0000000..ecd5cec --- /dev/null +++ b/scripts/install.py @@ -0,0 +1,55 @@ +"""Install the scverse package checked out in the current directory, with its test dependencies. + +Inputs (environment variables): +- ``PACKAGE``: the package's name, as in ``packages.json`` +- ``EXTRAS``: JSON list of extras to install (or ``null``) +- ``IS_PRE``: ``true`` to test against pre-releases and the scverse packages' ``main`` branches +""" + +import json +import os +import subprocess +import sys +import tomllib +from pathlib import Path +from tempfile import TemporaryDirectory + +ROOT = Path(__file__).parent.parent + +# always installed from their main branch +DATASTRUCTURES = ("anndata", "mudata", "spatialdata") +# overrides when testing pre-releases +OVERRIDES_PRE = ("pandas>=3",) + +package = os.environ["PACKAGE"] +extras_matrix: tuple[str, ...] = tuple(json.loads(os.environ.get("EXTRAS") or "null") or ()) +is_pre = os.environ.get("IS_PRE") == "true" + +pyproject = tomllib.loads(Path("pyproject.toml").read_text()) +has_test_group = "test" in pyproject.get("dependency-groups", {}) +extras = extras_matrix if has_test_group else ("test", *extras_matrix) + +from_git = ( + *DATASTRUCTURES, + *(p["name"] for p in json.loads((ROOT / "packages.json").read_text()) if is_pre), +) +# the package under test comes from its checkout, so don't constrain it +constraints = tuple( + f"{name} @ git+https://github.com/scverse/{name}@main" + for name in dict.fromkeys(from_git) + if name != package +) + +with TemporaryDirectory() as tmp: + constraints_file, overrides_file = Path(tmp, "constraints.txt"), Path(tmp, "overrides.txt") + constraints_file.write_text("\n".join(constraints) + "\n") + overrides_file.write_text("\n".join(OVERRIDES_PRE) + "\n") + cmd = ( + *("uv", "pip", "install", "--compile", "--system", "-v"), + f".[{','.join(extras)}]" if extras else ".", + *("-c", ROOT / "constraints.txt", "-c", constraints_file), + *(("--group", "test") if has_test_group else ()), + *(("--prerelease", "allow", "--override", overrides_file) if is_pre else ()), + ) + print(*cmd, flush=True) + sys.exit(subprocess.run(cmd, check=False).returncode)