Skip to content

Commit

Permalink
Use ruff as Python code formatter and linter
Browse files Browse the repository at this point in the history
Use `ruff` to replace:

* `autoflake`
* `black`
* `isort`
* `flake8`

Also reorganize the `pre-commit` hooks in a more logical order.
  • Loading branch information
fabcor-maxiv committed Feb 14, 2025
1 parent a10a4e8 commit 742b4ca
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 93 deletions.
12 changes: 0 additions & 12 deletions .flake8

This file was deleted.

4 changes: 0 additions & 4 deletions .isort.cfg

This file was deleted.

73 changes: 27 additions & 46 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,40 @@

repos:


- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-merge-conflict
# exclude files where underlines are not distinguishable from merge conflicts
exclude: /README\.rst$|^docs/.*\.rst$
- id: check-symlinks
- id: check-xml
- id: check-yaml
exclude: ^.drone\.yml|meta.yaml
- id: mixed-line-ending
args: ["--fix=lf"]


- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
args:
- --strict


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.6
hooks:
- id: ruff
args: [--fix]
- id: ruff-format


- repo: https://github.com/python-poetry/poetry
rev: 2.0.1
hooks:
Expand All @@ -38,51 +65,5 @@ repos:
hooks:
- id: poetry-export

- repo: https://github.com/myint/autoflake
rev: v2.3.1
hooks:
- id: autoflake
name: Autoflake
args:
- --expand-star-imports
- --ignore-init-module-imports
- --in-place
- --remove-duplicate-keys
- --ignore-pass-after-docstring

- repo: https://github.com/pycqa/isort
rev: 6.0.0
hooks:
- id: isort

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0
hooks:
- id: black
name: Black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-merge-conflict
# exclude files where underlines are not distinguishable from merge conflicts
exclude: /README\.rst$|^docs/.*\.rst$
- id: check-symlinks
- id: check-xml
- id: check-yaml
exclude: ^.drone\.yml|meta.yaml
- id: mixed-line-ending
args: ["--fix=lf"]

- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
name: Flake8
exclude: (ui/|test/)


...
12 changes: 7 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,14 @@ def function_with_types_in_docstring(param1, param2):
"""
```
You can use [autopep8](https://pypi.org/project/autopep8/) and [black](https://pypi.org/project/autopep8/) to format your code:
The Python code is to be formatted and checked for lint with
[*ruff*](https://astral.sh/ruff).
This repository uses [*pre-commit*](https://pre-commit.com/) hooks
to check the code quality automatically.
These checks are done for each pull request on GitHub.
It is also recommended to do these checks locally by enabling the git pre-commit hooks.
For example with a one-time command like this: `pre-commit install`.
```bash
autopep8 -a -r -j 0 -i --max-line-length 88 ./
black --safe ./
```
## Continuous integration (CI)
Expand Down
25 changes: 0 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,6 @@ sphinx = "<7.2"
sphinx-last-updated-by-git = "^0.3.7"
sphinxcontrib-httpdomain = "^1.8.1"

[tool.black]
line-length = 88
required-version = "25"
target-version = [
"py310",
"py311",
]
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| test
| ui
| docs
)/
'''

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Loading

0 comments on commit 742b4ca

Please sign in to comment.