8000 Migrate from isort and flake8 to ruff by Pierre-Sassoulas · Pull Request #414 · pylint-dev/pylint-django · GitHub
[go: up one dir, main page]

Skip to content

Migrate from isort and flake8 to ruff #414

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000 2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.11"]
toxenv: [django_not_installed, flake8, pylint, readme]
toxenv: [django_not_installed, ruff, pylint, readme]

steps:
- uses: actions/checkout@v3
Expand Down
14 changes: 5 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ repos:
- id: mixed-line-ending
args: [--fix=lf]
- id: debug-statements
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.4"
hooks:
- id: flake8
args: [--max-line-length=120]
- id: ruff
args: ["--fix"]
exclude: "tests/input/"
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
args: [--safe, --line-length=120]
- repo: https://github.com/PyCQA/isort
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do ruff + black play well together for sorting imports? I remember that isort came after black due to them conflicting, however that was some time ago and likely fixed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah ruff went out after black so it supports it without config. (there's also ruffmt now, but I like black for having only one option).

rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
Expand Down
3 changes: 2 additions & 1 deletion pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ def pylint_newstyle_classdef_compat(linter, warning_name, augment):
return
suppress_message(
linter,
getattr(NewStyleConflictChecker, "visit_classdef"),
# pylint: disable-next=no-member
NewStyleConflictChecker.visit_classdef,
warning_name,
augment,
)
Expand Down
2 changes: 0 additions & 2 deletions pylint_django/checkers/django_installed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from pylint.checkers import BaseChecker

from pylint_django.__pkginfo__ import BASE_ID
Expand Down
3 changes: 0 additions & 3 deletions pylint_django/checkers/foreign_key_strings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import astroid
from pylint.checkers import BaseChecker

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

# flake8: noqa=F401, F403
except ImproperlyConfigured:
# this means that Django wasn't able to configure itself using some defaults
# provided (likely in a DJANGO_SETTINGS_MODULE environment variable)
Expand Down
1 change: 0 additions & 1 deletion pylint_django/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Common Django module."""
# we want to import the transforms to make sure they get added to the astroid manager,
# however we don't actually access them directly, so we'll disable the warning
from pylint_django import transforms # noqa, pylint: disable=unused-import
from pylint_django import compat
from pylint_django.checkers import register_checkers

Expand Down
2 changes: 1 addition & 1 deletion pylint_django/tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, test_file):
# if hasattr(test_file, 'option_file') and test_file.option_file is None:
# pylint: disable=super-with-arguments
# TODO Fix this and the CI (?)
super(PylintDjangoLintModuleTest, self).__init__(test_file)
super(PylintDjangoLintModuleTest, self).__init__(test_file) # noqa
self._linter.load_plugin_modules(["pylint_django"])
self._linter.load_plugin_configuration()

Expand Down
4 changes: 2 additions & 2 deletions pylint_django/transforms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def is_model_or_form_field(cls):
return is_model_field(cls) or is_form_field(cls)


def apply_type_shim(cls, _context=None): # noqa
def apply_type_shim(cls, _context=None):
if cls.name in _STR_FIELDS:
base_nodes = scoped_nodes.builtin_lookup("str")
elif cls.name in _INT_FIELDS:
Expand Down Expand Up @@ -93,7 +93,7 @@ def apply_type_shim(cls, _context=None): # noqa
else:
base_nodes = list(base_nodes[1])

return iter([cls] + base_nodes)
return iter([cls, *base_nodes])


def _valid_base_node(node, context):
Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Django = {version=">=2.2", optional = true}
tox = "^4.5.1"
pytest = "^7.3.1"
pylint = ">=2.13"
ruff = ">=0.1.1"
twine = "^4.0.2"
wheel = "^0.40.0"
pytest-cov = "^4.0.0"
Expand Down Expand Up @@ -82,3 +83,18 @@ disable = [
]
ignore="tests"
max-line-length = 120

[tool.ruff]
line-length = 120
select = [
"E", # pycodestyle
"F", # pyflakes
"W", # pycodestyle
"B", # bugbear
"I", # isort
"RUF", # ruff
"UP", # pyupgrade
]
ignore = [
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
]
10 changes: 1 addition & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ commands =
clean: find . -type d -name __pycache__ -delete
clean: rm -rf build/ .cache/ dist/ .eggs/ pylint_django.egg-info/ .tox/
deps =
flake8: flake8
ruff: ruff
pylint: pylint<3
pylint: Django
readme: twine
Expand All @@ -50,11 +50,3 @@ allowlist_externals =
py{37,38,39,310,311}-django{22,30,31,32,40,41,42}: bash
clean: find
clean: rm

[flake8]
max-line-length = 120



[FORMAT]
max-line-length=120
0