From 82be717d2871d1f89e336497f0c4fa8add8b7a55 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Jun 2024 16:20:09 +1200 Subject: [PATCH 1/8] Setup GitHub Action Continuout Integration tests Running tests on Ubuntu-22.04 and Python 3.10/3.12. --- .github/workflows/ci-tests.yml | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/ci-tests.yml diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml new file mode 100644 index 0000000..dce39f6 --- /dev/null +++ b/.github/workflows/ci-tests.yml @@ -0,0 +1,42 @@ +name: Tests + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + test: + name: ${{ matrix.os }} - Python ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ['3.10', '3.12'] + os: [ubuntu-24.04] + + steps: + # Checkout current git repository + - name: Checkout + uses: actions/checkout@v4.1.7 + + # Install Python + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5.1.0 + with: + python-version: ${{ matrix.python-version }} + + # Install dependencies from requirements.txt file + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements_test.txt ]; then pip install -r requirements_test.txt; fi + python -m pip install . + + # Run the unit tests + - name: Test with pytest + run: | + pytest --verbose cupy_xarray/tests/ From 703b0b6ed49539fd88880139437cb4bc0310fca8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Jun 2024 04:24:54 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/ci-tests.yml | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index dce39f6..b1bc115 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -2,9 +2,9 @@ name: Tests on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] permissions: contents: read @@ -15,28 +15,28 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ['3.10', '3.12'] + python-version: ["3.10", "3.12"] os: [ubuntu-24.04] steps: - # Checkout current git repository - - name: Checkout - uses: actions/checkout@v4.1.7 + # Checkout current git repository + - name: Checkout + uses: actions/checkout@v4.1.7 - # Install Python - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5.1.0 - with: - python-version: ${{ matrix.python-version }} + # Install Python + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5.1.0 + with: + python-version: ${{ matrix.python-version }} - # Install dependencies from requirements.txt file - - name: Install dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements_test.txt ]; then pip install -r requirements_test.txt; fi - python -m pip install . + # Install dependencies from requirements.txt file + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements_test.txt ]; then pip install -r requirements_test.txt; fi + python -m pip install . - # Run the unit tests - - name: Test with pytest - run: | - pytest --verbose cupy_xarray/tests/ + # Run the unit tests + - name: Test with pytest + run: | + pytest --verbose cupy_xarray/tests/ From 3d3cf6333336c568a32ac1b4f7c752ea6e547787 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Jun 2024 16:36:11 +1200 Subject: [PATCH 3/8] Put extra test requirements in setup.py Remove the requirements_test.txt file, and put `dask` and `pytest` dependencies directly in setup.py instead. --- requirements_test.txt | 2 -- setup.py | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 requirements_test.txt diff --git a/requirements_test.txt b/requirements_test.txt deleted file mode 100644 index 78d2fa8..0000000 --- a/requirements_test.txt +++ /dev/null @@ -1,2 +0,0 @@ -pytest -dask diff --git a/setup.py b/setup.py index bd994f4..8e040c2 100644 --- a/setup.py +++ b/setup.py @@ -22,4 +22,5 @@ ], python_requires=">=3.7", install_requires=requirements, + extras_require={"test": ["dask", "pytest"]}, ) From 3b7b2ecfefc6ca626f55707616def5f4b404508e Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Jun 2024 16:50:58 +1200 Subject: [PATCH 4/8] Set CUPY_NO_CUDA=true environment variable Try pip installing CuPy without CUDA. --- .github/workflows/ci-tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index b1bc115..9bf9ab6 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -33,8 +33,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - if [ -f requirements_test.txt ]; then pip install -r requirements_test.txt; fi - python -m pip install . + CUPY_NO_CUDA=true python -m pip install .[test] # Run the unit tests - name: Test with pytest From c1d53ab1dba2d6d77f457ea2f35ab9bcf7696fe3 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Jun 2024 17:02:19 +1200 Subject: [PATCH 5/8] Switch from setup-python to setup-micromamba Easier to install CuPy (without CUDA libs) from conda-forge instead of PyPI. --- .github/workflows/ci-tests.yml | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 9bf9ab6..9a6c7f1 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -17,23 +17,35 @@ jobs: matrix: python-version: ["3.10", "3.12"] os: [ubuntu-24.04] + defaults: + run: + shell: bash -l {0} steps: # Checkout current git repository - name: Checkout uses: actions/checkout@v4.1.7 - # Install Python - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5.1.0 + # Install Micromamba with conda-forge dependencies + - name: Setup Micromamba + uses: mamba-org/setup-micromamba@v1.9.0 with: - python-version: ${{ matrix.python-version }} + environment-name: cupy-xarray + condarc: | + channels: + - conda-forge + - nodefaults + create-args: >- + cupy-core + dask + pip + python=${{ matrix.python-version }} + pytest + xarray - # Install dependencies from requirements.txt file - - name: Install dependencies - run: | - python -m pip install --upgrade pip - CUPY_NO_CUDA=true python -m pip install .[test] + # Install the package that we want to test + - name: Install the package + run: python -m pip install . # Run the unit tests - name: Test with pytest From 22cc7dc39d45632d25704ca286cb61a433e08960 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Jun 2024 17:07:14 +1200 Subject: [PATCH 6/8] Fix ModuleNotFoundError: No module named 'xarray.core.pycompat' Xref https://github.com/pydata/xarray/blob/v2024.06.0/xarray/namedarray/pycompat.py#L21-L43 --- cupy_xarray/tests/test_accessors.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cupy_xarray/tests/test_accessors.py b/cupy_xarray/tests/test_accessors.py index cad6955..08d1d7b 100644 --- a/cupy_xarray/tests/test_accessors.py +++ b/cupy_xarray/tests/test_accessors.py @@ -1,10 +1,13 @@ import numpy as np import pytest import xarray as xr -from xarray.core.pycompat import dask_array_type +from xarray.namedarray.pycompat import DuckArrayModule import cupy_xarray # noqa: F401 +dsk = DuckArrayModule("dask") +dask_array_type = dsk.type + @pytest.fixture def tutorial_ds_air(): From a9f5341d14a168e85a63e6824d2bbe3107315410 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Jun 2024 17:09:57 +1200 Subject: [PATCH 7/8] Add pooch to test_requires Fixes `ModuleNotFoundError: No module named 'pooch'` when trying to call `xr.tutorial.open_dataset`. --- .github/workflows/ci-tests.yml | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 9a6c7f1..f4e5621 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -39,6 +39,7 @@ jobs: cupy-core dask pip + pooch python=${{ matrix.python-version }} pytest xarray diff --git a/setup.py b/setup.py index 8e040c2..372af7e 100644 --- a/setup.py +++ b/setup.py @@ -22,5 +22,5 @@ ], python_requires=">=3.7", install_requires=requirements, - extras_require={"test": ["dask", "pytest"]}, + extras_require={"test": ["dask", "pooch", "pytest"]}, ) From 7f3a4c6f3c9e71b628ddd232aef5441caf20e80e Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Jun 2024 17:13:17 +1200 Subject: [PATCH 8/8] Add netcdf4 to test_requires Fixes `ImportError: opening tutorial dataset air_temperature requires either scipy or netCDF4 to be installed` when trying to read the air_temperature.nc file. --- .github/workflows/ci-tests.yml | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index f4e5621..51ab350 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -38,6 +38,7 @@ jobs: create-args: >- cupy-core dask + netcdf4 pip pooch python=${{ matrix.python-version }} diff --git a/setup.py b/setup.py index 372af7e..1ba685f 100644 --- a/setup.py +++ b/setup.py @@ -22,5 +22,5 @@ ], python_requires=">=3.7", install_requires=requirements, - extras_require={"test": ["dask", "pooch", "pytest"]}, + extras_require={"test": ["dask", "netcdf4", "pooch", "pytest"]}, )