Skip to content

Commit

Permalink
Migrate to pyproject.toml and ruff (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky authored Jan 28, 2024
1 parent 7052021 commit 350892c
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 164 deletions.
19 changes: 4 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@ repos:
hooks:
- id: absolufy-imports
name: absolufy-imports
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
language_version: python3
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
language_version: python3
args:
- --target-version=py38
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: flake8
language_version: python3
- id: ruff
args: ["--fix", "--show-fixes"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
Expand Down
23 changes: 11 additions & 12 deletions HOW_TO_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ Time required: about an hour.
git commit -a -m 'Release v0.X.Y'
5. Tag the release:
git tag -a v0.X.Y -m 'v0.X.Y'
6. Build source for pypi:
python setup.py sdist
7. Use twine to register and upload the release on pypi. Be careful, you can't
take this back!
twine upload dist/xarray_extras-0.X.Y*
You will need to be listed as a package owner at
https://pypi.python.org/pypi/xarray_extras for this to work.
8. Push your changes to main:
6. Push your changes to main:
git push origin main
git push origin --tags
9. Update the stable branch (used by ReadTheDocs) and switch back to main:
7. Update the stable branch (used by ReadTheDocs) and switch back to main:
git checkout stable
git rebase main
git push origin stable
git checkout main
It's OK to force push to 'stable' if necessary.
We also update the stable branch with `git cherrypick` for documentation
only fixes that apply the current released version.
10. Add a section for the next release (v.X.(Y+1)) to doc/whats-new.rst.
11. Commit your changes and push to main again:
8. Add a section for the next release (v.X.(Y+1)) to doc/whats-new.rst.
9. Commit your changes and push to main again:
git commit -a -m 'Revert to dev version'
git push origin main
You're done pushing to main!
12. Issue the release on GitHub. Open https://github.com/crusaderky/xarray_extras/releases;
10. Issue the release on GitHub. Open https://github.com/crusaderky/xarray_extras/releases;
the new release should have automatically appeared. Otherwise, click on
"Draft a new release" and paste in the latest from whats-new.rst.
11. Download the .tar.gz package for the release
12. Use twine to register and upload the release on pypi. Be careful, you can't
take this back!
twine upload xarray_extras-*.tar.gz
You will need to be listed as a package owner at
https://pypi.python.org/pypi/xarray_extras for this to work.
13. Update the docs. Login to https://readthedocs.org/projects/xarray_extras/versions/
and switch your new release tag (at the bottom) from "Inactive" to "Active".
It should now build automatically.
Expand Down
5 changes: 2 additions & 3 deletions doc/develop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ Test using ``py.test``:
Code Formatting
---------------

xarray_extras uses several code linters (flake8, black, isort, pyupgrade, mypy),
which are enforced by CI. Developers should run them locally before they submit a PR,
through the single command
xarray_extras uses several code linters (black, ruff, mypy), which are enforced by CI.
Developers should run them locally before they submit a PR, through the single command

.. code-block:: bash
Expand Down
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ v0.6.0 (Unreleased)
- Added support for Python 3.10 and 3.11
- Added support for recent versions of Pandas (tested up to 2.2) and xarray
- Added support for :cls:`pathlib.Path` in function arguments
- Migrated from setup.cfg to pyproject.toml
- Migrated from flake8+isort+pyupgrade to ruff

.. _whats-new.0.5.0:

Expand Down
118 changes: 118 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
[project]
name = "xarray_extras"
authors = [{name = "Guido Imperiale", email = "[email protected]"}]
license = {text = "Apache"}
description = "Advanced / experimental algorithms for xarray"
keywords = ["xarray"]
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
requires-python = ">=3.8"
dependencies = [
"dask >= 2022.6",
"numba >= 0.56",
"numpy >= 1.23",
"pandas >= 1.5",
"scipy >= 1.9",
"xarray >= 2022.6.0",
]
dynamic = ["version"]

[project.urls]
Homepage = "https://github.com/crusaderky/xarray_extras"

[tool.setuptools]
packages = ["xarray_extras"]
zip-safe = false # https://mypy.readthedocs.io/en/latest/installed_packages.html
include-package-data = true

[tool.setuptools_scm]
# Use hardcoded version when .git has been removed and this is not a package created
# by sdist. This is the case e.g. of a remote deployment with PyCharm.
fallback_version = "9999"

[tool.setuptools.package-data]
xarray_extras = [
"py.typed",
"tests/data/*",
]

[build-system]
requires = [
"setuptools>=66",
"setuptools_scm[toml]",
]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
addopts = "--strict-markers --strict-config -v -r sxfE --color=yes"
xfail_strict = true
python_files = ["test_*.py"]
testpaths = ["xarray_extras/tests"]

[tool.coverage.report]
show_missing = true
exclude_lines = [
"pragma: nocover",
"pragma: no cover",
"TYPE_CHECKING",
"except ImportError",
"@overload",
'@(abc\.)?abstractmethod',
'@(numba\.)?jit',
'@(numba\.)?vectorize',
'@(numba\.)?guvectorize',
]

[tool.ruff]
builtins = ["ellipsis"]
exclude = [".eggs"]
target-version = "py38"

[tool.ruff.lint]
ignore = [
"E402", # module level import not at top of file
"SIM108", # use ternary operator instead of if-else block
]
select = [
"F", # Pyflakes
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"ISC", # flake8-implicit-str-concat
"SIM", # flake8-simplify
"E", # Pycodestyle
"W", # Pycodestyle
"I", # isort
"N", # pep8-naming
"UP", # Pyupgrade
"RUF", # unused-noqa
"EXE001", # Shebang is present but file is not executable
]

[tool.ruff.lint.isort]
known-first-party = ["xarray_extras"]

[tool.mypy]
allow_incomplete_defs = false
allow_untyped_decorators = false
allow_untyped_defs = false
ignore_missing_imports = true
no_implicit_optional = true
show_error_codes = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true

[[tool.mypy.overrides]]
module = ["*.tests.*"]
allow_untyped_defs = true
98 changes: 0 additions & 98 deletions setup.cfg

This file was deleted.

5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env python
from setuptools import Extension, setup

setup(
# Use hardcoded version when .git has been removed and this is not a package created
# by sdist. This is the case e.g. of a remote deployment with PyCharm.
use_scm_version={"fallback_version": "999"},
use_scm_version=True,
# Compile CPython extensions
ext_modules=[
Extension(
Expand Down
6 changes: 3 additions & 3 deletions xarray_extras/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
__all__ = ("to_csv",)

if TYPE_CHECKING:
# TODO remove TYPE_CHECKING (requires dask >=2023.9.1)
# TODO: remove TYPE_CHECKING (requires dask >=2023.9.1)
from dask.typing import DaskCollection, Key


Expand Down Expand Up @@ -76,7 +76,7 @@ def to_csv(
and concatenate the partial outputs.
"""
if not isinstance(x, xarray.DataArray):
raise ValueError("first argument must be a DataArray")
raise TypeError("first argument must be a DataArray")

# Health checks
if not isinstance(path, (str, Path)):
Expand All @@ -86,7 +86,7 @@ def to_csv(

if x.ndim not in (1, 2):
raise ValueError(
"cannot convert arrays with %d dimensions into " "pandas objects" % x.ndim
"cannot convert arrays with %d dimensions into pandas objects" % x.ndim
)

if nogil and x.dtype.kind not in "if":
Expand Down
2 changes: 1 addition & 1 deletion xarray_extras/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def splev(
dims = [tck.spline_dim]
else:
raise ValueError(
"N-dimensional x_new is only supported if " "x_new is a DataArray"
"N-dimensional x_new is only supported if x_new is a DataArray"
)
x_new = xarray.DataArray(x_new, dims=dims, coords={tck.spline_dim: x_new})

Expand Down
4 changes: 2 additions & 2 deletions xarray_extras/kernels/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def to_csv(
x_pd = pd.DataFrame(x, index, columns)
else:
# proper ValueError already raised in wrapper
assert False, "unreachable" # pragma: nocover
raise AssertionError("unreachable") # pragma: nocover

encoding = kwargs.pop("encoding", "utf-8")
header = kwargs.pop("header", True)
Expand Down Expand Up @@ -83,7 +83,7 @@ def to_csv(
elif x.dtype.kind == "f":
body_bytes = snprintcsvd(x, index_csv, sep, fmt, na_rep)
else:
raise NotImplementedError("only int and float are supported when " "nogil=True")
raise NotImplementedError("only int and float are supported when nogil=True")

if header is not False:
header_bytes = (
Expand Down
3 changes: 1 addition & 2 deletions xarray_extras/kernels/cumulatives.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
"""Numba kernels for :mod:`cumulatives`
"""
import numpy as np
Expand Down Expand Up @@ -39,7 +38,7 @@ def compound_mean(x: np.ndarray, c: np.ndarray, y: np.ndarray) -> None:
"""
acc = 0
j = 0 # Initialise j explicitly for when x.shape == (0, )
for j, i in enumerate(c):
for j, i in enumerate(c): # noqa: B007
if i == -1:
break
acc += x[i]
Expand Down
Loading

0 comments on commit 350892c

Please sign in to comment.