Skip to content

Commit

Permalink
[ruff] Migrate from flake8 and isort, autofix existing issues (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Nov 4, 2023
1 parent d21ccd3 commit 955f779
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
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
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
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
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
@@ -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
@@ -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
@@ -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
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
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
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
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 comments on commit 955f779

Please sign in to comment.