Skip to content

Commit 906d9a2

Browse files
authored
chore: use more ruff (#524)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 3ad1a71 commit 906d9a2

21 files changed

+226
-207
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,13 @@ repos:
1616
- id: requirements-txt-fixer
1717
- id: trailing-whitespace
1818

19-
- repo: https://github.com/asottile/setup-cfg-fmt
20-
rev: "v2.5.0"
21-
hooks:
22-
- id: setup-cfg-fmt
23-
args: ["--include-version-classifiers", "--max-py-version=3.12"]
24-
25-
- repo: https://github.com/nbQA-dev/nbQA
26-
rev: 1.8.7
27-
hooks:
28-
- id: nbqa-pyupgrade
29-
additional_dependencies: [pyupgrade]
30-
args: ["--py38-plus"]
31-
32-
- repo: https://github.com/psf/black-pre-commit-mirror
33-
rev: 24.8.0
34-
hooks:
35-
- id: black-jupyter
36-
3719
- repo: https://github.com/astral-sh/ruff-pre-commit
3820
# Ruff version.
39-
rev: v0.6.7
21+
rev: v0.6.9
4022
hooks:
4123
# Run the linter.
4224
- id: ruff
43-
args: [ --fix ]
25+
args: [ --fix, --show-fixes ]
4426
# Run the formatter.
4527
- id: ruff-format
4628

docs/source/conf.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
# Add mplhep to path for sphinx-automodapi
2323
sys.path.insert(0, os.path.abspath("../../src"))
2424

25-
import mplhep # noqa: E402
2625
from pathlib import Path
2726

28-
print("sys.path:", sys.path)
29-
print("mplhep version:", mplhep.__version__)
27+
import mplhep
3028

3129
# -- Project information -----------------------------------------------------
3230

@@ -70,19 +68,18 @@ def linkcode_resolve(domain, info):
7068
mod = importlib.import_module(info["module"])
7169
modpath = [p for p in sys.path if mod.__file__.startswith(p)]
7270
if len(modpath) < 1:
73-
raise RuntimeError("Cannot deduce module path")
71+
msg = "Cannot deduce module path"
72+
raise RuntimeError(msg)
7473
modpath = modpath[0]
75-
obj = reduce(getattr, [mod] + info["fullname"].split("."))
74+
obj = reduce(getattr, [mod, *info["fullname"].split(".")])
7675
try:
7776
path = inspect.getsourcefile(obj)
7877
relpath = path[len(modpath) + 1 :]
7978
_, lineno = inspect.getsourcelines(obj)
8079
except TypeError:
8180
# skip property or other type that inspect doesn't like
8281
return None
83-
return "http://github.com/scikit-hep/mplhep/blob/{}/{}#L{}".format(
84-
githash, relpath, lineno
85-
)
82+
return f"http://github.com/scikit-hep/mplhep/blob/{githash}/{relpath}#L{lineno}"
8683

8784

8885
intersphinx_mapping = {

examples/Examples.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
},
1212
"outputs": [],
1313
"source": [
14-
"import numpy as np\n",
1514
"import matplotlib.pyplot as plt\n",
15+
"import numpy as np\n",
1616
"\n",
1717
"import mplhep as hep"
1818
]

pyproject.toml

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ dependencies = [
3636

3737
[project.optional-dependencies]
3838
dev = [
39-
"black",
4039
"bumpversion",
41-
"flake8",
4240
"jupyter",
4341
"pre-commit",
4442
"twine",
@@ -67,14 +65,16 @@ version.source = "vcs"
6765
build.hooks.vcs.version-file = "src/mplhep/_version.py"
6866

6967

70-
[tool.nbqa.mutate]
71-
pyupgrade = 1
72-
73-
[tool.nbqa.addopts]
74-
pyupgrade = ["--py38-plus"]
68+
[tool.uv]
69+
environments = [
70+
"python_version >= '3.10'",
71+
]
72+
dev-dependencies = [
73+
"mplhep[test]",
74+
]
7575

7676

77-
[tools.mypy]
77+
[tool.mypy]
7878
files = ["src"]
7979
python_version = 3.8
8080
warn_unused_configs = true
@@ -85,7 +85,7 @@ allow_redefinition = true
8585
# disallow_untyped_calls = true
8686
# disallow_untyped_defs = true
8787
# disallow_incomplete_defs = true
88-
check_untyped_defs = true
88+
check_untyped_defs = false
8989
# disallow_untyped_decorators = true
9090
# no_implicit_optional = true
9191
# warn_redundant_casts = true
@@ -106,5 +106,41 @@ testpaths = ["tests"]
106106
python_files = "test*.py"
107107

108108

109-
[tool.isort]
110-
profile = "black"
109+
[tool.ruff.lint]
110+
extend-select = [
111+
"B", # flake8-bugbear
112+
"I", # isort
113+
"ARG", # flake8-unused-arguments
114+
"C4", # flake8-comprehensions
115+
"EM", # flake8-errmsg
116+
"ICN", # flake8-import-conventions
117+
"G", # flake8-logging-format
118+
"PGH", # pygrep-hooks
119+
"PIE", # flake8-pie
120+
"PL", # pylint
121+
"PT", # flake8-pytest-style
122+
"RET", # flake8-return
123+
"RUF", # Ruff-specific
124+
"SIM", # flake8-simplify
125+
"T20", # flake8-print
126+
"UP", # pyupgrade
127+
"YTT", # flake8-2020
128+
"EXE", # flake8-executable
129+
"NPY", # NumPy specific rules
130+
"PD", # pandas-vet
131+
"FURB", # refurb
132+
"PYI", # flake8-pyi
133+
]
134+
ignore = [
135+
"PLR09", # Too many <...>
136+
"PLR2004", # Magic value used in comparison
137+
"ISC001", # Conflicts with formatter
138+
"NPY002", # np.random.Generator
139+
"G004", # Logging with f-string
140+
"PD011", # .values vs .to_numpy can get confused
141+
"PT013", # Import from pytest
142+
]
143+
144+
[tool.ruff.lint.per-file-ignores]
145+
"tests/**" = ["T20"]
146+
"docs/conf.py" = ["T20"]

src/mplhep/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
rescale_to_axessize,
2424
sort_legend,
2525
ylow,
26-
yscale_legend,
2726
yscale_anchored_text,
27+
yscale_legend,
2828
)
2929
from .styles import set_style
3030

src/mplhep/_deprecate.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ def __init__(self, name, reason="", warn_once: bool = True, warning=FutureWarnin
4848

4949
def __call__(self, func):
5050
def decorated_func(*args, **kwargs):
51-
if self._name in kwargs.keys() and not (
52-
self._warn_once and self._already_warned
53-
):
51+
if self._name in kwargs and not (self._warn_once and self._already_warned):
5452
warnings.warn(
55-
'kwarg "{}" in function ``{}`` is deprecated and may be removed in future versions: {}'.format(
56-
self._name, func.__name__, self._reason
57-
),
53+
f'kwarg "{self._name}" in function ``{func.__name__}`` is deprecated and may be removed in future versions: {self._reason}',
5854
category=self._warning,
5955
stacklevel=2,
6056
)

src/mplhep/_version.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
from __future__ import annotations
2-
31
version: str
42
version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str]

src/mplhep/alice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def text(text="", **kwargs):
1919
for key, value in dict(mplhep.rcParams.text._get_kwargs()).items():
2020
if (
2121
value is not None
22-
and key not in kwargs.keys()
22+
and key not in kwargs
2323
and key in inspect.getfullargspec(label_base.exp_text).kwonlyargs
2424
):
2525
kwargs.setdefault(key, value)
@@ -31,7 +31,7 @@ def label(label=None, **kwargs):
3131
for key, value in dict(mplhep.rcParams.label._get_kwargs()).items():
3232
if (
3333
value is not None
34-
and key not in kwargs.keys()
34+
and key not in kwargs
3535
and key in inspect.getfullargspec(label_base.exp_label).kwonlyargs
3636
):
3737
kwargs.setdefault(key, value)

src/mplhep/atlas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def text(text="", **kwargs):
2121
for key, value in dict(mplhep.rcParams.text._get_kwargs()).items():
2222
if (
2323
value is not None
24-
and key not in kwargs.keys()
24+
and key not in kwargs
2525
and key in inspect.getfullargspec(label_base.exp_text).kwonlyargs
2626
):
2727
kwargs.setdefault(key, value)
@@ -35,7 +35,7 @@ def label(label=None, **kwargs):
3535
for key, value in dict(mplhep.rcParams.label._get_kwargs()).items():
3636
if (
3737
value is not None
38-
and key not in kwargs.keys()
38+
and key not in kwargs
3939
and key in inspect.getfullargspec(label_base.exp_label).kwonlyargs
4040
):
4141
kwargs.setdefault(key, value)

src/mplhep/cms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def text(text="", **kwargs):
2121
for key, value in dict(mplhep.rcParams.text._get_kwargs()).items():
2222
if (
2323
value is not None
24-
and key not in kwargs.keys()
24+
and key not in kwargs
2525
and key in inspect.getfullargspec(label_base.exp_text).kwonlyargs
2626
):
2727
kwargs.setdefault(key, value)
@@ -35,7 +35,7 @@ def label(label=None, **kwargs):
3535
for key, value in dict(mplhep.rcParams.label._get_kwargs()).items():
3636
if (
3737
value is not None
38-
and key not in kwargs.keys()
38+
and key not in kwargs
3939
and key in inspect.getfullargspec(label_base.exp_label).kwonlyargs
4040
):
4141
kwargs.setdefault(key, value)

0 commit comments

Comments
 (0)