Skip to content

Commit

Permalink
CI: Add ruff (#208)
Browse files Browse the repository at this point in the history
This adds `ruff`, a modern version of `pyflakes`, for code linting
in pre-commits.
  • Loading branch information
ax3l authored Nov 3, 2023
1 parent 3c73a42 commit ba18b0f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
31 changes: 20 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ repos:
- id: isort
name: isort (python)

# Python: Flake8 (checks only, does this support auto-fixes?)
#- repo: https://github.com/PyCQA/flake8
# rev: 4.0.1
# hooks:
# - id: flake8
# additional_dependencies: &flake8_dependencies
# - flake8-bugbear
# - pep8-naming
# exclude: ^(docs/.*|tools/.*)$
# Alternatively: use autopep8?

# Python Formatting
- repo: https://github.com/psf/black
rev: 23.10.1 # Keep in sync with blacken-docs
Expand All @@ -110,6 +99,26 @@ repos:
- black==23.10.1 # keep in sync with black hook
# TODO: black-jupyter

# Python: Ruff linter
# https://docs.astral.sh/ruff/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types_or: [python, jupyter]

# Python: Flake8 (only for pyflake and bugbear)
# Ruff above is faster
#- repo: https://github.com/PyCQA/flake8
# rev: 6.1.0
# hooks:
# - id: flake8
# additional_dependencies: &flake8_dependencies
# - flake8-bugbear
# - Flake8-pyproject
# exclude: ^(docs/.*|tools/.*)$

# Jupyter Notebooks: clean up all cell outputs
- repo: https://github.com/roy-ht/pre-commit-jupyter
rev: v1.2.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
shutil.rmtree(dst_path)
shutil.copytree(src_path, dst_path)

for subdir, dirs, files in os.walk(dst_path):
for subdir, _dirs, files in os.walk(dst_path):
for f in files:
if f.find(".pyi") > 0:
dir_path = os.path.relpath(subdir, dst_path)
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ requires = [
"packaging>=23",
]
build-backend = "setuptools.build_meta"


[tool.flake8]
#ignore = ['E231', 'E241']
select = ['F', 'B']


[tool.ruff]
# https://docs.astral.sh/ruff/
select = ["E4", "E7", "E9", "F"]
ignore = ["E402"]
2 changes: 1 addition & 1 deletion tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_periodicity(geometry):
gm = geometry
bx = gm.Domain()

for non_periodic_coord in [0, 1]:
for _non_periodic_coord in [0, 1]:
error_thrown = False
try:
gm.period(0)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multifab.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_mfab_mfiter(mfab):
assert iter(mfab).length == 8

cnt = 0
for mfi in mfab:
for _mfi in mfab:
cnt += 1

assert iter(mfab).length == cnt
Expand Down
1 change: 1 addition & 0 deletions tests/test_particleContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def test_per_cell(empty_particle_container, std_geometry, std_particle):

sum_1 = 0
for tile_ind, pt in lev.items():
print("tile", tile_ind)
real_arrays = pt.GetStructOfArrays().GetRealData()
sum_1 += np.sum(real_arrays[1])
print(sum_1)
Expand Down

0 comments on commit ba18b0f

Please sign in to comment.