Skip to content

Commit 1e2e70d

Browse files
committed
use ruff
1 parent 88ff491 commit 1e2e70d

File tree

7 files changed

+46
-41
lines changed

7 files changed

+46
-41
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,12 @@ repos:
3939
hooks:
4040
- id: black
4141

42-
# Python docstring formatting
43-
- repo: https://github.com/pycqa/pydocstyle
44-
rev: 6.3.0
42+
# Ruff linter, replacement for flake8, pydocstyle, isort
43+
- repo: https://github.com/astral-sh/ruff-pre-commit
44+
rev: 'v0.3.3'
4545
hooks:
46-
- id: pydocstyle
47-
files: src/pyhepmc/[^_].*\\.py
48-
49-
# Python linter (Flake8)
50-
- repo: https://github.com/pycqa/flake8
51-
rev: 7.0.0
52-
hooks:
53-
- id: flake8
54-
exclude: ^(docs/.*|tests/.*)$
46+
- id: ruff
47+
args: [--fix, --show-fixes]
5548

5649
# C++ formatting
5750
- repo: https://github.com/pre-commit/mirrors-clang-format

pyproject.toml

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = [
33
"setuptools>=46.4",
44
"setuptools_scm[toml]>=6.2",
55
"cmake>=3.13",
6-
"wheel"
6+
"wheel",
77
]
88
build-backend = "setuptools.build_meta"
99

@@ -12,11 +12,11 @@ name = "pyhepmc"
1212
description = "Pythonic interface to the HepMC3 C++ library licensed under LGPL-v3."
1313
maintainers = [
1414
{ name = "Hans Dembinski" },
15-
{ email = "[email protected]" }
15+
{ email = "[email protected]" },
1616
]
1717
readme = "README.rst"
1818
requires-python = ">=3.8"
19-
license = {text = "BSD 3-Clause License"}
19+
license = { text = "BSD 3-Clause License" }
2020
classifiers = [
2121
"Development Status :: 5 - Production/Stable",
2222
"License :: OSI Approved :: BSD License",
@@ -25,7 +25,7 @@ classifiers = [
2525
"Operating System :: MacOS",
2626
"Operating System :: Microsoft :: Windows",
2727
"Topic :: Scientific/Engineering",
28-
"Intended Audience :: Developers"
28+
"Intended Audience :: Developers",
2929
]
3030
dependencies = ["numpy"]
3131
dynamic = ["version"]
@@ -35,18 +35,8 @@ repository = "https://github.com/scikit-hep/pyhepmc"
3535
documentation = "https://scikit-hep.org/pyhepmc"
3636

3737
[project.optional-dependencies]
38-
test = [
39-
"pytest",
40-
"particle",
41-
"matplotlib"
42-
]
43-
doc = [
44-
"sphinx",
45-
"sphinx-rtd-theme",
46-
"nbsphinx",
47-
"ipython",
48-
"ipykernel",
49-
]
38+
test = ["pytest", "particle", "matplotlib"]
39+
doc = ["sphinx", "sphinx-rtd-theme", "nbsphinx", "ipython", "ipykernel"]
5040

5141
[tool.setuptools_scm]
5242

@@ -75,8 +65,30 @@ source = ["pyhepmc"]
7565
[tool.coverage.report]
7666
exclude_lines = ["pragma: no cover"]
7767

78-
[tool.pydocstyle]
79-
convention = "numpy"
68+
[tool.ruff]
69+
src = ["src"]
70+
71+
[tool.ruff.lint]
72+
select = [
73+
"E",
74+
"F", # flake8
75+
"D", # pydocstyle
76+
]
77+
unfixable = [
78+
"F841", # Removes unused variables
79+
]
80+
extend-ignore = [
81+
"D212", # multi-line-summary-first-line
82+
]
83+
pydocstyle.convention = "numpy"
84+
85+
[tool.ruff.lint.per-file-ignores]
86+
"test_*.py" = ["B", "D"]
87+
"bench/*.py" = ["D"]
88+
"docs/*.py" = ["D"]
89+
"cmake_ext.py" = ["D"]
90+
"generate_*.py" = ["D"]
91+
"setup*.py" = ["D"]
8092

8193
[tool.cibuildwheel]
8294
# update skip when numpy wheels become available

setup_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def merge_license_files():
99
This follows the approach of Scipy and is to keep LICENSE in repo as an
1010
exact BSD 3-clause, to make GitHub state correctly how pyhepmc is licensed.
1111
"""
12-
1312
l1 = "LICENSE"
1413
l2 = "LICENSES_bundled"
1514

src/pyhepmc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def __getattr__(name: str) -> Any:
113113

114114
if name in dir(io):
115115
warnings.warn(
116-
f"importing {name} from pyhepmc is deprecated, please import from pyhepmc.io",
116+
f"importing {name} from pyhepmc is deprecated, "
117+
"please import from pyhepmc.io",
117118
category=VisibleDeprecationWarning,
118119
stacklevel=2,
119120
)

src/pyhepmc/_setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
class _SetupMeta(type):
1313
@property
1414
def print_errors(cls) -> bool:
15-
"Whether to print errors or not."
15+
"""Whether to print errors or not."""
1616
return _Setup_print_errors() # type:ignore
1717

1818
@property
1919
def print_warnings(cls) -> bool:
20-
"Whether to print warnings or not."
20+
"""Whether to print warnings or not."""
2121
return _Setup_print_warnings() # type:ignore
2222

2323
@property
2424
def debug_level(cls) -> int:
25-
"Access debug level."
25+
"""Access debug level."""
2626
return _Setup_debug_level() # type:ignore
2727

2828
def __setattr__(self, name: str, value: Any) -> None:

src/pyhepmc/io.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,22 @@ def __iter__(self: Any) -> _Iter:
100100

101101
# add contextmanager interface to IO classes
102102
class ReaderAscii(ReaderAsciiBase, ReaderMixin): # type:ignore
103-
pass
103+
"""Reader for HepMC3 ASCII files."""
104104

105105

106106
class ReaderAsciiHepMC2(ReaderAsciiHepMC2Base, ReaderMixin): # type:ignore
107-
pass
107+
"""Reader for HepMC2 ASCII files."""
108108

109109

110110
class ReaderLHEF(ReaderLHEFBase, ReaderMixin): # type:ignore
111+
"""Reader for LHEF files."""
112+
111113
_read_event_unpatched = ReaderLHEFBase.read_event
112114
read_event = _read_event_lhef_patch
113115

114116

115117
class ReaderHEPEVT(ReaderHEPEVTBase, ReaderMixin): # type:ignore
116-
pass
118+
"""Reader for HEPEVT files."""
117119

118120

119121
WriterAscii.__enter__ = _enter

src/pyhepmc/view.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Visualization for GenEvent.
3-
"""
1+
"""Visualization for GenEvent."""
42

53
from __future__ import annotations
64
from pyhepmc._graphviz import Digraph

0 commit comments

Comments
 (0)