Skip to content

Commit b9780e7

Browse files
authored
Replace black and blackdoc with ruff-format (#9506)
* Replace black with ruff-format * Fix formatting mistakes moving mypy comments * Replace black with ruff in the contributing guides
1 parent 1e579fb commit b9780e7

33 files changed

Lines changed: 41 additions & 70 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,15 @@ repos:
1515
# Ruff version.
1616
rev: 'v0.6.9'
1717
hooks:
18+
- id: ruff-format
1819
- id: ruff
1920
args: ["--fix", "--show-fixes"]
20-
# https://github.com/python/black#version-control-integration
21-
- repo: https://github.com/psf/black-pre-commit-mirror
22-
rev: 24.8.0
23-
hooks:
24-
- id: black-jupyter
2521
- repo: https://github.com/keewis/blackdoc
2622
rev: v0.3.9
2723
hooks:
2824
- id: blackdoc
2925
exclude: "generate_aggregations.py"
3026
additional_dependencies: ["black==24.8.0"]
31-
- id: blackdoc-autoupdate-black
3227
- repo: https://github.com/pre-commit/mirrors-mypy
3328
rev: v1.11.2
3429
hooks:

CORE_TEAM_GUIDE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ resources such as:
271271
[NumPy documentation guide](https://numpy.org/devdocs/dev/howto-docs.html#documentation-style)
272272
for docstring conventions.
273273
- [`pre-commit`](https://pre-commit.com) hooks for autoformatting.
274-
- [`black`](https://github.com/psf/black) autoformatting.
275-
- [`flake8`](https://github.com/PyCQA/flake8) linting.
274+
- [`ruff`](https://github.com/astral-sh/ruff) autoformatting and linting.
276275
- [python-xarray](https://stackoverflow.com/questions/tagged/python-xarray) on Stack Overflow.
277276
- [@xarray_dev](https://twitter.com/xarray_dev) on Twitter.
278277
- [xarray-dev](https://discord.gg/bsSGdwBn) discord community (normally only used for remote synchronous chat during sprints).

ci/min_deps_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
publication date. Compare it against requirements/min-all-deps.yml to verify the
44
policy on obsolete dependencies is being followed. Print a pretty report :)
55
"""
6+
67
from __future__ import annotations
78

89
import itertools
@@ -16,7 +17,6 @@
1617

1718
CHANNELS = ["conda-forge", "defaults"]
1819
IGNORE_DEPS = {
19-
"black",
2020
"coveralls",
2121
"flake8",
2222
"hypothesis",

ci/requirements/all-but-dask.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- black
76
- aiobotocore
87
- array-api-strict
98
- boto3

doc/contributing.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,7 @@ Code Formatting
549549

550550
xarray uses several tools to ensure a consistent code format throughout the project:
551551

552-
- `Black <https://black.readthedocs.io/en/stable/>`_ for standardized
553-
code formatting,
554-
- `blackdoc <https://blackdoc.readthedocs.io/en/stable/>`_ for
555-
standardized code formatting in documentation,
556-
- `ruff <https://github.com/charliermarsh/ruff/>`_ for code quality checks and standardized order in imports
552+
- `ruff <https://github.com/astral-sh/ruff>`_ for formatting, code quality checks and standardized order in imports
557553
- `absolufy-imports <https://github.com/MarcoGorelli/absolufy-imports>`_ for absolute instead of relative imports from different files,
558554
- `mypy <http://mypy-lang.org/>`_ for static type checking on `type hints
559555
<https://docs.python.org/3/library/typing.html>`_.
@@ -1069,7 +1065,7 @@ PR checklist
10691065
- Test the code using `Pytest <http://doc.pytest.org/en/latest/>`_. Running all tests (type ``pytest`` in the root directory) takes a while, so feel free to only run the tests you think are needed based on your PR (example: ``pytest xarray/tests/test_dataarray.py``). CI will catch any failing tests.
10701066
- By default, the upstream dev CI is disabled on pull request and push events. You can override this behavior per commit by adding a ``[test-upstream]`` tag to the first line of the commit message. For documentation-only commits, you can skip the CI per commit by adding a ``[skip-ci]`` tag to the first line of the commit message.
10711067
1072-
- **Properly format your code** and verify that it passes the formatting guidelines set by `Black <https://black.readthedocs.io/en/stable/>`_ and `Flake8 <http://flake8.pycqa.org/en/latest/>`_. See `"Code formatting" <https://docs.xarray.dev/en/stablcontributing.html#code-formatting>`_. You can use `pre-commit <https://pre-commit.com/>`_ to run these automatically on each commit.
1068+
- **Properly format your code** and verify that it passes the formatting guidelines set by `ruff <https://github.com/astral-sh/ruff>`_. See `"Code formatting" <https://docs.xarray.dev/en/stablcontributing.html#code-formatting>`_. You can use `pre-commit <https://pre-commit.com/>`_ to run these automatically on each commit.
10731069
10741070
- Run ``pre-commit run --all-files`` in the root directory. This may modify some files. Confirm and commit any formatting changes.
10751071

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ extend-exclude = [
233233

234234
[tool.ruff.lint]
235235
# E402: module level import not at top of file
236-
# E501: line too long - let black worry about that
236+
# E501: line too long - let the formatter worry about that
237237
# E731: do not assign a lambda expression, use a def
238238
extend-safe-fixes = [
239239
"TID252", # absolute imports

xarray/backends/common.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,10 @@ def load(self):
206206
For example::
207207
208208
class SuffixAppendingDataStore(AbstractDataStore):
209-
210209
def load(self):
211210
variables, attributes = AbstractDataStore.load(self)
212-
variables = {'%s_suffix' % k: v
213-
for k, v in variables.items()}
214-
attributes = {'%s_suffix' % k: v
215-
for k, v in attributes.items()}
211+
variables = {"%s_suffix" % k: v for k, v in variables.items()}
212+
attributes = {"%s_suffix" % k: v for k, v in attributes.items()}
216213
return variables, attributes
217214
218215
This function will be called anytime variables or attributes

xarray/backends/file_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CachingFileManager(FileManager):
6565
6666
Example usage::
6767
68-
manager = FileManager(open, 'example.txt', mode='w')
68+
manager = FileManager(open, "example.txt", mode="w")
6969
f = manager.acquire()
7070
f.write(...)
7171
manager.close() # ensures file is closed

xarray/backends/h5netcdf_.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ def open_datatree(
474474
driver_kwds=None,
475475
**kwargs,
476476
) -> DataTree:
477-
478477
from xarray.core.datatree import DataTree
479478

480479
groups_dict = self.open_groups_as_dict(
@@ -520,7 +519,6 @@ def open_groups_as_dict(
520519
driver_kwds=None,
521520
**kwargs,
522521
) -> dict[str, Dataset]:
523-
524522
from xarray.backends.common import _iter_nc_groups
525523
from xarray.core.treenode import NodePath
526524
from xarray.core.utils import close_on_error

xarray/backends/netCDF4_.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,6 @@ def open_datatree(
710710
autoclose=False,
711711
**kwargs,
712712
) -> DataTree:
713-
714713
from xarray.core.datatree import DataTree
715714

716715
groups_dict = self.open_groups_as_dict(

0 commit comments

Comments
 (0)