Skip to content

Commit 44d5da0

Browse files
committed
Reformat codebase with isort
1 parent e0a780a commit 44d5da0

30 files changed

+235
-185
lines changed

action/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import shlex
33
import sys
44
from pathlib import Path
5-
from subprocess import run, PIPE, STDOUT
5+
from subprocess import PIPE, STDOUT, run
66

77
ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
88
ENV_PATH = ACTION_PATH / ".black-env"

fuzz.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import re
99

1010
import hypothesmith
11-
from hypothesis import HealthCheck, given, settings, strategies as st
11+
from hypothesis import HealthCheck, given, settings
12+
from hypothesis import strategies as st
1213

1314
import black
1415
from blib2to3.pgen2.tokenize import TokenError
@@ -78,6 +79,7 @@ def test_idempotent_any_syntatically_valid_python(
7879
# (if you want only bounded fuzzing, just use `pytest fuzz.py`)
7980
try:
8081
import sys
82+
8183
import atheris
8284
except ImportError:
8385
pass

gallery/gallery.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@
1010
from concurrent.futures import ThreadPoolExecutor
1111
from functools import lru_cache, partial
1212
from pathlib import Path
13-
from typing import (
14-
Generator,
15-
List,
16-
NamedTuple,
17-
Optional,
18-
Tuple,
19-
Union,
20-
cast,
21-
)
13+
from typing import Generator, List, NamedTuple, Optional, Tuple, Union, cast
2214
from urllib.request import urlopen, urlretrieve
2315

2416
PYPI_INSTANCE = "https://pypi.org/pypi"

scripts/migrate-black.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import os
77
import sys
8-
from subprocess import check_output, run, Popen, PIPE
8+
from subprocess import PIPE, Popen, check_output, run
99

1010

1111
def git(*args: str) -> str:

setup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Copyright (C) 2020 Łukasz Langa
2-
from setuptools import setup, find_packages
3-
import sys
42
import os
3+
import sys
4+
5+
from setuptools import find_packages, setup
56

67
assert sys.version_info >= (3, 6, 2), "black requires Python 3.6.2+"
78
from pathlib import Path # noqa E402

src/black/__init__.py

+51-38
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import asyncio
2-
from json.decoder import JSONDecodeError
3-
import json
4-
from contextlib import contextmanager
5-
from datetime import datetime
6-
from enum import Enum
72
import io
8-
from multiprocessing import Manager, freeze_support
3+
import json
94
import os
10-
from pathlib import Path
11-
from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
125
import platform
136
import re
147
import signal
158
import sys
169
import tokenize
1710
import traceback
11+
from contextlib import contextmanager
12+
from dataclasses import replace
13+
from datetime import datetime
14+
from enum import Enum
15+
from json.decoder import JSONDecodeError
16+
from multiprocessing import Manager, freeze_support
17+
from pathlib import Path
1818
from typing import (
1919
TYPE_CHECKING,
2020
Any,
@@ -34,48 +34,61 @@
3434

3535
import click
3636
from click.core import ParameterSource
37-
from dataclasses import replace
3837
from mypy_extensions import mypyc_attr
38+
from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
3939

40-
from black.const import DEFAULT_LINE_LENGTH, DEFAULT_INCLUDES, DEFAULT_EXCLUDES
41-
from black.const import STDIN_PLACEHOLDER
42-
from black.nodes import STARS, syms, is_simple_decorator_expression
43-
from black.nodes import is_string_token, is_number_token
44-
from black.lines import Line, EmptyLineTracker
45-
from black.linegen import transform_line, LineGenerator, LN
40+
from _black_version import version as __version__
41+
from black.cache import Cache, filter_cached, get_cache_info, read_cache, write_cache
4642
from black.comments import normalize_fmt_off
47-
from black.mode import FUTURE_FLAG_TO_FEATURE, Mode, TargetVersion
48-
from black.mode import Feature, supports_feature, VERSION_TO_FEATURES
49-
from black.cache import read_cache, write_cache, get_cache_info, filter_cached, Cache
50-
from black.concurrency import cancel, shutdown, maybe_install_uvloop
51-
from black.output import dump_to_file, ipynb_diff, diff, color_diff, out, err
52-
from black.report import Report, Changed, NothingChanged
43+
from black.concurrency import cancel, maybe_install_uvloop, shutdown
44+
from black.const import (
45+
DEFAULT_EXCLUDES,
46+
DEFAULT_INCLUDES,
47+
DEFAULT_LINE_LENGTH,
48+
STDIN_PLACEHOLDER,
49+
)
5350
from black.files import (
5451
find_project_root,
5552
find_pyproject_toml,
56-
parse_pyproject_toml,
5753
find_user_pyproject_toml,
54+
gen_python_files,
55+
get_gitignore,
56+
normalize_path_maybe_ignore,
57+
parse_pyproject_toml,
58+
wrap_stream_for_windows,
5859
)
59-
from black.files import gen_python_files, get_gitignore, normalize_path_maybe_ignore
60-
from black.files import wrap_stream_for_windows
61-
from black.parsing import InvalidInput # noqa F401
62-
from black.parsing import lib2to3_parse, parse_ast, stringify_ast
6360
from black.handle_ipynb_magics import (
64-
mask_cell,
65-
unmask_cell,
66-
remove_trailing_semicolon,
67-
put_trailing_semicolon_back,
68-
TRANSFORMED_MAGICS,
6961
PYTHON_CELL_MAGICS,
62+
TRANSFORMED_MAGICS,
7063
jupyter_dependencies_are_installed,
64+
mask_cell,
65+
put_trailing_semicolon_back,
66+
remove_trailing_semicolon,
67+
unmask_cell,
7168
)
72-
73-
74-
# lib2to3 fork
75-
from blib2to3.pytree import Node, Leaf
69+
from black.linegen import LN, LineGenerator, transform_line
70+
from black.lines import EmptyLineTracker, Line
71+
from black.mode import (
72+
FUTURE_FLAG_TO_FEATURE,
73+
VERSION_TO_FEATURES,
74+
Feature,
75+
Mode,
76+
TargetVersion,
77+
supports_feature,
78+
)
79+
from black.nodes import (
80+
STARS,
81+
is_number_token,
82+
is_simple_decorator_expression,
83+
is_string_token,
84+
syms,
85+
)
86+
from black.output import color_diff, diff, dump_to_file, err, ipynb_diff, out
87+
from black.parsing import InvalidInput # noqa F401
88+
from black.parsing import lib2to3_parse, parse_ast, stringify_ast
89+
from black.report import Changed, NothingChanged, Report
7690
from blib2to3.pgen2 import token
77-
78-
from _black_version import version as __version__
91+
from blib2to3.pytree import Leaf, Node
7992

8093
if TYPE_CHECKING:
8194
from concurrent.futures import Executor
@@ -770,7 +783,7 @@ def reformat_many(
770783
workers: Optional[int],
771784
) -> None:
772785
"""Reformat multiple files using a ProcessPoolExecutor."""
773-
from concurrent.futures import Executor, ThreadPoolExecutor, ProcessPoolExecutor
786+
from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor
774787

775788
executor: Executor
776789
worker_count = workers if workers is not None else DEFAULT_WORKERS

src/black/brackets.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
"""Builds on top of nodes.py to track brackets."""
22

3-
from dataclasses import dataclass, field
43
import sys
4+
from dataclasses import dataclass, field
55
from typing import Dict, Iterable, List, Optional, Tuple, Union
66

77
if sys.version_info < (3, 8):
88
from typing_extensions import Final
99
else:
1010
from typing import Final
1111

12-
from blib2to3.pytree import Leaf, Node
12+
from black.nodes import (
13+
BRACKET,
14+
CLOSING_BRACKETS,
15+
COMPARATORS,
16+
LOGIC_OPERATORS,
17+
MATH_OPERATORS,
18+
OPENING_BRACKETS,
19+
UNPACKING_PARENTS,
20+
VARARGS_PARENTS,
21+
is_vararg,
22+
syms,
23+
)
1324
from blib2to3.pgen2 import token
14-
15-
from black.nodes import syms, is_vararg, VARARGS_PARENTS, UNPACKING_PARENTS
16-
from black.nodes import BRACKET, OPENING_BRACKETS, CLOSING_BRACKETS
17-
from black.nodes import MATH_OPERATORS, COMPARATORS, LOGIC_OPERATORS
25+
from blib2to3.pytree import Leaf, Node
1826

1927
# types
2028
LN = Union[Leaf, Node]

src/black/cache.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import os
44
import pickle
5-
from pathlib import Path
65
import tempfile
6+
from pathlib import Path
77
from typing import Dict, Iterable, Set, Tuple
88

99
from platformdirs import user_cache_dir
1010

11-
from black.mode import Mode
12-
1311
from _black_version import version as __version__
14-
12+
from black.mode import Mode
1513

1614
# types
1715
Timestamp = float

src/black/comments.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1+
import re
12
import sys
23
from dataclasses import dataclass
34
from functools import lru_cache
4-
import re
55
from typing import Iterator, List, Optional, Union
66

77
if sys.version_info >= (3, 8):
88
from typing import Final
99
else:
1010
from typing_extensions import Final
1111

12-
from blib2to3.pytree import Node, Leaf, type_repr
12+
from black.nodes import (
13+
CLOSING_BRACKETS,
14+
STANDALONE_COMMENT,
15+
WHITESPACE,
16+
container_of,
17+
first_leaf_column,
18+
preceding_leaf,
19+
)
1320
from blib2to3.pgen2 import token
14-
15-
from black.nodes import first_leaf_column, preceding_leaf, container_of
16-
from black.nodes import CLOSING_BRACKETS, STANDALONE_COMMENT, WHITESPACE
21+
from blib2to3.pytree import Leaf, Node, type_repr
1722

1823
# types
1924
LN = Union[Leaf, Node]

src/black/debug.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from dataclasses import dataclass
22
from typing import Iterator, TypeVar, Union
33

4-
from blib2to3.pytree import Node, Leaf, type_repr
5-
from blib2to3.pgen2 import token
6-
74
from black.nodes import Visitor
85
from black.output import out
96
from black.parsing import lib2to3_parse
7+
from blib2to3.pgen2 import token
8+
from blib2to3.pytree import Leaf, Node, type_repr
109

1110
LN = Union[Leaf, Node]
1211
T = TypeVar("T")

src/black/files.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from functools import lru_cache
21
import io
32
import os
4-
from pathlib import Path
53
import sys
4+
from functools import lru_cache
5+
from pathlib import Path
66
from typing import (
7+
TYPE_CHECKING,
78
Any,
89
Dict,
910
Iterable,
@@ -14,7 +15,6 @@
1415
Sequence,
1516
Tuple,
1617
Union,
17-
TYPE_CHECKING,
1818
)
1919

2020
from mypy_extensions import mypyc_attr
@@ -30,9 +30,9 @@
3030
else:
3131
import tomli as tomllib
3232

33+
from black.handle_ipynb_magics import jupyter_dependencies_are_installed
3334
from black.output import err
3435
from black.report import Report
35-
from black.handle_ipynb_magics import jupyter_dependencies_are_installed
3636

3737
if TYPE_CHECKING:
3838
import colorama # noqa: F401

src/black/handle_ipynb_magics.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
"""Functions to process IPython magics with."""
22

3-
from functools import lru_cache
4-
import dataclasses
53
import ast
6-
from typing import Dict, List, Tuple, Optional
7-
4+
import collections
5+
import dataclasses
86
import secrets
97
import sys
10-
import collections
8+
from functools import lru_cache
9+
from typing import Dict, List, Optional, Tuple
1110

1211
if sys.version_info >= (3, 10):
1312
from typing import TypeGuard
1413
else:
1514
from typing_extensions import TypeGuard
1615

17-
from black.report import NothingChanged
1816
from black.output import out
19-
17+
from black.report import NothingChanged
2018

2119
TRANSFORMED_MAGICS = frozenset(
2220
(
@@ -90,11 +88,7 @@ def remove_trailing_semicolon(src: str) -> Tuple[str, bool]:
9088
Mirrors the logic in `quiet` from `IPython.core.displayhook`, but uses
9189
``tokenize_rt`` so that round-tripping works fine.
9290
"""
93-
from tokenize_rt import (
94-
src_to_tokens,
95-
tokens_to_src,
96-
reversed_enumerate,
97-
)
91+
from tokenize_rt import reversed_enumerate, src_to_tokens, tokens_to_src
9892

9993
tokens = src_to_tokens(src)
10094
trailing_semicolon = False
@@ -118,7 +112,7 @@ def put_trailing_semicolon_back(src: str, has_trailing_semicolon: bool) -> str:
118112
"""
119113
if not has_trailing_semicolon:
120114
return src
121-
from tokenize_rt import src_to_tokens, tokens_to_src, reversed_enumerate
115+
from tokenize_rt import reversed_enumerate, src_to_tokens, tokens_to_src
122116

123117
tokens = src_to_tokens(src)
124118
for idx, token in reversed_enumerate(tokens):

0 commit comments

Comments
 (0)