Skip to content

Commit

Permalink
Move from isort to reorder-python-imports (#287)
Browse files Browse the repository at this point in the history
It’s [way
faster](https://twitter.com/codewithanthony/status/1553034384206438401)
and its one-import-per-line style prevents merge conflicts.
  • Loading branch information
adamchainz authored Nov 4, 2022
1 parent 68d4c6f commit 5afcc45
Show file tree
Hide file tree
Showing 70 changed files with 368 additions and 212 deletions.
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ repos:
- id: blacken-docs
additional_dependencies:
- black==22.10.0
- repo: https://github.com/pycqa/isort
rev: 5.10.1
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0
hooks:
- id: isort
- id: reorder-python-imports
args:
- --py38-plus
- --application-directories
- .:example:src
- --add-import
- 'from __future__ import annotations'
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ build-backend = "setuptools.build_meta"
[tool.black]
target-version = ['py38']

[tool.isort]
profile = "black"
add_imports = "from __future__ import annotations"

[tool.mypy]
mypy_path = "src/"
show_error_codes = true
Expand Down
23 changes: 11 additions & 12 deletions src/django_upgrade/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
import re
from collections import defaultdict
from functools import cached_property
from typing import (
TYPE_CHECKING,
Any,
Callable,
DefaultDict,
Iterable,
List,
Tuple,
TypeVar,
)

from tokenize_rt import Offset, Token
from typing import Any
from typing import Callable
from typing import DefaultDict
from typing import Iterable
from typing import List
from typing import Tuple
from typing import TYPE_CHECKING
from typing import TypeVar

from tokenize_rt import Offset
from tokenize_rt import Token

from django_upgrade import fixers

Expand Down
4 changes: 3 additions & 1 deletion src/django_upgrade/fixers/admin_allow_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from tokenize_rt import Offset

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import erase_node

fixer = Fixer(
Expand Down
25 changes: 14 additions & 11 deletions src/django_upgrade/fixers/admin_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@

import ast
from functools import partial
from typing import Iterable, Literal
from typing import Iterable
from typing import Literal

from tokenize_rt import Offset, Token, tokens_to_src
from tokenize_rt import Offset
from tokenize_rt import Token
from tokenize_rt import tokens_to_src

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.tokens import (
OP,
erase_node,
extract_indent,
find_last_token,
insert,
reverse_find,
)
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import erase_node
from django_upgrade.tokens import extract_indent
from django_upgrade.tokens import find_last_token
from django_upgrade.tokens import insert
from django_upgrade.tokens import OP
from django_upgrade.tokens import reverse_find

fixer = Fixer(
__name__,
Expand Down
18 changes: 14 additions & 4 deletions src/django_upgrade/fixers/admin_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@

import ast
from functools import partial
from typing import Iterable, Literal, MutableMapping, cast
from typing import cast
from typing import Iterable
from typing import Literal
from typing import MutableMapping
from weakref import WeakKeyDictionary

from tokenize_rt import Offset, Token
from tokenize_rt import Offset
from tokenize_rt import Token

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.tokens import OP, erase_node, extract_indent, insert, reverse_find
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import erase_node
from django_upgrade.tokens import extract_indent
from django_upgrade.tokens import insert
from django_upgrade.tokens import OP
from django_upgrade.tokens import reverse_find

fixer = Fixer(
__name__,
Expand Down
29 changes: 17 additions & 12 deletions src/django_upgrade/fixers/assert_form_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@

import ast
from functools import partial
from typing import Any, Iterable, Literal
from typing import Any
from typing import Iterable
from typing import Literal

from tokenize_rt import UNIMPORTANT_WS, Offset, Token, tokens_to_src
from tokenize_rt import Offset
from tokenize_rt import Token
from tokenize_rt import tokens_to_src
from tokenize_rt import UNIMPORTANT_WS

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.tokens import (
OP,
PHYSICAL_NEWLINE,
consume,
find_first_token,
find_last_token,
replace,
reverse_consume,
)
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import consume
from django_upgrade.tokens import find_first_token
from django_upgrade.tokens import find_last_token
from django_upgrade.tokens import OP
from django_upgrade.tokens import PHYSICAL_NEWLINE
from django_upgrade.tokens import replace
from django_upgrade.tokens import reverse_consume

fixer = Fixer(
__name__,
Expand Down
7 changes: 5 additions & 2 deletions src/django_upgrade/fixers/compatibility_imports_1_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

from tokenize_rt import Offset

from django_upgrade.ast import ast_start_offset, is_rewritable_import_from
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.ast import ast_start_offset
from django_upgrade.ast import is_rewritable_import_from
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import update_import_modules

fixer = Fixer(
Expand Down
7 changes: 5 additions & 2 deletions src/django_upgrade/fixers/compatibility_imports_1_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

from tokenize_rt import Offset

from django_upgrade.ast import ast_start_offset, is_rewritable_import_from
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.ast import ast_start_offset
from django_upgrade.ast import is_rewritable_import_from
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import update_import_modules

fixer = Fixer(
Expand Down
11 changes: 8 additions & 3 deletions src/django_upgrade/fixers/crypto_get_random_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
from functools import partial
from typing import Iterable

from tokenize_rt import Offset, Token
from tokenize_rt import Offset
from tokenize_rt import Token

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.tokens import CODE, OP, find
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import CODE
from django_upgrade.tokens import find
from django_upgrade.tokens import OP

fixer = Fixer(
__name__,
Expand Down
4 changes: 3 additions & 1 deletion src/django_upgrade/fixers/default_app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from tokenize_rt import Offset

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import erase_node

fixer = Fixer(
Expand Down
29 changes: 16 additions & 13 deletions src/django_upgrade/fixers/django_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@
import ast
import re
from functools import partial
from typing import Iterable, MutableMapping
from typing import Iterable
from typing import MutableMapping
from weakref import WeakKeyDictionary

from tokenize_rt import Offset, Token
from tokenize_rt import Offset
from tokenize_rt import Token

from django_upgrade.ast import ast_start_offset, is_rewritable_import_from
from django_upgrade.ast import ast_start_offset
from django_upgrade.ast import is_rewritable_import_from
from django_upgrade.compat import str_removeprefix
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.tokens import (
STRING,
extract_indent,
find,
insert,
replace,
str_repr_matching,
update_import_names,
)
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import extract_indent
from django_upgrade.tokens import find
from django_upgrade.tokens import insert
from django_upgrade.tokens import replace
from django_upgrade.tokens import str_repr_matching
from django_upgrade.tokens import STRING
from django_upgrade.tokens import update_import_names

fixer = Fixer(
__name__,
Expand Down
4 changes: 3 additions & 1 deletion src/django_upgrade/fixers/email_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from tokenize_rt import Offset

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import replace_argument_names

fixer = Fixer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from tokenize_rt import Offset

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import replace

fixer = Fixer(
Expand Down
7 changes: 5 additions & 2 deletions src/django_upgrade/fixers/jsonfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

from tokenize_rt import Offset

from django_upgrade.ast import ast_start_offset, is_rewritable_import_from
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.ast import ast_start_offset
from django_upgrade.ast import is_rewritable_import_from
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import update_import_modules

fixer = Fixer(
Expand Down
4 changes: 3 additions & 1 deletion src/django_upgrade/fixers/management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from tokenize_rt import Offset

from django_upgrade.ast import ast_start_offset
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import replace

fixer = Fixer(
Expand Down
24 changes: 13 additions & 11 deletions src/django_upgrade/fixers/null_boolean_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
from functools import partial
from typing import Iterable

from tokenize_rt import Offset, Token
from tokenize_rt import Offset
from tokenize_rt import Token

from django_upgrade.ast import ast_start_offset, is_rewritable_import_from
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.tokens import (
CODE,
OP,
find,
find_and_replace_name,
parse_call_args,
update_import_names,
)
from django_upgrade.ast import ast_start_offset
from django_upgrade.ast import is_rewritable_import_from
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import CODE
from django_upgrade.tokens import find
from django_upgrade.tokens import find_and_replace_name
from django_upgrade.tokens import OP
from django_upgrade.tokens import parse_call_args
from django_upgrade.tokens import update_import_names

fixer = Fixer(
__name__,
Expand Down
21 changes: 15 additions & 6 deletions src/django_upgrade/fixers/on_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@

import ast
from functools import partial
from typing import Iterable, MutableMapping
from typing import Iterable
from typing import MutableMapping
from weakref import WeakKeyDictionary

from tokenize_rt import Offset, Token

from django_upgrade.ast import ast_start_offset, is_rewritable_import_from
from django_upgrade.data import Fixer, State, TokenFunc
from django_upgrade.tokens import OP, extract_indent, find, insert, parse_call_args
from tokenize_rt import Offset
from tokenize_rt import Token

from django_upgrade.ast import ast_start_offset
from django_upgrade.ast import is_rewritable_import_from
from django_upgrade.data import Fixer
from django_upgrade.data import State
from django_upgrade.data import TokenFunc
from django_upgrade.tokens import extract_indent
from django_upgrade.tokens import find
from django_upgrade.tokens import insert
from django_upgrade.tokens import OP
from django_upgrade.tokens import parse_call_args

fixer = Fixer(
__name__,
Expand Down
Loading

0 comments on commit 5afcc45

Please sign in to comment.