Skip to content

Commit ba18b0f

Browse files
authored
CI: Add ruff (#208)
This adds `ruff`, a modern version of `pyflakes`, for code linting in pre-commits.
1 parent 3c73a42 commit ba18b0f

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

.pre-commit-config.yaml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,6 @@ repos:
8686
- id: isort
8787
name: isort (python)
8888

89-
# Python: Flake8 (checks only, does this support auto-fixes?)
90-
#- repo: https://github.com/PyCQA/flake8
91-
# rev: 4.0.1
92-
# hooks:
93-
# - id: flake8
94-
# additional_dependencies: &flake8_dependencies
95-
# - flake8-bugbear
96-
# - pep8-naming
97-
# exclude: ^(docs/.*|tools/.*)$
98-
# Alternatively: use autopep8?
99-
10089
# Python Formatting
10190
- repo: https://github.com/psf/black
10291
rev: 23.10.1 # Keep in sync with blacken-docs
@@ -110,6 +99,26 @@ repos:
11099
- black==23.10.1 # keep in sync with black hook
111100
# TODO: black-jupyter
112101

102+
# Python: Ruff linter
103+
# https://docs.astral.sh/ruff/
104+
- repo: https://github.com/astral-sh/ruff-pre-commit
105+
rev: v0.1.0
106+
hooks:
107+
- id: ruff
108+
args: [--fix, --exit-non-zero-on-fix]
109+
types_or: [python, jupyter]
110+
111+
# Python: Flake8 (only for pyflake and bugbear)
112+
# Ruff above is faster
113+
#- repo: https://github.com/PyCQA/flake8
114+
# rev: 6.1.0
115+
# hooks:
116+
# - id: flake8
117+
# additional_dependencies: &flake8_dependencies
118+
# - flake8-bugbear
119+
# - Flake8-pyproject
120+
# exclude: ^(docs/.*|tools/.*)$
121+
113122
# Jupyter Notebooks: clean up all cell outputs
114123
- repo: https://github.com/roy-ht/pre-commit-jupyter
115124
rev: v1.2.1

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
shutil.rmtree(dst_path)
213213
shutil.copytree(src_path, dst_path)
214214

215-
for subdir, dirs, files in os.walk(dst_path):
215+
for subdir, _dirs, files in os.walk(dst_path):
216216
for f in files:
217217
if f.find(".pyi") > 0:
218218
dir_path = os.path.relpath(subdir, dst_path)

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@ requires = [
66
"packaging>=23",
77
]
88
build-backend = "setuptools.build_meta"
9+
10+
11+
[tool.flake8]
12+
#ignore = ['E231', 'E241']
13+
select = ['F', 'B']
14+
15+
16+
[tool.ruff]
17+
# https://docs.astral.sh/ruff/
18+
select = ["E4", "E7", "E9", "F"]
19+
ignore = ["E402"]

tests/test_geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_periodicity(geometry):
132132
gm = geometry
133133
bx = gm.Domain()
134134

135-
for non_periodic_coord in [0, 1]:
135+
for _non_periodic_coord in [0, 1]:
136136
error_thrown = False
137137
try:
138138
gm.period(0)

tests/test_multifab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_mfab_mfiter(mfab):
147147
assert iter(mfab).length == 8
148148

149149
cnt = 0
150-
for mfi in mfab:
150+
for _mfi in mfab:
151151
cnt += 1
152152

153153
assert iter(mfab).length == cnt

tests/test_particleContainer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def test_per_cell(empty_particle_container, std_geometry, std_particle):
262262

263263
sum_1 = 0
264264
for tile_ind, pt in lev.items():
265+
print("tile", tile_ind)
265266
real_arrays = pt.GetStructOfArrays().GetRealData()
266267
sum_1 += np.sum(real_arrays[1])
267268
print(sum_1)

0 commit comments

Comments
 (0)