Skip to content

Commit

Permalink
[ruff] Migrate from flake8 and isort, autofix existing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Oct 30, 2023
1 parent 8229b3c commit 547e1cd
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 30 deletions.
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.7]
toxenv: [django_not_installed, flake8, pylint, readme]
toxenv: [django_not_installed, ruff, pylint, readme]

steps:
- uses: actions/checkout@v3
Expand Down
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ repos:
- id: mixed-line-ending
args: [--fix=lf]
- id: debug-statements
# code formatting
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.1"
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']
2 changes: 1 addition & 1 deletion pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def pylint_newstyle_classdef_compat(linter, warning_name, augment):
return
suppress_message(
linter,
getattr(NewStyleConflictChecker, "visit_classdef"),
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 @@ -52,7 +52,7 @@ class PylintDjangoLintModuleTest(LintModuleTest):

def __init__(self, test_file):
# if hasattr(test_file, 'option_file') and test_file.option_file is None:
super(PylintDjangoLintModuleTest, self).__init__(test_file)
super()
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 @@ -77,3 +78,18 @@ line_length = 120
disable = ["missing-docstring","too-many-branches","too-many-return-statements","too-many-ancestors","fixme"]
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 comments on commit 547e1cd

Please sign in to comment.