Skip to content

Commit

Permalink
CI: Replace isort with Ruff import sorting (#1507)
Browse files Browse the repository at this point in the history
This is the first step in adopting Ruff: https://beta.ruff.rs/

Ruff is faster and will allow us to perform more fixes and checks in the future (e.g. replacing flake8, pyupgrade, auto-removing unused imports, etc).

There are some import formatting changes around places that use renamed imports (import X import Y as Z) but I think it's not any worse.
  • Loading branch information
intgr authored Jun 5, 2023
1 parent e0587a5 commit 0ea2222
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.idea/
.mypy_cache/
.pytest_cache/
.ruff_cache/
.venv/
__pycache__/
django-source/
Expand Down
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ repos:
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.269
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (pyi)
types: [pyi]
- id: ruff
args: ["--fix", "--fixable=I001", "--exit-non-zero-on-fix"]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/db/backends/base/operations.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections.abc import Iterable, Sequence
from datetime import date
from datetime import date, time, timedelta
from datetime import datetime as real_datetime
from datetime import time, timedelta
from decimal import Decimal
from typing import Any

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/db/models/fields/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import decimal
import uuid
from collections.abc import Callable, Iterable, Sequence
from datetime import date
from datetime import date, time, timedelta
from datetime import datetime as real_datetime
from datetime import time, timedelta
from typing import Any, Generic, Protocol, TypeVar, overload

from django.core import validators # due to weird mypy.stubtest error
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/utils/dateparse.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import date
from datetime import date, time, timedelta
from datetime import datetime as builtin_datetime
from datetime import time, timedelta
from re import Pattern

date_re: Pattern[str]
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/utils/formats.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import types
from collections.abc import Iterator
from datetime import date
from datetime import date, time
from datetime import datetime as builtin_datetime
from datetime import time
from decimal import Decimal
from typing import Any, TypeVar, overload

Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/django/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
from mypy.checker import TypeChecker
from mypy.nodes import TypeInfo
from mypy.plugin import MethodContext
from mypy.types import AnyType, Instance
from mypy.types import AnyType, Instance, TypeOfAny, UnionType
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny, UnionType

from mypy_django_plugin.lib import fullnames, helpers
from mypy_django_plugin.lib.fullnames import WITH_ANNOTATIONS_FULLNAME
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
SemanticAnalyzerPluginInterface,
)
from mypy.semanal import SemanticAnalyzer
from mypy.types import AnyType, Instance, NoneTyp, TupleType
from mypy.types import AnyType, Instance, NoneTyp, TupleType, TypedDictType, TypeOfAny, UnionType
from mypy.types import Type as MypyType
from mypy.types import TypedDictType, TypeOfAny, UnionType

from mypy_django_plugin.lib import fullnames
from mypy_django_plugin.lib.fullnames import WITH_ANNOTATIONS_FULLNAME
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from django.db.models.fields.reverse_related import ForeignObjectRel
from mypy.nodes import AssignmentStmt, NameExpr, TypeInfo
from mypy.plugin import FunctionContext
from mypy.types import AnyType, Instance
from mypy.types import AnyType, Instance, TypeOfAny, UnionType
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny, UnionType

from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import fullnames, helpers
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional

from mypy.plugin import ClassDefContext, MethodContext
from mypy.types import CallableType, Instance, NoneTyp
from mypy.types import CallableType, Instance, NoneTyp, TypeType
from mypy.types import Type as MypyType
from mypy.types import TypeType

from mypy_django_plugin.lib import helpers

Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from mypy.errorcodes import ATTR_DEFINED
from mypy.nodes import CallExpr, MemberExpr
from mypy.plugin import AttributeContext
from mypy.types import AnyType, Instance
from mypy.types import AnyType, Instance, TypeOfAny
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny

from mypy_django_plugin.lib import helpers

Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
from mypy.plugin import AttributeContext, ClassDefContext, DynamicClassDefContext
from mypy.semanal import SemanticAnalyzer
from mypy.semanal_shared import has_placeholder
from mypy.types import AnyType, CallableType, Instance, ProperType
from mypy.types import AnyType, CallableType, Instance, ProperType, TypeOfAny
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny
from mypy.typevars import fill_typevars

from mypy_django_plugin.lib import fullnames, helpers
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/meta.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.core.exceptions import FieldDoesNotExist
from mypy.plugin import MethodContext
from mypy.types import AnyType, Instance
from mypy.types import AnyType, Instance, TypeOfAny
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny

from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import helpers
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from mypy.plugin import AnalyzeTypeContext, AttributeContext, CheckerPluginInterface, ClassDefContext
from mypy.plugins import common
from mypy.semanal import SemanticAnalyzer
from mypy.types import AnyType, Instance
from mypy.types import AnyType, Instance, TypedDictType, TypeOfAny, get_proper_type
from mypy.types import Type as MypyType
from mypy.types import TypedDictType, TypeOfAny, get_proper_type
from mypy.typevars import fill_typevars

from mypy_django_plugin.django.context import DjangoContext
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/orm_lookups.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from mypy.plugin import MethodContext
from mypy.types import AnyType, Instance
from mypy.types import AnyType, Instance, TypeOfAny
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny

from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import fullnames, helpers
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from django.db.models.fields.reverse_related import ForeignObjectRel
from mypy.nodes import ARG_NAMED, ARG_NAMED_OPT, Expression, NameExpr
from mypy.plugin import FunctionContext, MethodContext
from mypy.types import AnyType, Instance, TupleType
from mypy.types import AnyType, Instance, TupleType, TypedDictType, TypeOfAny, get_proper_type
from mypy.types import Type as MypyType
from mypy.types import TypedDictType, TypeOfAny, get_proper_type

from mypy_django_plugin.django.context import DjangoContext, LookupsAreUnsupported
from mypy_django_plugin.lib import fullnames, helpers
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/request.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from mypy.plugin import AttributeContext, MethodContext
from mypy.types import Instance
from mypy.types import Instance, UninhabitedType, UnionType
from mypy.types import Type as MypyType
from mypy.types import UninhabitedType, UnionType

from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import helpers
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from mypy.nodes import MemberExpr
from mypy.plugin import AttributeContext, FunctionContext
from mypy.types import AnyType, Instance
from mypy.types import AnyType, Instance, TypeOfAny, TypeType
from mypy.types import Type as MypyType
from mypy.types import TypeOfAny, TypeType

from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.lib import helpers
Expand Down
21 changes: 15 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
line-length = 120
include = '\.pyi?$'

[tool.isort]
profile = 'black'
line_length = 120
multi_line_output = 3
include_trailing_comma = true
float_to_top = true
[tool.ruff]
# Adds to default excludes: https://ruff.rs/docs/settings/#exclude
extend-exclude = [
"django-source",
"stubgen",
"out",
]
line-length = 120
target-version = "py38"
select = [
"I", # isort
]

[tool.ruff.isort]
split-on-trailing-comma = false

[build-system]
requires = ["setuptools<64", "wheel"]

0 comments on commit 0ea2222

Please sign in to comment.