-
-
Notifications
You must be signed in to change notification settings - Fork 259
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
Use ruff to lint Python code #518
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
repos: | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: '7.1.1' | ||
hooks: | ||
- id: flake8 | ||
exclude: docs/conf.py|test_settings.py | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: 'v5.0.0' | ||
hooks: | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.7.3 | ||
hooks: | ||
- id: ruff |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,90 @@ strict_equality = true | |
[[tool.mypy.overrides]] | ||
module = ["django.*"] | ||
ignore_missing_imports = true | ||
|
||
[tool.ruff] | ||
line-length = 120 | ||
target-version = "py38" | ||
|
||
[tool.ruff.lint] | ||
select = [ | ||
"AIR", # Airflow | ||
"ASYNC", # flake8-async | ||
"BLE", # flake8-blind-except | ||
"C90", # McCabe cyclomatic complexity | ||
"DJ", # flake8-django | ||
"DTZ", # flake8-datetimez | ||
"E", # pycodestyle errors | ||
"F", # Pyflakes | ||
"FIX", # flake8-fixme | ||
"FLY", # flynt | ||
"G", # flake8-logging-format | ||
"ICN", # flake8-import-conventions | ||
"INP", # flake8-no-pep420 | ||
"INT", # flake8-gettext | ||
"NPY", # NumPy-specific rules | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this library doesn't use numpy or pandas and seems unlikely to start doing so so these could be omitted for a minor gain in readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Famous last words. You never know when code will be forked or when contributors will have new ideas. Given that ruff can lint the entire CPython codebase in less than a third of a second with no cache, I take the stance that if a family of rules pass then run them. |
||
"PD", # pandas-vet | ||
"PIE", # flake8-pie | ||
"PL", # Pylint | ||
"PYI", # flake8-pyi | ||
"RSE", # flake8-raise | ||
"SLOT", # flake8-slots | ||
"T10", # flake8-debugger | ||
"T20", # flake8-print | ||
"TD", # flake8-todos | ||
"TID", # flake8-tidy-imports | ||
"UP", # pyupgrade | ||
"W", # pycodestyle warnings | ||
"YTT", # flake8-2020 | ||
# "A", # flake8-builtins | ||
# "ANN", # flake8-annotations | ||
# "ARG", # flake8-unused-arguments | ||
# "B", # flake8-bugbear | ||
# "C4", # flake8-comprehensions | ||
# "COM", # flake8-commas | ||
# "CPY", # flake8-copyright | ||
# "D", # pydocstyle | ||
# "EM", # flake8-errmsg | ||
# "ERA", # eradicate | ||
# "EXE", # flake8-executable | ||
# "FA", # flake8-future-annotations | ||
# "FBT", # flake8-boolean-trap | ||
# "I", # isort | ||
# "ISC", # flake8-implicit-str-concat | ||
# "N", # pep8-naming | ||
# "PERF", # Perflint | ||
# "PGH", # pygrep-hooks | ||
# "PT", # flake8-pytest-style | ||
# "PTH", # flake8-use-pathlib | ||
# "Q", # flake8-quotes | ||
# "RET", # flake8-return | ||
# "RUF", # Ruff-specific rules | ||
# "S", # flake8-bandit | ||
# "SIM", # flake8-simplify | ||
# "SLF", # flake8-self | ||
# "TCH", # flake8-type-checking | ||
# "TRY", # tryceratops | ||
] | ||
# Files not checked: | ||
# - migrations: most of these are autogenerated and don't need a check | ||
# - docs: contains autogenerated code that doesn't need a check | ||
exclude = [ | ||
"*/migrations/*", | ||
"docs", | ||
] | ||
ignore = ["F401"] | ||
|
||
[tool.ruff.lint.mccabe] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: why complexity 23 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set it to 22 and see what happens... % |
||
max-complexity = 23 | ||
|
||
[tool.ruff.lint.per-file-ignores] | ||
"docs/conf.py" = ["INP001"] | ||
"test_app/models.py" = ["DJ008"] # FIXME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: nice to highlight this in the comment |
||
"waffle/models.py" = ["DJ012", "PYI019"] # FIXME | ||
|
||
[tool.ruff.lint.pylint] | ||
allow-magic-value-types = ["float", "int", "str"] | ||
max-args = 6 # default is 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: nice to have the defaults mentioned here as a possible future target for refactoring |
||
max-branches = 23 # default is 12 | ||
max-returns = 13 # default is 6 | ||
max-statements = 51 # default is 50 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ Django | |
django-jinja>=2.4.1,<3 | ||
transifex-client | ||
|
||
flake8 | ||
mypy | ||
ruff | ||
tox |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
flake8 | ||
ruff | ||
tox |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||
# This file is distributed under the same license as the PACKAGE package. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
# | ||
# | ||
# Translators: | ||
# Clinton Blackburn <[email protected]>, 2021 | ||
# | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why this set of lint rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the ones that currently pass. Future PRs can uncomment rules that might be of interest. We do not want this PR to contain so many changes that it slows the review process.