Skip to content

Commit 547e1cd

Browse files
[ruff] Migrate from flake8 and isort, autofix existing issues
1 parent 8229b3c commit 547e1cd

File tree

10 files changed

+27
-30
lines changed

10 files changed

+27
-30
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
python-version: [3.7]
16-
toxenv: [django_not_installed, flake8, pylint, readme]
16+
toxenv: [django_not_installed, ruff, pylint, readme]
1717

1818
steps:
1919
- uses: actions/checkout@v3

.pre-commit-config.yaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@ repos:
88
- id: mixed-line-ending
99
args: [--fix=lf]
1010
- id: debug-statements
11-
# code formatting
12-
- repo: https://github.com/PyCQA/flake8
13-
rev: 6.1.0
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: "v0.1.1"
1413
hooks:
15-
- id: flake8
16-
args: [ --max-line-length=120 ]
14+
- id: ruff
15+
args: ["--fix"]
16+
exclude: "tests/input/"
1717
- repo: https://github.com/psf/black
1818
rev: 23.10.1
1919
hooks:
2020
- id: black
2121
args: [--safe, --line-length=120]
22-
- repo: https://github.com/PyCQA/isort
23-
rev: 5.12.0
24-
hooks:
25-
- id: isort
26-
args: ['--profile', 'black']

pylint_django/augmentations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def pylint_newstyle_classdef_compat(linter, warning_name, augment):
790790
return
791791
suppress_message(
792792
linter,
793-
getattr(NewStyleConflictChecker, "visit_classdef"),
793+
NewStyleConflictChecker.visit_classdef,
794794
warning_name,
795795
augment,
796796
)

pylint_django/checkers/django_installed.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
from pylint.checkers import BaseChecker
42

53
from pylint_django.__pkginfo__ import BASE_ID

pylint_django/checkers/foreign_key_strings.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import astroid
42
from pylint.checkers import BaseChecker
53

@@ -87,7 +85,6 @@ def open(self):
8785
django.setup()
8886
from django.apps import apps # noqa pylint: disable=import-outside-toplevel,unused-import
8987

90-
# flake8: noqa=F401, F403
9188
except ImproperlyConfigured:
9289
# this means that Django wasn't able to configure itself using some defaults
9390
# provided (likely in a DJANGO_SETTINGS_MODULE environment variable)

pylint_django/plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Common Django module."""
22
# we want to import the transforms to make sure they get added to the astroid manager,
33
# however we don't actually access them directly, so we'll disable the warning
4-
from pylint_django import transforms # noqa, pylint: disable=unused-import
54
from pylint_django import compat
65
from pylint_django.checkers import register_checkers
76

pylint_django/tests/test_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class PylintDjangoLintModuleTest(LintModuleTest):
5252

5353
def __init__(self, test_file):
5454
# if hasattr(test_file, 'option_file') and test_file.option_file is None:
55-
super(PylintDjangoLintModuleTest, self).__init__(test_file)
55+
super()
5656
self._linter.load_plugin_modules(["pylint_django"])
5757
self._linter.load_plugin_configuration()
5858

pylint_django/transforms/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def is_model_or_form_field(cls):
4646
return is_model_field(cls) or is_form_field(cls)
4747

4848

49-
def apply_type_shim(cls, _context=None): # noqa
49+
def apply_type_shim(cls, _context=None):
5050
if cls.name in _STR_FIELDS:
5151
base_nodes = scoped_nodes.builtin_lookup("str")
5252
elif cls.name in _INT_FIELDS:
@@ -93,7 +93,7 @@ def apply_type_shim(cls, _context=None): # noqa
9393
else:
9494
base_nodes = list(base_nodes[1])
9595

96-
return iter([cls] + base_nodes)
96+
return iter([cls, *base_nodes])
9797

9898

9999
def _valid_base_node(node, context):

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Django = {version=">=2.2", optional = true}
4949
tox = "^4.5.1"
5050
pytest = "^7.3.1"
5151
pylint = ">=2.13"
52+
ruff = ">=0.1.1"
5253
twine = "^4.0.2"
5354
wheel = "^0.40.0"
5455
pytest-cov = "^4.0.0"
@@ -77,3 +78,18 @@ line_length = 120
7778
disable = ["missing-docstring","too-many-branches","too-many-return-statements","too-many-ancestors","fixme"]
7879
ignore="tests"
7980
max-line-length = 120
81+
82+
[tool.ruff]
83+
line-length = 120
84+
select = [
85+
"E", # pycodestyle
86+
"F", # pyflakes
87+
"W", # pycodestyle
88+
"B", # bugbear
89+
"I", # isort
90+
"RUF", # ruff
91+
"UP", # pyupgrade
92+
]
93+
ignore = [
94+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
95+
]

tox.ini

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ commands =
2626
clean: find . -type d -name __pycache__ -delete
2727
clean: rm -rf build/ .cache/ dist/ .eggs/ pylint_django.egg-info/ .tox/
2828
deps =
29-
flake8: flake8
29+
ruff: ruff
3030
pylint: pylint<3
3131
pylint: Django
3232
readme: twine
@@ -50,11 +50,3 @@ allowlist_externals =
5050
py{37,38,39,310,311}-django{22,30,31,32,40,41,42}: bash
5151
clean: find
5252
clean: rm
53-
54-
[flake8]
55-
max-line-length = 120
56-
57-
58-
59-
[FORMAT]
60-
max-line-length=120

0 commit comments

Comments
 (0)