This PR tests if ruff can be used as an alternative to the combination of black and flake8 in our tests. I decided to do this test because of the following reasons:
Ruff is a standalone binary and has no dependencies, while flake8 and black bring 8 dependencies in pyproject.toml and thus make the setup of CI virtual machines slower
Ruff is able to signal more warnings; in fact, all the unused import statements that this PR removes were undetected by flake8
Ruff is able to automatically fix some of the issues it finds in the code; in fact, all the unused imports removed in this PR were fixed automatically by ruff itself with the command ruff check --fix ..
Although it's not relevant for our repository yet, Ruff is significantly faster than the combo flake8+black. This might impact the time spent in CI builds in the future.
This PR fixes the following stuff:
[X] It removes all the unused imports that were left in the code
[X] Although ruff claims 100% compatibility with black, I found that there were 4 instances where the formatting differed a bit. (This might be caused by a version mismatch between black and ruff). So I let ruff reformat them to make the CI tests pass
[X] It uses the preferred idiom isinstance(var, type) over type(var) is type in a few places
[X] It only uses ruff in bin/run_tests.sh (both to lint the code and to check its formatting)
[X] It does no longer call black and flake8 whenever git commit commands are issued; instead, it calls ruff twice to (a) check for lint errors and (b) check the formatting
What do you think? Do you believe it's worth for us to switch to ruff, or should we keep everything as it is?
This PR tests if ruff can be used as an alternative to the combination of black and flake8 in our tests. I decided to do this test because of the following reasons:
Ruff is a standalone binary and has no dependencies, while flake8 and black bring 8 dependencies in
pyproject.toml
and thus make the setup of CI virtual machines slowerRuff is able to signal more warnings; in fact, all the unused
import
statements that this PR removes were undetected by flake8Ruff is able to automatically fix some of the issues it finds in the code; in fact, all the unused imports removed in this PR were fixed automatically by ruff itself with the command
ruff check --fix .
.Although it's not relevant for our repository yet, Ruff is significantly faster than the combo flake8+black. This might impact the time spent in CI builds in the future.
This PR fixes the following stuff:
isinstance(var, type)
overtype(var) is type
in a few placesbin/run_tests.sh
(both to lint the code and to check its formatting)black
andflake8
whenevergit commit
commands are issued; instead, it callsruff
twice to (a) check for lint errors and (b) check the formattingWhat do you think? Do you believe it's worth for us to switch to ruff, or should we keep everything as it is?