Skip to content
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

Replace black with ruff #5634

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ repos:
- id: ruff
types: [file, python]
args: [--fix, --show-fixes]
- id: ruff-format
types: [file, python]

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
Expand All @@ -42,13 +44,6 @@ repos:
types_or: [asciidoc, python, markdown, rst]
additional_dependencies: [tomli]

- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
pass_filenames: false
args: [--config=./pyproject.toml, .]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
analysing and visualising Earth science data
</h4>

| | |
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ⚙️ CI | [![ci-manifest](https://github.com/SciTools/iris/actions/workflows/ci-manifest.yml/badge.svg)](https://github.com/SciTools/iris/actions/workflows/ci-manifest.yml) [![ci-tests](https://github.com/SciTools/iris/actions/workflows/ci-tests.yml/badge.svg)](https://github.com/SciTools/iris/actions/workflows/ci-tests.yml) [![ci-wheels](https://github.com/SciTools/iris/actions/workflows/ci-wheels.yml/badge.svg)](https://github.com/SciTools/iris/actions/workflows/ci-wheels.yml) [![pre-commit](https://results.pre-commit.ci/badge/github/SciTools/iris/main.svg)](https://results.pre-commit.ci/latest/github/SciTools/iris/main) |
| 💬 Community | [![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-2.1-4baaaa.svg)](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) [![GH Discussions](https://img.shields.io/badge/github-discussions%20%F0%9F%92%AC-yellow?logo=github&logoColor=lightgrey)](https://github.com/SciTools/iris/discussions) [![twitter](https://img.shields.io/twitter/follow/scitools_iris?color=yellow&label=twitter%7Cscitools_iris&logo=twitter&style=plastic)](https://twitter.com/scitools_iris) |
| 📖 Documentation | [![rtd](https://readthedocs.org/projects/scitools-iris/badge/?version=latest)](https://scitools-iris.readthedocs.io/en/latest/?badge=latest) |
| 📈 Health | [![codecov](https://codecov.io/gh/SciTools/iris/branch/main/graph/badge.svg?token=0GeICSIF3g)](https://codecov.io/gh/SciTools/iris) |
| ✨ Meta | [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![code style - black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![NEP29](https://raster.shields.io/badge/follows-NEP29-orange.png)](https://numpy.org/neps/nep-0029-deprecation_policy.html) [![license - bds-3-clause](https://img.shields.io/github/license/SciTools/iris)](https://github.com/SciTools/iris/blob/main/LICENSE) [![conda platform](https://img.shields.io/conda/pn/conda-forge/iris.svg)](https://anaconda.org/conda-forge/iris) |
| 📦 Package | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.595182.svg)](https://doi.org/10.5281/zenodo.595182) [![conda-forge](https://img.shields.io/conda/vn/conda-forge/iris?color=orange&label=conda-forge&logo=conda-forge&logoColor=white)](https://anaconda.org/conda-forge/iris) [![pypi](https://img.shields.io/pypi/v/scitools-iris?color=orange&label=pypi&logo=python&logoColor=white)](https://pypi.org/project/scitools-iris/) [![pypi - python version](https://img.shields.io/pypi/pyversions/scitools-iris.svg?color=orange&logo=python&label=python&logoColor=white)](https://pypi.org/project/scitools-iris/) |
| 🧰 Repo | [![commits-since](https://img.shields.io/github/commits-since/SciTools/iris/latest.svg)](https://github.com/SciTools/iris/commits/main) [![contributors](https://img.shields.io/github/contributors/SciTools/iris)](https://github.com/SciTools/iris/graphs/contributors) [![release](https://img.shields.io/github/v/release/scitools/iris)](https://github.com/SciTools/iris/releases) |
| | |
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ⚙️ CI | [![ci-manifest](https://github.com/SciTools/iris/actions/workflows/ci-manifest.yml/badge.svg)](https://github.com/SciTools/iris/actions/workflows/ci-manifest.yml) [![ci-tests](https://github.com/SciTools/iris/actions/workflows/ci-tests.yml/badge.svg)](https://github.com/SciTools/iris/actions/workflows/ci-tests.yml) [![ci-wheels](https://github.com/SciTools/iris/actions/workflows/ci-wheels.yml/badge.svg)](https://github.com/SciTools/iris/actions/workflows/ci-wheels.yml) [![pre-commit](https://results.pre-commit.ci/badge/github/SciTools/iris/main.svg)](https://results.pre-commit.ci/latest/github/SciTools/iris/main) |
| 💬 Community | [![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-2.1-4baaaa.svg)](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) [![GH Discussions](https://img.shields.io/badge/github-discussions%20%F0%9F%92%AC-yellow?logo=github&logoColor=lightgrey)](https://github.com/SciTools/iris/discussions) [![twitter](https://img.shields.io/twitter/follow/scitools_iris?color=yellow&label=twitter%7Cscitools_iris&logo=twitter&style=plastic)](https://twitter.com/scitools_iris) |
| 📖 Documentation | [![rtd](https://readthedocs.org/projects/scitools-iris/badge/?version=latest)](https://scitools-iris.readthedocs.io/en/latest/?badge=latest) |
| 📈 Health | [![codecov](https://codecov.io/gh/SciTools/iris/branch/main/graph/badge.svg?token=0GeICSIF3g)](https://codecov.io/gh/SciTools/iris) |
| ✨ Meta | [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![NEP29](https://raster.shields.io/badge/follows-NEP29-orange.png)](https://numpy.org/neps/nep-0029-deprecation_policy.html) [![license - bds-3-clause](https://img.shields.io/github/license/SciTools/iris)](https://github.com/SciTools/iris/blob/main/LICENSE) [![conda platform](https://img.shields.io/conda/pn/conda-forge/iris.svg)](https://anaconda.org/conda-forge/iris) |
| 📦 Package | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.595182.svg)](https://doi.org/10.5281/zenodo.595182) [![conda-forge](https://img.shields.io/conda/vn/conda-forge/iris?color=orange&label=conda-forge&logo=conda-forge&logoColor=white)](https://anaconda.org/conda-forge/iris) [![pypi](https://img.shields.io/pypi/v/scitools-iris?color=orange&label=pypi&logo=python&logoColor=white)](https://pypi.org/project/scitools-iris/) [![pypi - python version](https://img.shields.io/pypi/pyversions/scitools-iris.svg?color=orange&logo=python&label=python&logoColor=white)](https://pypi.org/project/scitools-iris/) |
| 🧰 Repo | [![commits-since](https://img.shields.io/github/commits-since/SciTools/iris/latest.svg)](https://github.com/SciTools/iris/commits/main) [![contributors](https://img.shields.io/github/contributors/SciTools/iris)](https://github.com/SciTools/iris/graphs/contributors) [![release](https://img.shields.io/github/v/release/scitools/iris)](https://github.com/SciTools/iris/releases) |
| |

<p align="center">
Expand Down
5 changes: 3 additions & 2 deletions docs/gallery_code/general/plot_projections_and_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ def make_plot(projection_name, projection_crs):

# Add a title, and display.
plt.title(
"A pseudocolour plot on the {} projection,\n"
"with overlaid contours.".format(projection_name)
"A pseudocolour plot on the {} projection,\nwith overlaid contours.".format(
projection_name
)
)
iplt.show()

Expand Down
4 changes: 1 addition & 3 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,7 @@ def _dotv(version):

# if we are building via Read The Docs and it is the latest (not stable)
if on_rtd and rtd_version == "latest":
html_theme_options[
"announcement"
] = f"""
html_theme_options["announcement"] = f"""
You are viewing the <b>latest</b> unreleased documentation
<strong>{version}</strong>. You can switch to a
<a href="https://scitools-iris.readthedocs.io/en/stable/">stable</a>
Expand Down
2 changes: 2 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ This document explains the changes made to Iris for this release

#. `@bjlittle`_ replaced `isort`_ with `ruff`_. (:pull:`5633`)

#. `@bjlittle`_ replaced `black`_ with `ruff`_. (:pull:`5634`)


.. comment
Whatsnew author names (@github name) in alphabetical order. Note that,
Expand Down
5 changes: 3 additions & 2 deletions lib/iris/analysis/_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ def _get_horizontal_coord(cube, axis):
coords = cube.coords(axis=axis, dim_coords=False)
if len(coords) != 1:
raise ValueError(
"Cube {!r} must contain a single 1D {} "
"coordinate.".format(cube.name(), axis)
"Cube {!r} must contain a single 1D {} coordinate.".format(
cube.name(), axis
)
)
return coords[0]

Expand Down
10 changes: 6 additions & 4 deletions lib/iris/analysis/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ def cube_delta(cube, coord):
coord.shape[0] == 1 and not getattr(coord, "circular", False)
) or not delta_dims:
raise ValueError(
"Cannot calculate delta over {!r} as it has "
"length of 1.".format(coord.name())
"Cannot calculate delta over {!r} as it has length of 1.".format(
coord.name()
)
)
delta_dim = delta_dims[0]

Expand Down Expand Up @@ -570,8 +571,9 @@ def curl(i_cube, j_cube, k_cube=None):
bad_coords = coord_comparison["resamplable"]
if bad_coords:
raise ValueError(
"Some coordinates are different ({}), consider "
"resampling.".format(", ".join(group.name() for group in bad_coords))
"Some coordinates are different ({}), consider resampling.".format(
", ".join(group.name() for group in bad_coords)
)
)

# Get the dim_coord, or None if none exist, for the xyz dimensions
Expand Down
13 changes: 7 additions & 6 deletions lib/iris/analysis/cartography.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,9 @@ def area_weights(cube, normalize=False):
lon, lat = _get_lon_lat_coords(cube)
except IndexError:
raise ValueError(
"Cannot get latitude/longitude "
"coordinates from cube {!r}.".format(cube.name())
"Cannot get latitude/longitude coordinates from cube {!r}.".format(
cube.name()
)
)

if lat.ndim > 1:
Expand Down Expand Up @@ -631,8 +632,9 @@ def project(cube, target_proj, nx=None, ny=None):
lon_coord, lat_coord = _get_lon_lat_coords(cube)
except IndexError:
raise ValueError(
"Cannot get latitude/longitude "
"coordinates from cube {!r}.".format(cube.name())
"Cannot get latitude/longitude coordinates from cube {!r}.".format(
cube.name()
)
)

if lat_coord.coord_system != lon_coord.coord_system:
Expand Down Expand Up @@ -840,8 +842,7 @@ def project(cube, target_proj, nx=None, ny=None):
discarded_coords = coords_to_ignore.difference([lat_coord, lon_coord])
if discarded_coords:
warnings.warn(
"Discarding coordinates that share dimensions with "
"{} and {}: {}".format(
"Discarding coordinates that share dimensions with {} and {}: {}".format(
lat_coord.name(),
lon_coord.name(),
[coord.name() for coord in discarded_coords],
Expand Down
20 changes: 8 additions & 12 deletions lib/iris/aux_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,8 @@ def _check_dependencies(sigma, eta, depth, depth_c, nsigma, zlev):
sigma.units = cf_units.Unit("1")

if sigma is not None and not sigma.units.is_dimensionless():
msg = (
"Invalid units: sigma coordinate {!r} "
"must be dimensionless.".format(sigma.name())
msg = "Invalid units: sigma coordinate {!r} must be dimensionless.".format(
sigma.name()
)
raise ValueError(msg)

Expand Down Expand Up @@ -1198,9 +1197,8 @@ def _check_dependencies(sigma, eta, depth):
# Check bounds and shape.
coord, term = (sigma, "sigma")
if coord is not None and coord.nbounds not in (0, 2):
msg = (
"Invalid {} coordinate {!r}: must have either "
"0 or 2 bounds.".format(term, coord.name())
msg = "Invalid {} coordinate {!r}: must have either 0 or 2 bounds.".format(
term, coord.name()
)
raise ValueError(msg)

Expand All @@ -1219,9 +1217,8 @@ def _check_dependencies(sigma, eta, depth):
sigma.units = cf_units.Unit("1")

if sigma is not None and not sigma.units.is_dimensionless():
msg = (
"Invalid units: sigma coordinate {!r} "
"must be dimensionless.".format(sigma.name())
msg = "Invalid units: sigma coordinate {!r} must be dimensionless.".format(
sigma.name()
)
raise ValueError(msg)

Expand Down Expand Up @@ -1550,9 +1547,8 @@ def _check_dependencies(s, eta, depth, a, b, depth_c):

# Check bounds and shape.
if s is not None and s.nbounds not in (0, 2):
msg = (
"Invalid s coordinate {!r}: must have either "
"0 or 2 bounds.".format(s.name())
msg = "Invalid s coordinate {!r}: must have either 0 or 2 bounds.".format(
s.name()
)
raise ValueError(msg)

Expand Down
10 changes: 6 additions & 4 deletions lib/iris/coord_categorisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,19 @@ def _validate_seasons(seasons):
]
if not_present:
raise ValueError(
"some months do not appear in any season: "
"{!s}".format(", ".join(not_present))
"some months do not appear in any season: {!s}".format(
", ".join(not_present)
)
)
# Make a list of months that appear multiple times...
multi_present = [
calendar.month_abbr[month] for month in range(1, 13) if c[month] > 1
]
if multi_present:
raise ValueError(
"some months appear in more than one season: "
"{!s}".format(", ".join(multi_present))
"some months appear in more than one season: {!s}".format(
", ".join(multi_present)
)
)
return

Expand Down