Skip to content

Commit 1482bbd

Browse files
andersy005dcherianpre-commit-ci[bot]
authored
Add pre-commit hooks (#15)
Co-authored-by: Deepak Cherian <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c1f9565 commit 1482bbd

17 files changed

+110
-42
lines changed

.github/workflows/pypi-release.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ jobs:
5656
name: releases
5757
path: dist
5858

59-
60-
6159
upload-to-pypi:
6260
needs: build-artifacts
6361
if: github.event_name == 'release'

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ dmypy.json
137137
# Cython debug symbols
138138
cython_debug/
139139

140-
.vscode/
140+
.vscode/

.pre-commit-config.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ci:
2+
autoupdate_schedule: quarterly
3+
4+
exclude: |
5+
(?x)^(
6+
versioneer.py|
7+
cupy_xarray/_version.py
8+
)$
9+
10+
repos:
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: v4.3.0
13+
hooks:
14+
- id: trailing-whitespace
15+
- id: end-of-file-fixer
16+
- id: check-docstring-first
17+
- id: check-json
18+
- id: check-yaml
19+
# - id: double-quote-string-fixer
20+
- id: debug-statements
21+
- id: mixed-line-ending
22+
23+
- repo: https://github.com/asottile/pyupgrade
24+
rev: v2.37.3
25+
hooks:
26+
- id: pyupgrade
27+
args:
28+
- '--py38-plus'
29+
30+
- repo: https://github.com/psf/black
31+
rev: 22.6.0
32+
hooks:
33+
- id: black
34+
- id: black-jupyter
35+
36+
- repo: https://github.com/keewis/blackdoc
37+
rev: v0.3.5
38+
hooks:
39+
- id: blackdoc
40+
41+
- repo: https://github.com/PyCQA/flake8
42+
rev: 5.0.4
43+
hooks:
44+
- id: flake8
45+
46+
- repo: https://github.com/PyCQA/isort
47+
rev: 5.10.1
48+
hooks:
49+
- id: isort
50+
51+
- repo: https://github.com/pre-commit/mirrors-prettier
52+
rev: v2.7.1
53+
hooks:
54+
- id: prettier

.prettierrc.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tabWidth = 2
2+
semi = false
3+
singleQuote = true

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sphinx:
1212

1313
# Optionally set the version of Python and requirements required to build your docs
1414
conda:
15-
environment: ci/doc.yml
15+
environment: ci/doc.yml
1616

1717
python:
1818
install:

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
Interface for using cupy in xarray, providing convenience accessors.
66

7-
87
## Installation
98

109
```console

cupy_xarray/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
from ._version import get_versions
2-
3-
__version__ = get_versions()["version"]
4-
del get_versions
5-
1+
from . import _version
62
from .accessors import CupyDataArrayAccessor, CupyDatasetAccessor # noqa
73

8-
from . import _version
9-
__version__ = _version.get_versions()['version']
4+
__version__ = _version.get_versions()["version"]

cupy_xarray/accessors.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import cupy as cp
2-
32
from xarray import (
43
DataArray,
54
Dataset,
@@ -119,11 +118,11 @@ def as_cupy(self):
119118

120119
def as_numpy(self):
121120
if self.is_cupy:
122-
data_vars = {
123-
var: da.cupy.as_numpy() for var, da in self.ds.data_vars.items()
124-
}
121+
data_vars = {var: da.cupy.as_numpy() for var, da in self.ds.data_vars.items()}
125122
return Dataset(
126-
data_vars=data_vars, coords=self.ds.coords, attrs=self.ds.attrs,
123+
data_vars=data_vars,
124+
coords=self.ds.coords,
125+
attrs=self.ds.attrs,
127126
)
128127
else:
129128
return self.ds.as_numpy()

cupy_xarray/tests/test_accessors.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import numpy as np
12
import pytest
2-
33
import xarray as xr
44
from xarray.core.pycompat import dask_array_type
5-
import cupy as cp
6-
import numpy as np
7-
import cupy_xarray
5+
6+
import cupy_xarray # noqa: F401
87

98

109
@pytest.fixture
@@ -19,9 +18,7 @@ def tutorial_da_air(tutorial_ds_air):
1918

2019
@pytest.fixture
2120
def tutorial_ds_air_dask():
22-
return xr.tutorial.open_dataset(
23-
"air_temperature", chunks={"lat": 25, "lon": 25, "time": -1}
24-
)
21+
return xr.tutorial.open_dataset("air_temperature", chunks={"lat": 25, "lon": 25, "time": -1})
2522

2623

2724
@pytest.fixture

docs/conf.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
# import cupy_xarray
1010
import sphinx_autosummary_accessors
1111

12-
project = 'cupy-xarray'
13-
copyright = '2022, cupy-xarray developers'
14-
author = 'cupy-xarray developers'
15-
release = 'v0.1'
12+
project = "cupy-xarray"
13+
copyright = "2022, cupy-xarray developers"
14+
author = "cupy-xarray developers"
15+
release = "v0.1"
1616

1717
# -- General configuration ---------------------------------------------------
1818
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -38,13 +38,13 @@
3838
}
3939

4040
templates_path = ["_templates", sphinx_autosummary_accessors.templates_path]
41-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'api.rst']
41+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "api.rst"]
4242

4343
# -- Options for HTML output -------------------------------------------------
4444
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
4545

46-
html_theme = 'furo'
47-
html_static_path = ['_static']
46+
html_theme = "furo"
47+
html_static_path = ["_static"]
4848

4949

5050
# Myst_nb options

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Welcome to cupy-xarray's documentation!
22

33
## Contents
4+
45
```{eval-rst}
56
.. toctree::
67
:maxdepth: 1

docs/quickstart.ipynb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,7 @@
27302730
}
27312731
],
27322732
"source": [
2733-
"da_gpu.groupby('x').mean(...)"
2733+
"da_gpu.groupby(\"x\").mean(...)"
27342734
]
27352735
},
27362736
{
@@ -2817,7 +2817,7 @@
28172817
}
28182818
],
28192819
"source": [
2820-
"weights = xr.DataArray(cp.asarray([0, 0.5, 1, 0.5, 0]), dims='y')\n",
2820+
"weights = xr.DataArray(cp.asarray([0, 0.5, 1, 0.5, 0]), dims=\"y\")\n",
28212821
"da_gpu.weighted(weights).sum().cupy.is_cupy"
28222822
]
28232823
},
@@ -2897,18 +2897,21 @@
28972897
}
28982898
],
28992899
"source": [
2900-
"x = cp.arange(6, dtype='f').reshape(2, 3)\n",
2901-
"y = cp.arange(3, dtype='f')\n",
2900+
"x = cp.arange(6, dtype=\"f\").reshape(2, 3)\n",
2901+
"y = cp.arange(3, dtype=\"f\")\n",
29022902
"\n",
29032903
"kernel = cp.ElementwiseKernel(\n",
2904-
" 'float32 x, float32 y', 'float32 z',\n",
2905-
" '''\n",
2904+
" \"float32 x, float32 y\",\n",
2905+
" \"float32 z\",\n",
2906+
" \"\"\"\n",
29062907
" if (x - 2 > y) {\n",
29072908
" z = x * y;\n",
29082909
" } else {\n",
29092910
" z = x + y;\n",
29102911
" }\n",
2911-
" ''', 'my_kernel')\n",
2912+
" \"\"\",\n",
2913+
" \"my_kernel\",\n",
2914+
")\n",
29122915
"\n",
29132916
"kernel(x, y)"
29142917
]

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.black]
2+
line-length = 100
3+
target-version = ['py38']

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
cupy
2-
xarray
2+
xarray

requirements_test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pytest
2-
dask
2+
dask

setup.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,18 @@ versionfile_source = cupy_xarray/_version.py
55
versionfile_build = cupy_xarray/_version.py
66
tag_prefix =
77
parentdir_prefix =
8+
9+
[flake8]
10+
exclude = docs,versioneer.py,cupy_xarray/_version.py
11+
ignore = E203,E266,E501,W503,E722,E402,C901,E731
12+
max-line-length = 100
13+
max-complexity = 18
14+
select = B,C,E,F,W,T4,B9
15+
16+
[isort]
17+
profile=black
18+
skip=
19+
docs/source/conf.py
20+
setup.py
21+
versioneer.py
22+
cupy_xarray/_version.py

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import setuptools
2+
23
import versioneer
34

4-
with open("README.md", "r") as fh:
5+
with open("README.md") as fh:
56
long_description = fh.read()
6-
with open("requirements.txt", "r") as fh:
7+
with open("requirements.txt") as fh:
78
requirements = [line.strip() for line in fh]
89

910
setuptools.setup(

0 commit comments

Comments
 (0)