Skip to content

Commit b8c7273

Browse files
authored
Merge pull request #24 from imglib/use-ruff
Use the `ruff` linter/formatter and add `pre-commit`
2 parents 4e89c7d + af8b83d commit b8c7273

File tree

7 files changed

+57
-35
lines changed

7 files changed

+57
-35
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,17 @@ jobs:
4141
python -m pytest -s -p no:faulthandler --color=yes
4242
echo "Done!"
4343
44-
lint:
45-
runs-on: ubuntu-latest
46-
steps:
47-
- uses: actions/checkout@v2
48-
- uses: psf/black@stable
49-
50-
flake:
44+
ensure-clean-code:
5145
runs-on: ubuntu-latest
5246
steps:
5347
- uses: actions/checkout@v2
5448
- uses: actions/setup-python@v3
55-
- name: flake src code
56-
run: |
57-
python -m pip install flake8 Flake8-pyproject
58-
python -m flake8 src
59-
- name: flake test code
49+
50+
- name: Lint code
6051
run: |
61-
python -m flake8 tests
52+
python -m pip install ruff
53+
ruff check
54+
ruff format --check
6255
6356
conda-dev-test:
6457
name: Test Conda Development Setup And Code Coverage

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# ruff version
4+
rev: v0.9.1
5+
hooks:
6+
# run the linter
7+
- id: ruff
8+
# run the formatter
9+
- id: ruff-format
10+
- repo: https://github.com/abravalheri/validate-pyproject
11+
rev: v0.10.1
12+
hooks:
13+
- id: validate-pyproject

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ check:
2020
lint: check
2121
bin/lint.sh
2222

23+
fmt: check
24+
bin/fmt.sh
25+
2326
test: check
2427
bin/test.sh
2528

bin/fmt.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
dir=$(dirname "$0")
4+
cd "$dir/.."
5+
6+
exitCode=0
7+
ruff check --fix
8+
code=$?; test $code -eq 0 || exitCode=$code
9+
ruff format
10+
code=$?; test $code -eq 0 || exitCode=$code
11+
exit $exitCode

bin/lint.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ dir=$(dirname "$0")
44
cd "$dir/.."
55

66
exitCode=0
7-
black src tests
7+
ruff check
88
code=$?; test $code -eq 0 || exitCode=$code
9-
isort src tests
10-
code=$?; test $code -eq 0 || exitCode=$code
11-
python -m flake8 src tests
9+
ruff format --check
1210
code=$?; test $code -eq 0 || exitCode=$code
1311
validate-pyproject pyproject.toml
1412
code=$?; test $code -eq 0 || exitCode=$code

dev-environment.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@ dependencies:
2525
- numpy
2626
- scyjava
2727
# Developer tools
28-
- autopep8
29-
- black
3028
- build
31-
- flake8
32-
- flake8-pyproject
33-
- isort
29+
- pre-commit
3430
- pytest
3531
- pytest-cov
32+
- ruff
3633
- toml
3734
# Project from source
3835
- pip
3936
- pip:
4037
- validate-pyproject[all]
41-
- -e '.'
38+
- -e .

pyproject.toml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ dependencies = [
5050
[project.optional-dependencies]
5151
# NB: Keep this in sync with dev-environment.yml!
5252
dev = [
53-
"autopep8",
54-
"black",
5553
"build",
56-
"flake8",
57-
"isort",
5854
"pytest",
55+
"pre-commit",
5956
"pytest-cov",
57+
"ruff",
6058
"toml",
6159
"validate-pyproject[all]",
6260
]
@@ -76,13 +74,22 @@ include-package-data = false
7674
where = ["src"]
7775
namespaces = false
7876

79-
# Thanks to Flake8-pyproject, we can configure flake8 here!
80-
[tool.flake8]
81-
exclude = ["bin", "build", "docs", "dist"]
77+
# ruff configuration
78+
[tool.ruff]
79+
line-length = 88
80+
src = ["src", "tests"]
81+
include = ["pyproject.toml", "src/**/*.py", "tests/**/*.py"]
82+
extend-exclude = ["bin", "build", "dist"]
83+
84+
[tool.ruff.lint]
8285
extend-ignore = ["E203"]
83-
# See https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
84-
max-line-length = 88
85-
min_python_version = "3.8"
8686

87-
[tool.isort]
88-
profile = "black"
87+
[tool.ruff.lint.per-file-ignores]
88+
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
89+
"__init__.py" = ["E402", "F401"]
90+
91+
[tool.pytest.ini_options]
92+
addopts = "--ignore=docs"
93+
testpaths = [
94+
"tests",
95+
]

0 commit comments

Comments
 (0)