Run ruff via pre-commit
This MR is to open the discussion about using pre-commit to run tools like flake8
. Part of #500 (closed)
- Add pre-commit to run
flake8ruff - Convert flake8 config from setup.cfg to pyproject.toml for ruff
- Add CI job to run pre-commit
- Add pre-commit and ruff to the documentation
- Fix bare except
- Remove unused import and other ruff errors
The advantage of pre-commit
is that it takes care of installing the required tools and makes sure all developers use the same version.
Of course, pre-commit
itself needs to be installed locally by the developers to be used.
This will have to be documented.
I only added flake8
so far. There are already a bunch of errors/warnings to fix: https://gitlab.com/beenje/pytango/-/jobs/3659332423
I tried to add pylint
. According to the documentation, it needs to be installed locally since it imports modules. I think that would remove many advantages of pre-commit
.
But it seems to work fine using the upstream repo: https://gitlab.com/beenje/pytango/-/jobs/3659663394
The .pylintrc
seems to be very old and would need to be updated.
- What do you think about
pre-commit
? - Should we customise/update
flake8
rules? - Should we run both
flake8
andpylint
?
Another alternative could be to use ruff, a fast Python linter written in Rust. It's still quite new but many "big" projects already switched to it. Seems to be mostly compatible with flake8
(https://github.com/charliermarsh/ruff#how-does-ruff-compare-to-flake8) and it already implements some rules from pylint
(https://github.com/charliermarsh/ruff#how-does-ruff-compare-to-pylint).