Skip to content
Open
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
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down Expand Up @@ -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 = "*"
Expand All @@ -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 = "*"

Expand Down
11 changes: 1 addition & 10 deletions xarray/util/generate_aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading