Skip to content

Commit 3615ce4

Browse files
committed
Enable isort
1 parent 936884d commit 3615ce4

20 files changed

Lines changed: 85 additions & 58 deletions

pytools/__init__.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,22 @@
2727
THE SOFTWARE.
2828
"""
2929

30-
import re
31-
from functools import reduce, wraps
32-
import operator
33-
import sys
34-
import logging
35-
from typing import (
36-
Any, Callable, Dict, Generic, Hashable, Iterable,
37-
List, Optional, Set, Tuple, TypeVar, Union, ClassVar)
3830
import builtins
39-
31+
import logging
4032
import math
33+
import operator
34+
import re
35+
import sys
36+
from functools import reduce, wraps
4137
from sys import intern
38+
from typing import (Any, Callable, ClassVar, Dict, Generic, Hashable, Iterable,
39+
List, Optional, Set, Tuple, TypeVar, Union)
40+
4241

4342
try:
44-
from typing import SupportsIndex, Concatenate
43+
from typing import Concatenate, SupportsIndex
4544
except ImportError:
46-
from typing_extensions import SupportsIndex, Concatenate
45+
from typing_extensions import Concatenate, SupportsIndex
4746

4847
try:
4948
from typing import ParamSpec
@@ -1584,6 +1583,8 @@ def get_write_to_map_from_permutation(original, permuted):
15841583
# {{{ graph algorithms
15851584

15861585
from pytools.graph import a_star as a_star_moved
1586+
1587+
15871588
a_star = MovedFunctionDeprecationWrapper(a_star_moved)
15881589

15891590
# }}}
@@ -1871,7 +1872,7 @@ def string_histogram( # pylint: disable=too-many-arguments,too-many-locals
18711872
print(value, bin_nr, bin_starts)
18721873
raise
18731874

1874-
from math import floor, ceil
1875+
from math import ceil, floor
18751876
if use_unicode:
18761877
def format_bar(cnt):
18771878
scaled = cnt*width/max_count
@@ -2169,7 +2170,7 @@ def assert_not_a_file(name):
21692170

21702171

21712172
def add_python_path_relative_to_script(rel_path):
2172-
from os.path import dirname, join, abspath
2173+
from os.path import abspath, dirname, join
21732174

21742175
script_name = sys.argv[0]
21752176
rel_script_dir = dirname(script_name)
@@ -2391,8 +2392,9 @@ def download_from_web_if_not_present(url, local_name=None):
23912392
local_name = basename(url)
23922393

23932394
if not exists(local_name):
2394-
from pytools.version import VERSION_TEXT
23952395
from urllib.request import Request, urlopen
2396+
2397+
from pytools.version import VERSION_TEXT
23962398
req = Request(url, headers={
23972399
"User-Agent": f"pytools/{VERSION_TEXT}"
23982400
})
@@ -2412,7 +2414,7 @@ def find_git_revision(tree_root): # pylint: disable=too-many-locals
24122414
# Keep this routine self-contained so that it can be copy-pasted into
24132415
# setup.py.
24142416

2415-
from os.path import join, exists, abspath
2417+
from os.path import abspath, exists, join
24162418
tree_root = abspath(tree_root)
24172419

24182420
if not exists(join(tree_root, ".git")):
@@ -2432,7 +2434,7 @@ def find_git_revision(tree_root): # pylint: disable=too-many-locals
24322434
env["LANG"] = "C"
24332435
env["LC_ALL"] = "C"
24342436

2435-
from subprocess import Popen, PIPE, STDOUT
2437+
from subprocess import PIPE, STDOUT, Popen
24362438
p = Popen(["git", "rev-parse", "HEAD"], shell=False,
24372439
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True,
24382440
cwd=tree_root, env=env)
@@ -2808,8 +2810,8 @@ def unordered_hash(hash_instance, iterable, hash_constructor=None):
28082810
"""
28092811

28102812
if hash_constructor is None:
2811-
from functools import partial
28122813
import hashlib
2814+
from functools import partial
28132815
hash_constructor = partial(hashlib.new, hash_instance.name)
28142816

28152817
h_int = 0

pytools/batchjob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def submit(self, env=(("LD_LIBRARY_PATH", INHERIT), ("PYTHONPATH", INHERIT)),
120120

121121

122122
def guess_job_class():
123-
from subprocess import Popen, PIPE, STDOUT
123+
from subprocess import PIPE, STDOUT, Popen
124124
qstat_helplines = Popen(["qstat", "--help"],
125125
stdout=PIPE, stderr=STDOUT).communicate()[0].split("\n")
126126
if qstat_helplines[0].startswith("GE"):

pytools/convergence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import numbers
12
from typing import List, Optional, Tuple
23

34
import numpy as np
4-
import numbers
55

66

77
# {{{ eoc estimation --------------------------------------------------------------

pytools/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def make_unique_filesystem_object(stem, extension="", directory="",
1111
:param extension: needs a leading dot.
1212
:param directory: must not have a trailing slash.
1313
"""
14-
from os.path import join
1514
import os
15+
from os.path import join
1616

1717
if creator is None:
1818
def default_creator(name):

pytools/graph.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
34
__copyright__ = """
45
Copyright (C) 2009-2013 Andreas Kloeckner
56
Copyright (C) 2020 Matt Wala
@@ -63,9 +64,9 @@
6364
is included as a key in the graph.
6465
"""
6566

66-
from typing import (Collection, Mapping, List, Optional, Any,
67-
Callable, Set, MutableSet, Dict, Iterator, Tuple,
68-
Hashable, TypeVar)
67+
from typing import (Any, Callable, Collection, Dict, Hashable, Iterator, List,
68+
Mapping, MutableSet, Optional, Set, Tuple, TypeVar)
69+
6970

7071
try:
7172
from typing import TypeAlias

pytools/graphviz.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
.. autofunction:: show_dot
3232
"""
3333

34-
from typing import Optional
35-
3634
import html
3735
import logging
36+
from typing import Optional
37+
38+
3839
logger = logging.getLogger(__name__)
3940

4041

@@ -76,8 +77,8 @@ def show_dot(dot_code: str, output_to: Optional[str] = None) -> Optional[str]:
7677
generated SVG file, otherwise returns ``None``.
7778
"""
7879

79-
from tempfile import mkdtemp
8080
import subprocess
81+
from tempfile import mkdtemp
8182
temp_dir = mkdtemp(prefix="tmp_pytools_dot")
8283

8384
dot_file_name = "code.dot"

pytools/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from warnings import warn
22

3+
34
warn("pytools.log was moved to https://github.com/illinois-ceesd/logpyle/. "
45
"I will try to import that for you. If the import fails, say "
56
"'pip install logpyle', and change your imports from 'pytools.log' "

pytools/mpi.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
.. autofunction:: pytest_raises_on_rank
3333
"""
3434

35-
from contextlib import contextmanager, AbstractContextManager
36-
from typing import Generator, Tuple, Union, Type
35+
from contextlib import AbstractContextManager, contextmanager
36+
from typing import Generator, Tuple, Type, Union
3737

3838

3939
def check_for_mpi_relaunch(argv):
@@ -52,8 +52,8 @@ def run_with_mpi_ranks(py_script, ranks, callable_, args=(), kwargs=None):
5252
if kwargs is None:
5353
kwargs = {}
5454

55-
import sys
5655
import os
56+
import sys
5757
newenv = os.environ.copy()
5858
newenv["PYTOOLS_RUN_WITHIN_MPI"] = "1"
5959

@@ -74,9 +74,10 @@ def pytest_raises_on_rank(my_rank: int, fail_rank: int,
7474
"""
7575
Like :func:`pytest.raises`, but only expect an exception on rank *fail_rank*.
7676
"""
77-
import pytest
7877
from contextlib import nullcontext
7978

79+
import pytest
80+
8081
if my_rank == fail_rank:
8182
cm: AbstractContextManager = pytest.raises(expected_exception)
8283
else:

pytools/mpiwrap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"""See pytools.prefork for this module's reason for being."""
22

33
import mpi4py.rc # pylint:disable=import-error
4+
5+
46
mpi4py.rc.initialize = False
57

68
from mpi4py.MPI import * # noqa pylint:disable=wildcard-import,wrong-import-position
79

810
import pytools.prefork # pylint:disable=wrong-import-position
11+
12+
913
pytools.prefork.enable_prefork()
1014

1115

pytools/obj_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
THE SOFTWARE.
2121
"""
2222

23-
import numpy as np
2423
from functools import partial, update_wrapper
2524
from warnings import warn
2625

26+
import numpy as np
27+
2728

2829
__doc__ = """
2930
Handling :mod:`numpy` Object Arrays

0 commit comments

Comments
 (0)