Skip to content

Commit 2e478c5

Browse files
authored
switch to ruff (#164)
* switch to ruff * fixes
1 parent 7f5ecec commit 2e478c5

File tree

8 files changed

+39
-40
lines changed

8 files changed

+39
-40
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
- [ ] Closes #xxx
44
- [ ] Tests added
5-
- [ ] Passes `isort . && black . && flake8`
65
- [ ] Fully documented, including `CHANGELOG.md`

.pre-commit-config.yaml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,14 @@ repos:
88
- id: check-yaml
99
- id: debug-statements
1010
- id: mixed-line-ending
11-
# This wants to go before isort & flake8
12-
- repo: https://github.com/PyCQA/autoflake
13-
rev: "v2.3.1"
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
# Ruff version.
13+
rev: 'v0.12.7'
1414
hooks:
15-
- id: autoflake # isort should run before black as black sometimes tweaks the isort output
16-
args: ["--in-place", "--ignore-init-module-imports"]
17-
- repo: https://github.com/PyCQA/isort
18-
rev: 5.13.2
19-
hooks:
20-
- id: isort
15+
- id: ruff
16+
args: ["--fix", "--show-fixes"]
2117
# https://github.com/python/black#version-control-integration
2218
- repo: https://github.com/psf/black
2319
rev: 24.10.0
2420
hooks:
2521
- id: black
26-
- repo: https://github.com/PyCQA/flake8
27-
rev: 7.1.1
28-
hooks:
29-
- id: flake8

ci/min_deps_check.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import sys
1212
from collections.abc import Iterator
1313
from datetime import datetime
14-
from typing import Optional
1514

1615
import conda.api # type: ignore[import]
1716
import yaml
@@ -30,6 +29,7 @@
3029
"pytest-cov",
3130
"pytest-env",
3231
"pytest-xdist",
32+
"ruff",
3333
}
3434

3535
POLICY_MONTHS = {"python": 24, "numpy": 18, "setuptools": 42}
@@ -57,7 +57,7 @@ def warning(msg: str) -> None:
5757
print("WARNING:", msg)
5858

5959

60-
def parse_requirements(fname) -> Iterator[tuple[str, int, int, Optional[int]]]:
60+
def parse_requirements(fname) -> Iterator[tuple[str, int, int, int | None]]:
6161
"""Load requirements/py*-min-all-deps.yml
6262
6363
Yield (package name, major version, minor version, [patch version])
@@ -128,7 +128,7 @@ def metadata(entry):
128128

129129

130130
def process_pkg(
131-
pkg: str, req_major: int, req_minor: int, req_patch: Optional[int]
131+
pkg: str, req_major: int, req_minor: int, req_patch: int | None
132132
) -> tuple[str, str, str, str, str, str]:
133133
"""Compare package version from requirements file to available versions in conda.
134134
Return row to build pandas dataframe:
@@ -140,7 +140,7 @@ def process_pkg(
140140
- publication date of version suggested by policy (YYYY-MM-DD)
141141
- status ("<", "=", "> (!)")
142142
"""
143-
print("Analyzing %s..." % pkg)
143+
print(f"Analyzing {pkg}...")
144144
versions = query_conda(pkg)
145145

146146
try:

ci/requirements/environment.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ dependencies:
1010
- xarray
1111
# formatting
1212
- black
13-
- isort
14-
- flake8
13+
- ruff
1514
# for testing
1615
- pytest
1716
- pytest-cov

mplotutils/_cartopy_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def yticklabels(
327327
if not y_label_points:
328328
msg = (
329329
"WARN: no points found for ylabel\n"
330-
"y_lim is: {:0.2f} to {:0.2f}".format(y_lim[0], y_lim[1])
330+
f"y_lim is: {y_lim[0]:0.2f} to {y_lim[1]:0.2f}"
331331
)
332332
warnings.warn(msg)
333333

@@ -427,7 +427,7 @@ def xticklabels(
427427
if not x_label_points:
428428
msg = (
429429
"WARN: no points found for xlabel\n"
430-
"x_lim is: {:0.2f} to {:0.2f}".format(x_lim[0], x_lim[1])
430+
f"x_lim is: {x_lim[0]:0.2f} to {x_lim[1]:0.2f}"
431431
)
432432
warnings.warn(msg)
433433

mplotutils/_colormaps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _color_palette(cmap, n_colors):
5555
from matplotlib.colors import ListedColormap
5656

5757
colors_i = np.linspace(0, 1.0, n_colors)
58-
if isinstance(cmap, (list, tuple)):
58+
if isinstance(cmap, list | tuple):
5959
# expand or truncate the list of colors to n_colors
6060
cmap = list(itertools.islice(itertools.cycle(cmap), n_colors))
6161
cmap = ListedColormap(cmap)

pyproject.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@ build-backend = "setuptools.build_meta"
99
fallback_version = "999"
1010
version_scheme = "no-guess-dev"
1111

12+
13+
[tool.ruff]
14+
# also check notebooks
15+
extend-include = ["*.ipynb"]
16+
target-version = "py310"
17+
18+
[tool.ruff.lint]
19+
# E402: module level import not at top of file
20+
# E501: line too long - let the formatter worry about this
21+
# E731: do not assign a lambda expression, use a def
22+
ignore = [
23+
"E402",
24+
"E501",
25+
"E731",
26+
]
27+
select = [
28+
"F", # Pyflakes
29+
"E", # Pycodestyle
30+
"W", # warnings
31+
"I", # isort
32+
"UP", # Pyupgrade
33+
]
34+
35+
[tool.ruff.lint.isort]
36+
known-first-party = ["mplotutils"]
37+
1238
[tool.pytest.ini_options]
1339

1440
log_cli_level = "INFO"

setup.cfg

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ install_requires =
2929
numpy >=1.26
3030
xarray >=2024.7
3131

32-
[flake8]
33-
ignore=
34-
# E203: whitespace before ':' - doesn't work well with black
35-
# E402: module level import not at top of file
36-
# E501: line too long - let black worry about that
37-
# E731: do not assign a lambda expression, use a def
38-
# W503: line break before binary operator
39-
E203, E402, E501, E731, W503
40-
exclude =
41-
build
42-
docs
43-
.git
44-
45-
[isort]
46-
profile = black
47-
known_first_party = mplotutils
48-
4932
[coverage:run]
5033
omit =
5134
*/tests/*,

0 commit comments

Comments
 (0)