From 2a5ac32150ad31e443b9fc413c7085d971d2a5c0 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 30 Oct 2023 08:51:17 +0100 Subject: [PATCH] [ruff] Migrate from flake8 and isort, autofix existing issues --- .github/workflows/build.yml | 2 +- .pre-commit-config.yaml | 14 +++++--------- pylint_django/augmentations/__init__.py | 3 ++- pylint_django/checkers/django_installed.py | 2 -- pylint_django/checkers/foreign_key_strings.py | 3 --- pylint_django/plugin.py | 1 - pylint_django/tests/test_func.py | 2 +- pylint_django/transforms/fields.py | 4 ++-- pyproject.toml | 16 ++++++++++++++++ tox.ini | 10 +--------- 10 files changed, 28 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c86de4f9..b9b559db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3a776ed9..9b5909ab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,21 +7,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.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"] - repo: https://github.com/pre-commit/mirrors-prettier rev: v3.0.0-alpha.9-for-vscode hooks: diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index ca8c850b..89f454f4 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -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, ) diff --git a/pylint_django/checkers/django_installed.py b/pylint_django/checkers/django_installed.py index 0caf275b..07723b9e 100644 --- a/pylint_django/checkers/django_installed.py +++ b/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 diff --git a/pylint_django/checkers/foreign_key_strings.py b/pylint_django/checkers/foreign_key_strings.py index 6000c580..345c7eef 100644 --- a/pylint_django/checkers/foreign_key_strings.py +++ b/pylint_django/checkers/foreign_key_strings.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import astroid from pylint.checkers import BaseChecker @@ -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) diff --git a/pylint_django/plugin.py b/pylint_django/plugin.py index 1db620a5..254bd0c9 100644 --- a/pylint_django/plugin.py +++ b/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 diff --git a/pylint_django/tests/test_func.py b/pylint_django/tests/test_func.py index 90adac3d..6ec6894b 100644 --- a/pylint_django/tests/test_func.py +++ b/pylint_django/tests/test_func.py @@ -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() diff --git a/pylint_django/transforms/fields.py b/pylint_django/transforms/fields.py index b9746c5f..b820b12b 100644 --- a/pylint_django/transforms/fields.py +++ b/pylint_django/transforms/fields.py @@ -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: @@ -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): diff --git a/pyproject.toml b/pyproject.toml index 653e25a8..fc5553d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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` +] diff --git a/tox.ini b/tox.ini index 3c191b12..17594857 100644 --- a/tox.ini +++ b/tox.ini @@ -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 @@ -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