From 79e71d1db86cb62d6578220a45ea41174e49d4db Mon Sep 17 00:00:00 2001 From: iacopo Date: Tue, 17 Jun 2025 15:45:50 +0200 Subject: [PATCH 1/7] requirements: update versions pylintrc: update --- pylintrc | 26 +++++++++++------- requirements.txt | 70 +++++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/pylintrc b/pylintrc index ed61e69..0bd587b 100644 --- a/pylintrc +++ b/pylintrc @@ -59,10 +59,11 @@ ignore-paths= # Emacs file locks ignore-patterns=^\.# -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis). It -# supports qualified module names, as well as Unix pattern matching. +# List of module names for which member attributes should not be checked and +# will not be imported (useful for modules/projects where namespaces are +# manipulated during runtime and thus existing member attributes cannot be +# deduced by static analysis). It supports qualified module names, as well as +# Unix pattern matching. ignored-modules= # Python code to execute, usually for sys.path manipulation such as @@ -86,6 +87,10 @@ load-plugins= # Pickle collected data for later comparisons. persistent=yes +# Resolve imports to .pyi stubs if available. May reduce no-member messages and +# increase not-an-iterable messages. +prefer-stubs=no + # Minimum Python version to use for version dependent checks. Will default to # the version used to run pylint. py-version=3.11 @@ -302,6 +307,9 @@ max-locals=15 # Maximum number of parents for a class (see R0901). max-parents=7 +# Maximum number of positional arguments for function / method. +max-positional-arguments=5 + # Maximum number of public methods for a class (see R0904). max-public-methods=20 @@ -487,10 +495,10 @@ evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor # used to format the message information. See doc for all details. msg-template= -# Set the output format. Available formats are: text, parseable, colorized, -# json2 (improved json format), json (old json format) and msvs (visual -# studio). You can also give a reporter class, e.g. -# mypackage.mymodule.MyReporterClass. +# Set the output format. Available formats are: 'text', 'parseable', +# 'colorized', 'json2' (improved json format), 'json' (old json format), msvs +# (visual studio) and 'github' (GitHub actions). You can also give a reporter +# class, e.g. mypackage.mymodule.MyReporterClass. #output-format= # 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 # of finding the hint is based on edit distance. missing-member-hint=yes -# The minimum edit distance a name should have in order to be considered a +# The maximum edit distance a name should have in order to be considered a # similar match for a missing member name. missing-member-hint-distance=1 diff --git a/requirements.txt b/requirements.txt index cd290ad..d29e8ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,50 +1,50 @@ # -# This file is autogenerated by pip-compile with Python 3.12 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile # -astroid==3.3.8 +astroid==3.3.10 # via pylint black==25.1.0 # via -r requirements.in blinker==1.9.0 # via flask -click==8.1.8 +click==8.2.1 # via # black # flask # mkdocs colorama==0.4.6 # via griffe -coverage[toml]==7.6.12 +coverage[toml]==7.9.1 # via # -r requirements.in # pytest-cov -dill==0.3.9 +dill==0.4.0 # via pylint -flake8==7.1.2 +flake8==7.2.0 # via -r requirements.in -flask==3.1.0 +flask==3.1.1 # via -r requirements.in ghp-import==2.1.0 # via mkdocs -griffe==1.5.7 +griffe==1.7.3 # via mkdocstrings-python -iniconfig==2.0.0 +iniconfig==2.1.0 # via pytest -isort==6.0.0 +isort==6.0.1 # via # -r requirements.in # pylint itsdangerous==2.2.0 # via flask -jinja2==3.1.5 +jinja2==3.1.6 # via # flask # mkdocs # mkdocstrings -markdown==3.7 +markdown==3.8 # via # mkdocs # mkdocs-autorefs @@ -52,6 +52,7 @@ markdown==3.7 # pymdown-extensions markupsafe==3.0.2 # via + # flask # jinja2 # mkdocs # mkdocs-autorefs @@ -70,27 +71,25 @@ mkdocs==1.6.1 # -r requirements.in # mkdocs-autorefs # mkdocstrings -mkdocs-autorefs==1.3.1 +mkdocs-autorefs==1.4.2 # via # mkdocstrings # mkdocstrings-python mkdocs-get-deps==0.2.0 - # via - # mkdocs - # mkdocstrings -mkdocstrings==0.28.1 + # via mkdocs +mkdocstrings==0.29.1 # via # -r requirements.in # mkdocstrings-python -mkdocstrings-python==1.16.1 +mkdocstrings-python==1.16.12 # via -r requirements.in -mypy==1.15.0 +mypy==1.16.1 # via -r requirements.in -mypy-extensions==1.0.0 +mypy-extensions==1.1.0 # via # black # mypy -packaging==24.2 +packaging==25.0 # via # black # mkdocs @@ -99,31 +98,36 @@ pathspec==0.12.1 # via # black # mkdocs -platformdirs==4.3.6 + # mypy +platformdirs==4.3.8 # via # black # mkdocs-get-deps # pylint -pluggy==1.5.0 - # via pytest +pluggy==1.6.0 + # via + # pytest + # pytest-cov py-cpuinfo==9.0.0 # via pytest-benchmark -pycodestyle==2.12.1 +pycodestyle==2.13.0 # via flake8 -pyflakes==3.2.0 +pyflakes==3.3.2 # via flake8 -pylint==3.3.4 +pygments==2.19.1 + # via pytest +pylint==3.3.7 # via -r requirements.in -pymdown-extensions==10.14.3 +pymdown-extensions==10.15 # via mkdocstrings -pytest==8.3.4 +pytest==8.4.0 # via # -r requirements.in # pytest-benchmark # pytest-cov pytest-benchmark==5.1.0 # via -r requirements.in -pytest-cov==6.0.0 +pytest-cov==6.2.1 # via -r requirements.in python-dateutil==2.9.0.post0 # via ghp-import @@ -133,13 +137,13 @@ pyyaml==6.0.2 # mkdocs-get-deps # pymdown-extensions # pyyaml-env-tag -pyyaml-env-tag==0.1 +pyyaml-env-tag==1.1 # via mkdocs six==1.17.0 # via python-dateutil -tomlkit==0.13.2 +tomlkit==0.13.3 # via pylint -typing-extensions==4.12.2 +typing-extensions==4.14.0 # via mypy watchdog==6.0.0 # via mkdocs From c1b84893627ee4b1b7eb6c112d0a02541af78426 Mon Sep 17 00:00:00 2001 From: iacopo Date: Tue, 17 Jun 2025 15:50:43 +0200 Subject: [PATCH 2/7] requirements: install ruff, drop black,flake8,isort Issue #75 --- requirements.in | 4 +--- requirements.txt | 26 +++++--------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/requirements.in b/requirements.in index 7dc0d23..d50f9a2 100644 --- a/requirements.in +++ b/requirements.in @@ -8,9 +8,7 @@ pytest-cov coverage mypy pylint -flake8 -isort -black +ruff # Documentation mkdocs diff --git a/requirements.txt b/requirements.txt index d29e8ae..9f4d955 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,13 +6,10 @@ # astroid==3.3.10 # via pylint -black==25.1.0 - # via -r requirements.in blinker==1.9.0 # via flask click==8.2.1 # via - # black # flask # mkdocs colorama==0.4.6 @@ -23,8 +20,6 @@ coverage[toml]==7.9.1 # pytest-cov dill==0.4.0 # via pylint -flake8==7.2.0 - # via -r requirements.in flask==3.1.1 # via -r requirements.in ghp-import==2.1.0 @@ -34,9 +29,7 @@ griffe==1.7.3 iniconfig==2.1.0 # via pytest isort==6.0.1 - # via - # -r requirements.in - # pylint + # via pylint itsdangerous==2.2.0 # via flask jinja2==3.1.6 @@ -59,9 +52,7 @@ markupsafe==3.0.2 # mkdocstrings # werkzeug mccabe==0.7.0 - # via - # flake8 - # pylint + # via pylint mergedeep==1.3.4 # via # mkdocs @@ -86,22 +77,17 @@ mkdocstrings-python==1.16.12 mypy==1.16.1 # via -r requirements.in mypy-extensions==1.1.0 - # via - # black - # mypy + # via mypy packaging==25.0 # via - # black # mkdocs # pytest pathspec==0.12.1 # via - # black # mkdocs # mypy platformdirs==4.3.8 # via - # black # mkdocs-get-deps # pylint pluggy==1.6.0 @@ -110,10 +96,6 @@ pluggy==1.6.0 # pytest-cov py-cpuinfo==9.0.0 # via pytest-benchmark -pycodestyle==2.13.0 - # via flake8 -pyflakes==3.3.2 - # via flake8 pygments==2.19.1 # via pytest pylint==3.3.7 @@ -139,6 +121,8 @@ pyyaml==6.0.2 # pyyaml-env-tag pyyaml-env-tag==1.1 # via mkdocs +ruff==0.11.13 + # via -r requirements.in six==1.17.0 # via python-dateutil tomlkit==0.13.3 From 70abd2dbb23bcb28a3d9c970094387634c233d12 Mon Sep 17 00:00:00 2001 From: iacopo Date: Tue, 17 Jun 2025 16:39:19 +0200 Subject: [PATCH 3/7] cleanup isort and flake8 config files --- .flake8 | 2 -- .isort.cfg | 8 -------- 2 files changed, 10 deletions(-) delete mode 100644 .flake8 delete mode 100644 .isort.cfg diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 7da1f96..0000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -max-line-length = 100 diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 343aeb5..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,8 +0,0 @@ -[settings] - -force_single_line=True - -# Auto-comment import sections -import_heading_stdlib=Standard Library -import_heading_thirdparty=3rd party -import_heading_firstparty=My stuff From 7cf05e3a49d5274b2b63e5641c4110d1e8c80564 Mon Sep 17 00:00:00 2001 From: iacopo Date: Tue, 17 Jun 2025 15:53:03 +0200 Subject: [PATCH 4/7] pre-commit-ruff: add rm pre-commit-black Issue #75 --- pre-commit-black | 10 ---------- pre-commit-ruff | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 pre-commit-black create mode 100644 pre-commit-ruff diff --git a/pre-commit-black b/pre-commit-black deleted file mode 100644 index 267aeb9..0000000 --- a/pre-commit-black +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -# Run Black on all Python files -files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$') -if [ -n "$files" ]; then - echo "Running Black on Python files..." - black $files - # Add the formatted files back to the staging area - git add $files -fi \ No newline at end of file diff --git a/pre-commit-ruff b/pre-commit-ruff new file mode 100644 index 0000000..45783a9 --- /dev/null +++ b/pre-commit-ruff @@ -0,0 +1,10 @@ +#!/bin/sh + +# Run Ruff check on all Python files +files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$') +if [ -n "$files" ]; then + echo "Running Ruff check on Python files..." + ruff check $files + # Run the Ruff formatter on the given files or directories + ruff format --check $files +fi \ No newline at end of file From a74fed9b2babc0d543ce08963ff74ecc36c72da6 Mon Sep 17 00:00:00 2001 From: iacopo Date: Tue, 17 Jun 2025 15:36:37 +0200 Subject: [PATCH 5/7] justfile: introduce ruff Drop isort, black and flake8 Issue #75 --- justfile | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/justfile b/justfile index 22c5c96..c5a37e2 100644 --- a/justfile +++ b/justfile @@ -120,10 +120,10 @@ install-hooks: # install pre-push hook echo "just test" > .git/hooks/pre-push&&chmod +x .git/hooks/pre-push -# install hook to black code before commit -black-hook: - # ensures that all your commits contain Python code formatted according to Black’s rules. - cp pre-commit-black .git/hooks/pre-commit&&chmod +x .git/hooks/pre-commit +# install hook to check code before commit +ruff-hook: + # ensures that all your commits contain Python code formatted according to ruff’s rules. + cp pre-commit-ruff .git/hooks/pre-commit&&chmod +x .git/hooks/pre-commit # bootstrap your virtualenv (deprecated) setenv VIRTUALENV: @@ -135,35 +135,24 @@ setenv VIRTUALENV: @_mypy: mypy --ignore-missing-imports src -@_flake8: - flake8 . - @_pylint: pylint $(git ls-files '*.py') --ignore conf.py -@_isort: - isort --check-only --recursive --quiet . || just _fail "Fix imports by calling \'just fix\'." - -@_black: - black --check -q . || just _fail "Fix code formatting by calling \'just fix\'." +@_ruff: + ruff check -q $(git ls-files '*.py') -# statically check the codebase (mypy, flake8, pylint, isort) +# statically check the codebase (mypy, pylint, ruff) @lint: just _mypy - echo "mypy : OK ✅" - just _flake8 - echo "flake8: OK ✅✅" + echo "mypy : OK ☑️" + just _ruff + echo "ruff : OK ⚡️⚡️" just _pylint - echo "pylint: OK ✅✅✅" - just _isort - echo "isort : OK ✅✅✅ 🍰" - just _black - echo "black : OK ✅✅✅ 🍒" + echo "pylint: OK ☑️☑️☑️" -# auto fix imports and pep8 coding style +# auto fix imports and pep8 coding style (via ruff) @fix: - isort . - black . + ruff format . # Re-check code quality just lint @@ -174,7 +163,7 @@ setenv VIRTUALENV: # run tests only (with no coverage and no lint) @test: pytest - echo "Tests: OK ✅✅✅✅" + echo "Tests: OK ✅✅✅" # run tests with coverage.py, create html report and open it @cov: From 2251a8bcfe4114b599f4954716d1858dd06aa138 Mon Sep 17 00:00:00 2001 From: iacopo Date: Tue, 17 Jun 2025 15:51:24 +0200 Subject: [PATCH 6/7] ci: update versions and name (comment) Issue #75 --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5499227..2c9766b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,15 +20,15 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install just - uses: extractions/setup-just@v1 + uses: extractions/setup-just@v3 - name: Install dependencies run: | just install - - name: Lint with flake8, mypy, pylint, isort and black + - name: Lint with mypy, pylint, and ruff run: | just lint - name: Test with pytest From 0966cdfc3de6221b6cd0c5c07baabc42b23ee263 Mon Sep 17 00:00:00 2001 From: iacopo Date: Tue, 17 Jun 2025 16:03:07 +0200 Subject: [PATCH 7/7] README: Update after Ruff introduction Close #75 Fixup issue #71 (drop poetry) --- README.md | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c78c73b..c82cdbc 100644 --- a/README.md +++ b/README.md @@ -40,13 +40,17 @@ Read [here](https://www.butterfly.com.au/blog/website-development/clean-high-qua - can catch even duplicate code in different files! 🙌 - helps you to start refactoring before your code becomes too messy -- [Flake8](http://flake8.readthedocs.io) - - helps to write standard, clean, and documented code - - wraps pep8, pyflakes, McCabe Complexity analysis - - supports plugins - -- [Isort](https://pycqa.github.io/isort/) - - Keep imports sorted alphabetically and grouped (standard, third party, local) +- [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. + - ⚡️ 10-100x faster than existing linters (like Flake8) and formatters (like Black) + - 🐍 Installable via pip + - 🛠️ pyproject.toml support + - 🤝 Python 3.13 compatibility + - ⚖️ Drop-in parity with Flake8, isort, and Black + - 📦 Built-in caching, to avoid re-analyzing unchanged files + - 🔧 Fix support, for automatic error correction (e.g., automatically remove unused imports) + - 📏 Over 800 built-in rules, with native re-implementations of popular Flake8 plugins, like - flake8-bugbear + - ⌨️ First-party editor integrations for VS Code and more + - 🌎 Monorepo-friendly, with hierarchical and cascading configuration - [MkDocs](https://www.mkdocs.org/) - generates html documentation @@ -57,13 +61,6 @@ Read [here](https://www.butterfly.com.au/blog/website-development/clean-high-qua - `pip-sync` installs from requirements.txt - You can also have dev-requirements if you want -- [Poetry](https://python-poetry.org/) - - Poetry comes with all the tools you might need to manage your projects in a deterministic way - - Dependency resolver, isolation, cli - - Check the state of your dependencies - - Easily build and package your projects with a single command - - Make your work known by publishing it to PyPI - - [just](https://github.com/casey/just) - rules them all together in your workflow - `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 - [Git](https://git-scm.com) - [Python3](https://docs.python.org/3/) -- [Poetry](https://python-poetry.org/) - [just](https://github.com/casey/just) ## Usage @@ -103,9 +99,9 @@ checks, pedantic): just install-hooks -To install hook to black-format code before commit: +To install hook to check code when commit: - just black-hook + just ruff-hook ### Badges