Skip to content

Commit 4ea599e

Browse files
authored
Merge pull request #315 from imagej/add-ruff
Use the `ruff` linter/formatter
2 parents 1911ea3 + 9a7a93d commit 4ea599e

File tree

8 files changed

+41
-58
lines changed

8 files changed

+41
-58
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,11 @@ jobs:
5555
- uses: actions/setup-python@v3
5656

5757
- name: Lint code
58-
uses: psf/black@stable
59-
60-
- name: Flake code
6158
run: |
62-
python -m pip install flake8 Flake8-pyproject flake8-typing-imports
63-
python -m flake8 src tests
64-
65-
- name: Check import ordering
66-
uses: isort/isort-action@master
67-
with:
68-
configuration: --check-only
69-
59+
python -m pip install ruff
60+
ruff check
61+
ruff format --check
62+
7063
- name: Validate pyproject.toml
7164
run: |
7265
python -m pip install validate-pyproject[all]

.pre-commit-config.yaml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
repos:
2-
- repo: https://github.com/myint/autoflake
3-
rev: v1.4
4-
hooks:
5-
- id: autoflake
6-
args: ["--in-place", "--remove-all-unused-imports"]
7-
- repo: https://github.com/PyCQA/flake8
8-
rev: 6.1.0
9-
hooks:
10-
- id: flake8
11-
additional_dependencies:
12-
- "flake8-typing-imports"
13-
- "Flake8-pyproject"
14-
- repo: https://github.com/PyCQA/isort
15-
rev: 5.12.0
16-
hooks:
17-
- id: isort
18-
- repo: https://github.com/psf/black
19-
rev: 22.3.0
20-
hooks:
21-
- id: black
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# ruff version
4+
rev: v0.6.2
5+
hooks:
6+
# run the linter
7+
- id: ruff
8+
# run the formatter
9+
- id: ruff-format
2210
- repo: https://github.com/abravalheri/validate-pyproject
2311
rev: v0.10.1
2412
hooks:

Makefile

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

24+
fmt: check
25+
bin/fmt.sh
26+
2427
test: check
2528
bin/test.sh
2629

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: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,17 @@ dependencies:
3939
- pooch # for scikit image
4040
- scikit-image
4141
# Developer tools
42-
- autopep8
43-
- black
44-
- flake8
45-
- flake8-typing-imports
46-
- isort
4742
- myst-nb
4843
- pre-commit
4944
- python-build
5045
- pytest
5146
- pytest-cov
47+
- ruff
5248
- sphinx
5349
- sphinx_rtd_theme
5450
- pip
5551
- pip:
5652
- readthedocs-sphinx-search
57-
- flake8-pyproject
5853
- validate-pyproject[all]
5954
# Project from source
6055
- -e .

pyproject.toml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,12 @@ dependencies = [
4949
# NB: Keep this in sync with dev-environment.yml!
5050
# Development tools
5151
dev = [
52-
"autopep8",
53-
"black",
5452
"build",
55-
"flake8",
56-
"flake8-pyproject",
57-
"flake8-typing-imports",
58-
"isort",
5953
"myst-nb",
6054
"pre-commit",
6155
"pytest",
6256
"pytest-cov",
57+
"ruff",
6358
"sphinx",
6459
"sphinx_rtd_theme",
6560
"validate-pyproject[all]",
@@ -96,20 +91,19 @@ include-package-data = false
9691
where = ["src"]
9792
namespaces = false
9893

99-
[tool.black]
100-
exclude = 'dist|doc'
94+
# ruff configuration
95+
[tool.ruff]
96+
line-length = 88
97+
src = ["src", "tests"]
98+
include = ["pyproject.toml", "src/**/*.py", "tests/**/*.py"]
99+
extend-exclude = ["bin", "build", "dist"]
101100

102-
# Thanks to Flake8-pyproject, we can configure flake8 here!
103-
[tool.flake8]
104-
exclude = ["build", "dist", "doc"]
101+
[tool.ruff.lint]
105102
extend-ignore = ["E203"]
106-
# See https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
107-
max-line-length = 88
108-
min_python_version = "3.8"
109103

110-
[tool.isort]
111-
profile = "black"
112-
skip = ["doc"]
104+
[tool.ruff.lint.per-file-ignores]
105+
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
106+
"__init__.py" = ["E402", "F401"]
113107

114108
[tool.pytest.ini_options]
115109
addopts = "--ignore=docs"

src/imagej/doctor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import imagej
1515
ij = imagej.init()
1616
"""
17+
1718
import importlib
1819
import logging
1920
import os

0 commit comments

Comments
 (0)