Skip to content

Commit

Permalink
Add pre-commit hooks (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: Deepak Cherian <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 17, 2022
1 parent c1f9565 commit 1482bbd
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 42 deletions.
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/
54 changes: 54 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
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
9 changes: 2 additions & 7 deletions cupy_xarray/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
9 changes: 4 additions & 5 deletions cupy_xarray/accessors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cupy as cp

from xarray import (
DataArray,
Dataset,
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 4 additions & 7 deletions cupy_xarray/tests/test_accessors.py
Original file line number Diff line number Diff line change
@@ -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
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 Down
14 changes: 7 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
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
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 100
target-version = ['py38']
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
15 changes: 15 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit 1482bbd

Please sign in to comment.