-
Notifications
You must be signed in to change notification settings - Fork 438
Lint Python code with ruff instead of flake8 and isort #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is interesting, I've never heard of ruff before. Speed for the static checkers hasn't been a concern for this repository before, but the simpler configuration and invocation of ruff looks really good |
I also like the idea of separating the linters from tox, since it's meant to be a testing tool |
Many projects put subsecond tools like codespell, ruff, etc into https://pre-commit.com |
Scarry to run tests on Python 3.6 but not Python 3.13. |
We stopped the python3.6 tests a while ago, but I don't have enough permissions on the repo to remove it as a required check: # Python 3.6 tests have been removed since swagger-spec-validator no longer supports it.
# A successful workflow run for Python 3.6 is required by the GitHub branch protection rules.
if: ${{ matrix.python != 3.6 }} Now it just skips them |
Thanks for this PR @cclauss, I've had a look at the branch and would like to simplify the [build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=68", "setuptools-scm>=3.0.3", "wheel"]
[tool.ruff]
exclude = ["**/migrations/*"]
line-length = 80
lint.select = [
"ASYNC", # flake8-async
"C4", # flake8-comprehensions
"C90", # mccabe
"E", # pycodestyle
"F", # pyflakes
"FA", # flake8-future-annotations
"FLY", # flynt
"I", # isort
"ICN", # flake8-import-conventions
"INT", # flake8-gettext
"LOG", # flake8-logging
"PLE", # pylint
"PYI", # flake8-pyi
"SLOT", # flake8-slots
"T10", # flake8-debugger
"TCH", # flake8-type-checking
"W", # pycodestyle warnings
"YTT", # flake8-2020
]
lint.isort.known-first-party = [
"articles",
"drf_yasg",
"people",
"snippets",
"testproj",
"todo",
"urlconfs",
"users",
]
lint.mccabe.max-complexity = 13
lint.per-file-ignores."src/drf_yasg/inspectors/field.py" = ["E721"]
lint.per-file-ignores."src/drf_yasg/openapi.py" = ["E721"]
lint.per-file-ignores."testproj/testproj/settings/*" = ["F405"] After this PR is merged I'd like to run the formatter in a new PR. The code is currently not compliant with any formatter. When we run Other related things that I'd like to do in separate PRs:
|
line-length = 80 instead of the default 88? |
The line-too-long (E501) rule suggests 88, but the PEP 8 suggestion is 80. The ruff docs say they use 88 for compatibility with Black and the Ruff formatter. It's arbitrary which one we pick since they're both followed by large projects. I checked the Django repository and they're using 88. I think we should stick to the PEP 8 convention though. |
Please read the justification for the change in psf/black docs. |
@cclauss is this the section you mean?
Although shorter files is certainly a good thing I think that sticking to the most popular length is the smarter choice. My preference is 120 but I'd much rather just stick to PEP 8 because that aligns with what a majority of people are used to and we get a lot of contributors. |
My point is that since black and ruff format have taken over the automated Python formatting space, MOST Python codebases are 88. Checkout NumPy, SciPy, Jupyter, Pyodide, Django, FastAPI, Pydantic, etc. I bet that in really popular codebases it will be difficult to find 80 char limits anymore. |
I found this stack overflow answer pretty convincing when I researching what the standard is:
|
It was written 15 years ago and does represent the way things were in that epoch. Things have changed in the interim. |
Tbh I really don't mind as long as we stick to it. If it's the default for |
@cclauss could you please update the PR to 88? |
bff535c
to
d1eee24
Compare
Thank you @cclauss |
https://docs.astral.sh/ruff