Skip to content

Commit 955f779

Browse files
[ruff] Migrate from flake8 and isort, autofix existing issues (#414)
1 parent d21ccd3 commit 955f779

File tree

10 files changed

+28
-29
lines changed

10 files changed

+28
-29
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.11"]
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,17 @@ repos:
1010
- id: mixed-line-ending
1111
args: [--fix=lf]
1212
- id: debug-statements
13-
- repo: https://github.com/PyCQA/flake8
14-
rev: 6.1.0
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: "v0.1.4"
1515
hooks:
16-
- id: flake8
17-
args: [--max-line-length=120]
16+
- id: ruff
17+
args: ["--fix"]
18+
exclude: "tests/input/"
1819
- repo: https://github.com/psf/black
1920
rev: 23.10.1
2021
hooks:
2122
- id: black
2223
args: [--safe, --line-length=120]
23-
- repo: https://github.com/PyCQA/isort
24-
rev: 5.12.0
25-
hooks:
26-
- id: isort
27-
args: ["--profile", "black"]
2824
- repo: https://github.com/pre-commit/mirrors-prettier
2925
rev: v3.0.3
3026
hooks:

pylint_django/augmentations/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ def pylint_newstyle_classdef_compat(linter, warning_name, augment):
790790
return
791791
suppress_message(
792792
linter,
793-
getattr(NewStyleConflictChecker, "visit_classdef"),
793+
# pylint: disable-next=no-member
794+
NewStyleConflictChecker.visit_classdef,
794795
warning_name,
795796
augment,
796797
)

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
@@ -54,7 +54,7 @@ def __init__(self, test_file):
5454
# if hasattr(test_file, 'option_file') and test_file.option_file is None:
5555
# pylint: disable=super-with-arguments
5656
# TODO Fix this and the CI (?)
57-
super(PylintDjangoLintModuleTest, self).__init__(test_file)
57+
super(PylintDjangoLintModuleTest, self).__init__(test_file) # noqa
5858
self._linter.load_plugin_modules(["pylint_django"])
5959
self._linter.load_plugin_configuration()
6060

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"
@@ -82,3 +83,18 @@ disable = [
8283
]
8384
ignore="tests"
8485
max-line-length = 120
86+
87+
[tool.ruff]
88+
line-length = 120
89+
select = [
90+
"E", # pycodestyle
91+
"F", # pyflakes
92+
"W", # pycodestyle
93+
"B", # bugbear
94+
"I", # isort
95+
"RUF", # ruff
96+
"UP", # pyupgrade
97+
]
98+
ignore = [
99+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
100+
]

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy