Skip to content

Add pre-commit hooks #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions .github/workflows/pypi-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ jobs:
name: releases
path: dist



upload-to-pypi:
needs: build-artifacts
if: github.event_name == 'release'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ dmypy.json
# Cython debug symbols
cython_debug/

.vscode/
.vscode/
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ci:
autoupdate_schedule: monthly

exclude: '^(_version|versionner)*'

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
3 changes: 3 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tabWidth = 2
semi = false
singleQuote = true
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

Interface for using cupy in xarray, providing convenience accessors.


## Installation

```console
Expand Down
4 changes: 2 additions & 2 deletions cupy_xarray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ._version import get_versions

__version__ = get_versions()["version"]
__version__ = get_versions()['version']
del get_versions

from . import _version
from .accessors import CupyDataArrayAccessor, CupyDatasetAccessor # noqa

from . import _version
__version__ = _version.get_versions()['version']
24 changes: 9 additions & 15 deletions cupy_xarray/accessors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import cupy as cp

from xarray import (
DataArray,
Dataset,
register_dataarray_accessor,
register_dataset_accessor,
)
from xarray import DataArray, Dataset, register_dataarray_accessor, register_dataset_accessor
from xarray.core.pycompat import dask_array_type


@register_dataarray_accessor("cupy")
@register_dataarray_accessor('cupy')
class CupyDataArrayAccessor:
"""
Access methods for DataArrays using Cupy.
Expand Down Expand Up @@ -99,7 +93,7 @@ def get(self):
return self.da.data.get()


@register_dataset_accessor("cupy")
@register_dataset_accessor('cupy')
class CupyDatasetAccessor:
"""
Access methods for DataArrays using Cupy.
Expand All @@ -119,11 +113,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()
Expand All @@ -134,7 +128,7 @@ def as_numpy(self):
# libraries like this could register new ``as_`` methods for dispatch.


@register_dataarray_accessor("as_cupy")
@register_dataarray_accessor('as_cupy')
def _(da):
"""
Converts the DataArray's underlying array type to cupy.
Expand All @@ -148,7 +142,7 @@ def as_cupy(*args, **kwargs):
return as_cupy


@register_dataset_accessor("as_cupy")
@register_dataset_accessor('as_cupy')
def _(ds):
"""
Converts the Dataset's underlying Dataarray's array type to cupy.
Expand Down
19 changes: 8 additions & 11 deletions cupy_xarray/tests/test_accessors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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
def tutorial_ds_air():
return xr.tutorial.load_dataset("air_temperature")
return xr.tutorial.load_dataset('air_temperature')


@pytest.fixture
Expand All @@ -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
Expand All @@ -31,7 +28,7 @@ def tutorial_da_air_dask(tutorial_ds_air_dask):

def test_data_set_accessor(tutorial_ds_air):
ds = tutorial_ds_air
assert hasattr(ds, "cupy")
assert hasattr(ds, 'cupy')
assert not ds.cupy.is_cupy

ds = ds.as_cupy()
Expand All @@ -43,7 +40,7 @@ def test_data_set_accessor(tutorial_ds_air):

def test_data_array_accessor(tutorial_da_air):
da = tutorial_da_air
assert hasattr(da, "cupy")
assert hasattr(da, 'cupy')
assert not da.cupy.is_cupy

da = da.as_cupy()
Expand All @@ -58,7 +55,7 @@ def test_data_array_accessor(tutorial_da_air):

def test_data_array_accessor_dask(tutorial_da_air_dask):
da = tutorial_da_air_dask
assert hasattr(da, "cupy")
assert hasattr(da, 'cupy')
assert not da.cupy.is_cupy

da = da.as_cupy()
Expand Down
32 changes: 16 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@

extensions = [
# "sphinx.ext.autodoc",
"sphinx.ext.viewcode",
'sphinx.ext.viewcode',
# "sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.extlinks",
"numpydoc",
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.extlinks',
'numpydoc',
# "sphinx_autosummary_accessors",
"IPython.sphinxext.ipython_directive",
"myst_nb",
"sphinx_copybutton",
'IPython.sphinxext.ipython_directive',
'myst_nb',
'sphinx_copybutton',
]


extlinks = {
"issue": ("https://github.com/xarray-contrib/cupy-xarray/issues/%s", "GH#"),
"pr": ("https://github.com/xarray-contrib/cupy-xarray/pull/%s", "GH#"),
'issue': ('https://github.com/xarray-contrib/cupy-xarray/issues/%s', 'GH#'),
'pr': ('https://github.com/xarray-contrib/cupy-xarray/pull/%s', 'GH#'),
}

templates_path = ["_templates", sphinx_autosummary_accessors.templates_path]
templates_path = ['_templates', sphinx_autosummary_accessors.templates_path]
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'api.rst']

# -- Options for HTML output -------------------------------------------------
Expand All @@ -48,11 +48,11 @@


# Myst_nb options
nb_execution_mode = "off"
nb_execution_mode = 'off'

intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"dask": ("https://docs.dask.org/en/latest", None),
"cupy": ("https://docs.cupy.dev/en/latest", None),
"xarray": ("http://docs.xarray.dev/en/latest/", None),
'python': ('https://docs.python.org/3/', None),
'dask': ('https://docs.dask.org/en/latest', None),
'cupy': ('https://docs.cupy.dev/en/latest', None),
'xarray': ('http://docs.xarray.dev/en/latest/', None),
}
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Welcome to cupy-xarray's documentation!

## Contents

```{eval-rst}
.. toctree::
:maxdepth: 1
Expand Down
17 changes: 10 additions & 7 deletions docs/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,7 @@
}
],
"source": [
"da_gpu.groupby('x').mean(...)"
"da_gpu.groupby(\"x\").mean(...)"
]
},
{
Expand Down Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -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)"
]
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool.black]
line-length = 100
target-version = ['py38']
skip-string-normalization = true
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cupy
xarray
xarray
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest
dask
dask
21 changes: 21 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,24 @@ 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]
known_first_party=cupy_xarray
known_third_party=
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
combine_as_imports=True
line_length=100
skip=
docs/source/conf.py
setup.py
versioneer.py
cupy_xarray/_version.py
Loading