Skip to content

Commit 6aa9360

Browse files
authored
Merge pull request #76 from iacopy/75-use-ruff---drop-flake8-isort-black
75 use ruff, drop flake8, isort and black
2 parents 37ae4c6 + 0966cdf commit 6aa9360

File tree

10 files changed

+97
-128
lines changed

10 files changed

+97
-128
lines changed

.flake8

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222
- name: Set up ${{ matrix.python-version }}
23-
uses: actions/setup-python@v4
23+
uses: actions/setup-python@v5
2424
with:
2525
python-version: ${{ matrix.python-version }}
2626
- name: Install just
27-
uses: extractions/setup-just@v1
27+
uses: extractions/setup-just@v3
2828
- name: Install dependencies
2929
run: |
3030
just install
31-
- name: Lint with flake8, mypy, pylint, isort and black
31+
- name: Lint with mypy, pylint, and ruff
3232
run: |
3333
just lint
3434
- name: Test with pytest

.isort.cfg

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ Read [here](https://www.butterfly.com.au/blog/website-development/clean-high-qua
4040
- can catch even duplicate code in different files! 🙌
4141
- helps you to start refactoring before your code becomes too messy
4242

43-
- [Flake8](http://flake8.readthedocs.io)
44-
- helps to write standard, clean, and documented code
45-
- wraps pep8, pyflakes, McCabe Complexity analysis
46-
- supports plugins
47-
48-
- [Isort](https://pycqa.github.io/isort/)
49-
- Keep imports sorted alphabetically and grouped (standard, third party, local)
43+
- [Ruff](https://github.com/astral-sh/ruff): an extremely fast Python linter and code formatter, written in Rust. Ruff can be used to replace Flake8 (plus dozens of plugins), Black, isort, pydocstyle, pyupgrade, autoflake, and more, all while executing tens or hundreds of times faster than any individual tool.
44+
- ⚡️ 10-100x faster than existing linters (like Flake8) and formatters (like Black)
45+
- 🐍 Installable via pip
46+
- 🛠️ pyproject.toml support
47+
- 🤝 Python 3.13 compatibility
48+
- ⚖️ Drop-in parity with Flake8, isort, and Black
49+
- 📦 Built-in caching, to avoid re-analyzing unchanged files
50+
- 🔧 Fix support, for automatic error correction (e.g., automatically remove unused imports)
51+
- 📏 Over 800 built-in rules, with native re-implementations of popular Flake8 plugins, like - flake8-bugbear
52+
- ⌨️ First-party editor integrations for VS Code and more
53+
- 🌎 Monorepo-friendly, with hierarchical and cascading configuration
5054

5155
- [MkDocs](https://www.mkdocs.org/)
5256
- generates html documentation
@@ -57,13 +61,6 @@ Read [here](https://www.butterfly.com.au/blog/website-development/clean-high-qua
5761
- `pip-sync` installs from requirements.txt
5862
- You can also have dev-requirements if you want
5963

60-
- [Poetry](https://python-poetry.org/)
61-
- Poetry comes with all the tools you might need to manage your projects in a deterministic way
62-
- Dependency resolver, isolation, cli
63-
- Check the state of your dependencies
64-
- Easily build and package your projects with a single command
65-
- Make your work known by publishing it to PyPI
66-
6764
- [just](https://github.com/casey/just)
6865
- rules them all together in your workflow
6966
- `just check` to make sure everything is OK
@@ -74,7 +71,6 @@ Read [here](https://www.butterfly.com.au/blog/website-development/clean-high-qua
7471

7572
- [Git](https://git-scm.com)
7673
- [Python3](https://docs.python.org/3/)
77-
- [Poetry](https://python-poetry.org/)
7874
- [just](https://github.com/casey/just)
7975

8076
## Usage
@@ -103,9 +99,9 @@ checks, pedantic):
10399

104100
just install-hooks
105101

106-
To install hook to black-format code before commit:
102+
To install hook to check code when commit:
107103

108-
just black-hook
104+
just ruff-hook
109105

110106
### Badges
111107

justfile

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ install-hooks:
120120
# install pre-push hook
121121
echo "just test" > .git/hooks/pre-push&&chmod +x .git/hooks/pre-push
122122

123-
# install hook to black code before commit
124-
black-hook:
125-
# ensures that all your commits contain Python code formatted according to Black’s rules.
126-
cp pre-commit-black .git/hooks/pre-commit&&chmod +x .git/hooks/pre-commit
123+
# install hook to check code before commit
124+
ruff-hook:
125+
# ensures that all your commits contain Python code formatted according to ruff’s rules.
126+
cp pre-commit-ruff .git/hooks/pre-commit&&chmod +x .git/hooks/pre-commit
127127

128128
# bootstrap your virtualenv (deprecated)
129129
setenv VIRTUALENV:
@@ -135,35 +135,24 @@ setenv VIRTUALENV:
135135
@_mypy:
136136
mypy --ignore-missing-imports src
137137
138-
@_flake8:
139-
flake8 .
140-
141138
@_pylint:
142139
pylint $(git ls-files '*.py') --ignore conf.py
143140
144-
@_isort:
145-
isort --check-only --recursive --quiet . || just _fail "Fix imports by calling \'just fix\'."
146-
147-
@_black:
148-
black --check -q . || just _fail "Fix code formatting by calling \'just fix\'."
141+
@_ruff:
142+
ruff check -q $(git ls-files '*.py')
149143
150-
# statically check the codebase (mypy, flake8, pylint, isort)
144+
# statically check the codebase (mypy, pylint, ruff)
151145
@lint:
152146
just _mypy
153-
echo "mypy : OK "
154-
just _flake8
155-
echo "flake8: OK ✅✅"
147+
echo "mypy : OK ☑️"
148+
just _ruff
149+
echo "ruff : OK ⚡️⚡️"
156150
just _pylint
157-
echo "pylint: OK ✅✅✅"
158-
just _isort
159-
echo "isort : OK ✅✅✅ 🍰"
160-
just _black
161-
echo "black : OK ✅✅✅ 🍒"
151+
echo "pylint: OK ☑️☑️☑️"
162152
163-
# auto fix imports and pep8 coding style
153+
# auto fix imports and pep8 coding style (via ruff)
164154
@fix:
165-
isort .
166-
black .
155+
ruff format .
167156
# Re-check code quality
168157
just lint
169158
@@ -174,7 +163,7 @@ setenv VIRTUALENV:
174163
# run tests only (with no coverage and no lint)
175164
@test:
176165
pytest
177-
echo "Tests: OK ✅✅✅"
166+
echo "Tests: OK ✅✅✅"
178167
179168
# run tests with coverage.py, create html report and open it
180169
@cov:

pre-commit-black

Lines changed: 0 additions & 10 deletions
This file was deleted.

pre-commit-ruff

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# Run Ruff check on all Python files
4+
files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$')
5+
if [ -n "$files" ]; then
6+
echo "Running Ruff check on Python files..."
7+
ruff check $files
8+
# Run the Ruff formatter on the given files or directories
9+
ruff format --check $files
10+
fi

pylintrc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ ignore-paths=
5959
# Emacs file locks
6060
ignore-patterns=^\.#
6161

62-
# List of module names for which member attributes should not be checked
63-
# (useful for modules/projects where namespaces are manipulated during runtime
64-
# and thus existing member attributes cannot be deduced by static analysis). It
65-
# supports qualified module names, as well as Unix pattern matching.
62+
# List of module names for which member attributes should not be checked and
63+
# will not be imported (useful for modules/projects where namespaces are
64+
# manipulated during runtime and thus existing member attributes cannot be
65+
# deduced by static analysis). It supports qualified module names, as well as
66+
# Unix pattern matching.
6667
ignored-modules=
6768

6869
# Python code to execute, usually for sys.path manipulation such as
@@ -86,6 +87,10 @@ load-plugins=
8687
# Pickle collected data for later comparisons.
8788
persistent=yes
8889

90+
# Resolve imports to .pyi stubs if available. May reduce no-member messages and
91+
# increase not-an-iterable messages.
92+
prefer-stubs=no
93+
8994
# Minimum Python version to use for version dependent checks. Will default to
9095
# the version used to run pylint.
9196
py-version=3.11
@@ -302,6 +307,9 @@ max-locals=15
302307
# Maximum number of parents for a class (see R0901).
303308
max-parents=7
304309

310+
# Maximum number of positional arguments for function / method.
311+
max-positional-arguments=5
312+
305313
# Maximum number of public methods for a class (see R0904).
306314
max-public-methods=20
307315

@@ -487,10 +495,10 @@ evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor
487495
# used to format the message information. See doc for all details.
488496
msg-template=
489497

490-
# Set the output format. Available formats are: text, parseable, colorized,
491-
# json2 (improved json format), json (old json format) and msvs (visual
492-
# studio). You can also give a reporter class, e.g.
493-
# mypackage.mymodule.MyReporterClass.
498+
# Set the output format. Available formats are: 'text', 'parseable',
499+
# 'colorized', 'json2' (improved json format), 'json' (old json format), msvs
500+
# (visual studio) and 'github' (GitHub actions). You can also give a reporter
501+
# class, e.g. mypackage.mymodule.MyReporterClass.
494502
#output-format=
495503

496504
# Tells whether to display a full report or only the messages.
@@ -592,7 +600,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace
592600
# of finding the hint is based on edit distance.
593601
missing-member-hint=yes
594602

595-
# The minimum edit distance a name should have in order to be considered a
603+
# The maximum edit distance a name should have in order to be considered a
596604
# similar match for a missing member name.
597605
missing-member-hint-distance=1
598606

requirements.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ pytest-cov
88
coverage
99
mypy
1010
pylint
11-
flake8
12-
isort
13-
black
11+
ruff
1412

1513
# Documentation
1614
mkdocs

0 commit comments

Comments
 (0)