diff --git a/.github/workflows/pypi-release.yaml b/.github/workflows/pypi-release.yaml index ced1e55..8cb3c3f 100644 --- a/.github/workflows/pypi-release.yaml +++ b/.github/workflows/pypi-release.yaml @@ -56,8 +56,6 @@ jobs: name: releases path: dist - - upload-to-pypi: needs: build-artifacts if: github.event_name == 'release' diff --git a/.gitignore b/.gitignore index b8fa2d6..2dc658c 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,4 @@ dmypy.json # Cython debug symbols cython_debug/ -.vscode/ \ No newline at end of file +.vscode/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ca58390 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,54 @@ +ci: + autoupdate_schedule: quarterly + +exclude: | + (?x)^( + versioneer.py| + cupy_xarray/_version.py + )$ + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-docstring-first + - id: check-json + - id: check-yaml + # - id: double-quote-string-fixer + - id: debug-statements + - id: mixed-line-ending + + - repo: https://github.com/asottile/pyupgrade + rev: v2.37.3 + hooks: + - id: pyupgrade + args: + - '--py38-plus' + + - repo: https://github.com/psf/black + rev: 22.6.0 + hooks: + - id: black + - id: black-jupyter + + - repo: https://github.com/keewis/blackdoc + rev: v0.3.5 + hooks: + - id: blackdoc + + - repo: https://github.com/PyCQA/flake8 + rev: 5.0.4 + hooks: + - id: flake8 + + - repo: https://github.com/PyCQA/isort + rev: 5.10.1 + hooks: + - id: isort + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.7.1 + hooks: + - id: prettier diff --git a/.prettierrc.toml b/.prettierrc.toml new file mode 100644 index 0000000..addd6d3 --- /dev/null +++ b/.prettierrc.toml @@ -0,0 +1,3 @@ +tabWidth = 2 +semi = false +singleQuote = true diff --git a/.readthedocs.yml b/.readthedocs.yml index 2beab05..169181c 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -12,7 +12,7 @@ sphinx: # Optionally set the version of Python and requirements required to build your docs conda: - environment: ci/doc.yml + environment: ci/doc.yml python: install: diff --git a/README.md b/README.md index 644a082..1990d6c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ Interface for using cupy in xarray, providing convenience accessors. - ## Installation ```console diff --git a/cupy_xarray/__init__.py b/cupy_xarray/__init__.py index e8b9692..5c3a06c 100644 --- a/cupy_xarray/__init__.py +++ b/cupy_xarray/__init__.py @@ -1,9 +1,4 @@ -from ._version import get_versions - -__version__ = get_versions()["version"] -del get_versions - +from . import _version from .accessors import CupyDataArrayAccessor, CupyDatasetAccessor # noqa -from . import _version -__version__ = _version.get_versions()['version'] +__version__ = _version.get_versions()["version"] diff --git a/cupy_xarray/accessors.py b/cupy_xarray/accessors.py index f2cf085..325f2f3 100644 --- a/cupy_xarray/accessors.py +++ b/cupy_xarray/accessors.py @@ -1,5 +1,4 @@ import cupy as cp - from xarray import ( DataArray, Dataset, @@ -119,11 +118,11 @@ def as_cupy(self): def as_numpy(self): if self.is_cupy: - data_vars = { - var: da.cupy.as_numpy() for var, da in self.ds.data_vars.items() - } + data_vars = {var: da.cupy.as_numpy() for var, da in self.ds.data_vars.items()} return Dataset( - data_vars=data_vars, coords=self.ds.coords, attrs=self.ds.attrs, + data_vars=data_vars, + coords=self.ds.coords, + attrs=self.ds.attrs, ) else: return self.ds.as_numpy() diff --git a/cupy_xarray/tests/test_accessors.py b/cupy_xarray/tests/test_accessors.py index 4f41063..cad6955 100644 --- a/cupy_xarray/tests/test_accessors.py +++ b/cupy_xarray/tests/test_accessors.py @@ -1,10 +1,9 @@ +import numpy as np import pytest - import xarray as xr from xarray.core.pycompat import dask_array_type -import cupy as cp -import numpy as np -import cupy_xarray + +import cupy_xarray # noqa: F401 @pytest.fixture @@ -19,9 +18,7 @@ def tutorial_da_air(tutorial_ds_air): @pytest.fixture def tutorial_ds_air_dask(): - return xr.tutorial.open_dataset( - "air_temperature", chunks={"lat": 25, "lon": 25, "time": -1} - ) + return xr.tutorial.open_dataset("air_temperature", chunks={"lat": 25, "lon": 25, "time": -1}) @pytest.fixture diff --git a/docs/conf.py b/docs/conf.py index 257f037..12d16d6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,10 +9,10 @@ # import cupy_xarray import sphinx_autosummary_accessors -project = 'cupy-xarray' -copyright = '2022, cupy-xarray developers' -author = 'cupy-xarray developers' -release = 'v0.1' +project = "cupy-xarray" +copyright = "2022, cupy-xarray developers" +author = "cupy-xarray developers" +release = "v0.1" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration @@ -38,13 +38,13 @@ } templates_path = ["_templates", sphinx_autosummary_accessors.templates_path] -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'api.rst'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "api.rst"] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = 'furo' -html_static_path = ['_static'] +html_theme = "furo" +html_static_path = ["_static"] # Myst_nb options diff --git a/docs/index.md b/docs/index.md index be1fed9..597dd16 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,7 @@ # Welcome to cupy-xarray's documentation! ## Contents + ```{eval-rst} .. toctree:: :maxdepth: 1 diff --git a/docs/quickstart.ipynb b/docs/quickstart.ipynb index bce6db4..02e9d18 100644 --- a/docs/quickstart.ipynb +++ b/docs/quickstart.ipynb @@ -2730,7 +2730,7 @@ } ], "source": [ - "da_gpu.groupby('x').mean(...)" + "da_gpu.groupby(\"x\").mean(...)" ] }, { @@ -2817,7 +2817,7 @@ } ], "source": [ - "weights = xr.DataArray(cp.asarray([0, 0.5, 1, 0.5, 0]), dims='y')\n", + "weights = xr.DataArray(cp.asarray([0, 0.5, 1, 0.5, 0]), dims=\"y\")\n", "da_gpu.weighted(weights).sum().cupy.is_cupy" ] }, @@ -2897,18 +2897,21 @@ } ], "source": [ - "x = cp.arange(6, dtype='f').reshape(2, 3)\n", - "y = cp.arange(3, dtype='f')\n", + "x = cp.arange(6, dtype=\"f\").reshape(2, 3)\n", + "y = cp.arange(3, dtype=\"f\")\n", "\n", "kernel = cp.ElementwiseKernel(\n", - " 'float32 x, float32 y', 'float32 z',\n", - " '''\n", + " \"float32 x, float32 y\",\n", + " \"float32 z\",\n", + " \"\"\"\n", " if (x - 2 > y) {\n", " z = x * y;\n", " } else {\n", " z = x + y;\n", " }\n", - " ''', 'my_kernel')\n", + " \"\"\",\n", + " \"my_kernel\",\n", + ")\n", "\n", "kernel(x, y)" ] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..96a9361 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[tool.black] +line-length = 100 +target-version = ['py38'] diff --git a/requirements.txt b/requirements.txt index eb3c1a2..68466b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ cupy -xarray \ No newline at end of file +xarray diff --git a/requirements_test.txt b/requirements_test.txt index eb5b152..78d2fa8 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,2 +1,2 @@ pytest -dask \ No newline at end of file +dask diff --git a/setup.cfg b/setup.cfg index d20de6f..be99e8d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,3 +5,18 @@ versionfile_source = cupy_xarray/_version.py versionfile_build = cupy_xarray/_version.py tag_prefix = parentdir_prefix = + +[flake8] +exclude = docs,versioneer.py,cupy_xarray/_version.py +ignore = E203,E266,E501,W503,E722,E402,C901,E731 +max-line-length = 100 +max-complexity = 18 +select = B,C,E,F,W,T4,B9 + +[isort] +profile=black +skip= + docs/source/conf.py + setup.py + versioneer.py + cupy_xarray/_version.py diff --git a/setup.py b/setup.py index f691906..c72e8eb 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,10 @@ import setuptools + import versioneer -with open("README.md", "r") as fh: +with open("README.md") as fh: long_description = fh.read() -with open("requirements.txt", "r") as fh: +with open("requirements.txt") as fh: requirements = [line.strip() for line in fh] setuptools.setup(