Skip to content

Commit

Permalink
Add ruff and remove the packages it replaces
Browse files Browse the repository at this point in the history
This commit implements the ruff linter/formater and
removes the old dependencies it replaces.
  • Loading branch information
elevans committed Oct 14, 2024
1 parent 1911ea3 commit 7b35634
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 58 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,11 @@ jobs:
- uses: actions/setup-python@v3

- name: Lint code
uses: psf/black@stable

- name: Flake code
run: |
python -m pip install flake8 Flake8-pyproject flake8-typing-imports
python -m flake8 src tests
- name: Check import ordering
uses: isort/isort-action@master
with:
configuration: --check-only

python -m pip install ruff
ruff check
ruff format --check
- name: Validate pyproject.toml
run: |
python -m pip install validate-pyproject[all]
Expand Down
28 changes: 8 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
repos:
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports"]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- "flake8-typing-imports"
- "Flake8-pyproject"
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
# ruff version
rev: v0.6.2
hooks:
# run the linter
- id: ruff
# run the formatter
- id: ruff-format
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
hooks:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ check:
lint: check
bin/lint.sh

fmt: check
bin/fmt.sh

test: check
bin/test.sh

Expand Down
11 changes: 11 additions & 0 deletions bin/fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

dir=$(dirname "$0")
cd "$dir/.."

exitCode=0
ruff check --fix
code=$?; test $code -eq 0 || exitCode=$code
ruff format
code=$?; test $code -eq 0 || exitCode=$code
exit $exitCode
6 changes: 2 additions & 4 deletions bin/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ dir=$(dirname "$0")
cd "$dir/.."

exitCode=0
black src tests
ruff check
code=$?; test $code -eq 0 || exitCode=$code
isort src tests
code=$?; test $code -eq 0 || exitCode=$code
python -m flake8 src tests
ruff format --check
code=$?; test $code -eq 0 || exitCode=$code
validate-pyproject pyproject.toml
code=$?; test $code -eq 0 || exitCode=$code
Expand Down
7 changes: 1 addition & 6 deletions dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,17 @@ dependencies:
- pooch # for scikit image
- scikit-image
# Developer tools
- autopep8
- black
- flake8
- flake8-typing-imports
- isort
- myst-nb
- pre-commit
- python-build
- pytest
- pytest-cov
- ruff
- sphinx
- sphinx_rtd_theme
- pip
- pip:
- readthedocs-sphinx-search
- flake8-pyproject
- validate-pyproject[all]
# Project from source
- -e .
28 changes: 11 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,12 @@ dependencies = [
# NB: Keep this in sync with dev-environment.yml!
# Development tools
dev = [
"autopep8",
"black",
"build",
"flake8",
"flake8-pyproject",
"flake8-typing-imports",
"isort",
"myst-nb",
"pre-commit",
"pytest",
"pytest-cov",
"ruff",
"sphinx",
"sphinx_rtd_theme",
"validate-pyproject[all]",
Expand Down Expand Up @@ -96,20 +91,19 @@ include-package-data = false
where = ["src"]
namespaces = false

[tool.black]
exclude = 'dist|doc'
# ruff configuration
[tool.ruff]
line-length = 88
src = ["src", "tests"]
include = ["pyproject.toml", "src/**/*.py", "tests/**/*.py"]
extend-exclude = ["bin", "build", "dist"]

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

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

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

0 comments on commit 7b35634

Please sign in to comment.