From 860bee132c28aa6b0bbda58ff4f6b2d412e949b6 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Fri, 31 Jul 2026 14:37:58 +0800 Subject: [PATCH 1/3] Add generate-aggregations pixi task --- pixi.toml | 21 +++++++++++++++++---- xarray/util/generate_aggregations.py | 11 +---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pixi.toml b/pixi.toml index 4df6b781578..50ad75e7093 100644 --- a/pixi.toml +++ b/pixi.toml @@ -211,9 +211,25 @@ pytz = "*" hypothesis = "*" coveralls = "*" +[feature.test.pypi-dependencies] +pytest-accept = ">=0.2.2, <0.3" # needed for task generate-aggregations + [feature.test.tasks] test = { cmd = "pytest", description = "Run the test suite with pytest." } +# The second run of pytest is deliberate, since the first will return an error while replacing the doctests +generate-aggregations = { cmd = """python xarray/util/generate_aggregations.py &&\ +! pytest --doctest-modules xarray/core/_aggregations.py --accept &&\ +pytest --doctest-modules xarray/core/_aggregations.py &&\ +! pytest --doctest-modules xarray/namedarray/_aggregations.py --accept &&\ +pytest --doctest-modules xarray/namedarray/_aggregations.py &&\ +echo 'Aggregations generated successfully!' +""", description = "Generate module and stub file for arithmetic operators of various xarray classes." } +generate-aggregations-ci = { cmd = 'test -z "$(git status --porcelain)" && echo "Success! Generate-aggregations matches the committed tree" || echo "Failure :( . Generate-aggregations does not match the committed files"', depends-on = [ + 'generate-aggregations', + 'pre-commit', +] } + [feature.doc.dependencies] kerchunk = "*" ipykernel = "*" @@ -305,7 +321,7 @@ mypy = { cmd = "mypy --install-types --non-interactive --cobertura-xml-report my pre-commit = "*" [feature.pre-commit.tasks] -pre-commit = { cmd = "pre-commit", description = "Run pre-commit hooks and linters." } +pre-commit = { cmd = "pre-commit run --all-files || true", description = "Run pre-commit hooks and linters." } # `|| true` so that this can be used as a task dependency [feature.release.dependencies] gitpython = "*" @@ -318,9 +334,6 @@ release-contributors = { cmd = "python ci/release_contributors.py", description ipython = ">=9.8.0,<10" black = ">=25.1.0,<26" -[feature.dev.pypi-dependencies] -pytest-accept = ">=0.2.2, <0.3" - [feature.policy.pypi-dependencies] xarray-minimum-dependency-policy = "*" diff --git a/xarray/util/generate_aggregations.py b/xarray/util/generate_aggregations.py index 545850fcc46..9660cda92a0 100644 --- a/xarray/util/generate_aggregations.py +++ b/xarray/util/generate_aggregations.py @@ -3,16 +3,7 @@ For internal xarray development use only. Usage: - python xarray/util/generate_aggregations.py - pytest --doctest-modules xarray/core/_aggregations.py --accept - pytest --doctest-modules xarray/core/_aggregations.py - pytest --doctest-modules xarray/namedarray/_aggregations.py --accept - pytest --doctest-modules xarray/namedarray/_aggregations.py - -This requires [pytest-accept](https://github.com/max-sixty/pytest-accept). -The second run of pytest is deliberate, since the first will return an error -while replacing the doctests. - + pixi run generate-aggregations """ import textwrap From 098371daf5c3546a2f91ddfb1efc203c17b346f9 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Fri, 31 Jul 2026 18:25:08 +0800 Subject: [PATCH 2/3] Add CI job --- .github/workflows/ci.yaml | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4be140f485d..573fd67bad6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -189,6 +189,49 @@ jobs: name: codecov-umbrella fail_ci_if_error: false + check-generate-aggregations: + name: "Check generate-aggregations is up-to-date" + runs-on: ubuntu-latest + needs: cache-pixi-lock + if: | + github.event_name == 'pull_request' + && needs.cache-pixi-lock.result == 'success' + defaults: + run: + shell: bash -l {0} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Check if generate_aggregations.py changed + id: filter + run: | + if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q 'xarray/util/generate_aggregations.py'; then + echo "changed=true" >> "$GITHUB_OUTPUT" + else + echo "changed=false" >> "$GITHUB_OUTPUT" + fi + + - name: Restore cached pixi lockfile + if: steps.filter.outputs.changed == 'true' + uses: Parcels-code/pixi-lock/restore@38495788b79a5ff26009aecc15daa9a8310b8832 # v0.1.0 + with: + cache-key: ${{ needs.cache-pixi-lock.outputs.cache-key }} + + - uses: prefix-dev/setup-pixi@a09b6247153796b190642a2b53fac4241043cf6f # v0.10.0 + if: steps.filter.outputs.changed == 'true' + with: + pixi-version: ${{ needs.cache-pixi-lock.outputs.pixi-version }} + cache: true + cache-write: false + + - name: Run generate-aggregations-ci + if: steps.filter.outputs.changed == 'true' + run: | + pixi run generate-aggregations-ci + event_file: name: "Event File" runs-on: ubuntu-slim From d28e563d7c9cd34e8e2eac84af0f7d92e35cd706 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Fri, 31 Jul 2026 18:37:02 +0800 Subject: [PATCH 3/3] Zizmor fix --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 573fd67bad6..9ed85c869e2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -208,7 +208,7 @@ jobs: - name: Check if generate_aggregations.py changed id: filter run: | - if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q 'xarray/util/generate_aggregations.py'; then + if git diff --name-only origin/${GITHUB_BASE_REF}...HEAD | grep -q 'xarray/util/generate_aggregations.py'; then echo "changed=true" >> "$GITHUB_OUTPUT" else echo "changed=false" >> "$GITHUB_OUTPUT"