Skip to content

Commit 9df2f1f

Browse files
authored
maint(precommit): Apply isort (#3195)
* Apply isort * Tweak isort config * Add env.py as a known_first_party * Add one missing known first party * Make config compat with older isort versions * Add another comment * Revert pyproject setting
1 parent d6841f6 commit 9df2f1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+72
-66
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ repos:
3535
hooks:
3636
- id: pyupgrade
3737

38+
- repo: https://github.com/PyCQA/isort
39+
rev: 5.9.3
40+
hooks:
41+
- id: isort
42+
3843
# Black, the code formatter, natively supports pre-commit
3944
- repo: https://github.com/psf/black
4045
rev: 21.7b0

docs/benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
import random
2+
import datetime as dt
33
import os
4+
import random
45
import time
5-
import datetime as dt
66

77
nfns = 4 # Functions per class
88
nargs = 4 # Arguments per function

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
# All configuration values have a default; values that are commented out
1414
# serve to show the default.
1515

16-
import sys
1716
import os
17+
import re
1818
import shlex
1919
import subprocess
20+
import sys
2021
from pathlib import Path
21-
import re
2222

2323
DIR = Path(__file__).parent.resolve()
2424

noxfile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import nox
22

3-
43
nox.options.sessions = ["lint", "tests", "tests_packaging"]
54

65

pybind11/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3-
from ._version import version_info, __version__
4-
from .commands import get_include, get_cmake_dir
5-
3+
from ._version import __version__, version_info
4+
from .commands import get_cmake_dir, get_include
65

76
__all__ = (
87
"version_info",

pybind11/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import sysconfig
77

8-
from .commands import get_include, get_cmake_dir
8+
from .commands import get_cmake_dir, get_include
99

1010

1111
def print_includes():

pybind11/_version.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union, Tuple
1+
from typing import Tuple, Union
22

33
def _to_int(s: str) -> Union[int, str]: ...
44

pybind11/commands.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import os
33

4-
54
DIR = os.path.abspath(os.path.dirname(__file__))
65

76

pybind11/setup_helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@
4141

4242
import contextlib
4343
import os
44+
import platform
4445
import shutil
4546
import sys
47+
import sysconfig
4648
import tempfile
4749
import threading
48-
import platform
4950
import warnings
50-
import sysconfig
5151

5252
try:
53-
from setuptools.command.build_ext import build_ext as _build_ext
5453
from setuptools import Extension as _Extension
54+
from setuptools.command.build_ext import build_ext as _build_ext
5555
except ImportError:
5656
from distutils.command.build_ext import build_ext as _build_ext
5757
from distutils.extension import Extension as _Extension
5858

59-
import distutils.errors
6059
import distutils.ccompiler
60+
import distutils.errors
6161

6262
WIN = sys.platform.startswith("win32") and "mingw" not in sysconfig.get_platform()
6363
PY2 = sys.version_info[0] < 3

pybind11/setup_helpers.pyi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# IMPORTANT: Should stay in sync with setup_helpers.py (mostly checked by CI /
22
# pre-commit).
33

4-
from typing import Any, Callable, Dict, Iterator, List, Optional, Type, TypeVar, Union
5-
from types import TracebackType
6-
4+
import contextlib
5+
import distutils.ccompiler
76
from distutils.command.build_ext import build_ext as _build_ext # type: ignore
87
from distutils.extension import Extension as _Extension
9-
import distutils.ccompiler
10-
import contextlib
8+
from types import TracebackType
9+
from typing import Any, Callable, Dict, Iterator, List, Optional, Type, TypeVar, Union
1110

1211
WIN: bool
1312
PY2: bool

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ ignore = [
1515
"noxfile.py",
1616
]
1717

18+
[tool.isort]
19+
# Needs the compiled .so modules and env.py from tests
20+
known_first_party = "env,pybind11_cross_module_tests,pybind11_tests,"
21+
# For black compatibility
22+
profile = "black"
23+
1824
[tool.mypy]
1925
files = "pybind11"
2026
python_version = "2.7"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
# Setup script for PyPI; use CMakeFile.txt to build extension modules
55

66
import contextlib
7+
import io
78
import os
89
import re
910
import shutil
1011
import string
1112
import subprocess
1213
import sys
1314
import tempfile
14-
import io
1515

1616
import setuptools.command.sdist
1717

tests/extra_setuptools/test_setuphelper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import os
3-
import sys
43
import subprocess
4+
import sys
55
from textwrap import dedent
66

77
import pytest

tests/test_buffers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# -*- coding: utf-8 -*-
2+
import ctypes
23
import io
34
import struct
4-
import ctypes
55

66
import pytest
77

88
import env # noqa: F401
9-
10-
from pybind11_tests import buffers as m
119
from pybind11_tests import ConstructorStats
10+
from pybind11_tests import buffers as m
1211

1312
np = pytest.importorskip("numpy")
1413

tests/test_builtin_casters.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import pytest
33

44
import env # noqa: F401
5-
5+
from pybind11_tests import IncType, UserType
66
from pybind11_tests import builtin_casters as m
7-
from pybind11_tests import UserType, IncType
87

98

109
def test_simple_string():

tests/test_call_policies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import pytest
33

44
import env # noqa: F401
5-
6-
from pybind11_tests import call_policies as m
75
from pybind11_tests import ConstructorStats
6+
from pybind11_tests import call_policies as m
87

98

109
@pytest.mark.xfail("env.PYPY", reason="sometimes comes out 1 off on PyPy", strict=False)

tests/test_callbacks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# -*- coding: utf-8 -*-
2-
import pytest
3-
from pybind11_tests import callbacks as m
4-
from threading import Thread
52
import time
3+
from threading import Thread
4+
5+
import pytest
6+
67
import env # NOQA: F401
8+
from pybind11_tests import callbacks as m
79

810

911
def test_callbacks():

tests/test_chrono.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
from pybind11_tests import chrono as m
32
import datetime
3+
44
import pytest
55

66
import env # noqa: F401
7+
from pybind11_tests import chrono as m
78

89

910
def test_chrono_system_clock():

tests/test_class.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import pytest
33

44
import env # noqa: F401
5-
5+
from pybind11_tests import ConstructorStats, UserType
66
from pybind11_tests import class_ as m
7-
from pybind11_tests import UserType, ConstructorStats
87

98

109
def test_repr():

tests/test_cmake_build/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import sys
3+
34
import test_cmake_build
45

56
assert test_cmake_build.add(1, 2) == 3

tests/test_copy_move.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import pytest
3+
34
from pybind11_tests import copy_move_policies as m
45

56

tests/test_custom_type_casters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import pytest
3+
34
from pybind11_tests import custom_type_casters as m
45

56

tests/test_eigen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import pytest
3+
34
from pybind11_tests import ConstructorStats
45

56
np = pytest.importorskip("numpy")

tests/test_enum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import pytest
3+
34
from pybind11_tests import enums as m
45

56

tests/test_eval.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
import env # noqa: F401
7-
87
from pybind11_tests import eval_ as m
98

109

tests/test_exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import pytest
55

66
import env # noqa: F401
7-
8-
from pybind11_tests import exceptions as m
97
import pybind11_cross_module_tests as cm
8+
from pybind11_tests import exceptions as m
109

1110

1211
def test_std_exception(msg):

tests/test_factory_constructors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# -*- coding: utf-8 -*-
2-
import pytest
32
import re
43

5-
import env # noqa: F401
4+
import pytest
65

6+
import env # noqa: F401
7+
from pybind11_tests import ConstructorStats
78
from pybind11_tests import factory_constructors as m
89
from pybind11_tests.factory_constructors import tag
9-
from pybind11_tests import ConstructorStats
1010

1111

1212
def test_init_factory_basic():

tests/test_iostream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
2-
from pybind11_tests import iostream as m
32
import sys
4-
53
from contextlib import contextmanager
64

5+
from pybind11_tests import iostream as m
6+
77
try:
88
# Python 3
99
from io import StringIO

tests/test_kwargs_and_defaults.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import pytest
33

44
import env # noqa: F401
5-
65
from pybind11_tests import kwargs_and_defaults as m
76

87

tests/test_local_bindings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import pytest
33

44
import env # noqa: F401
5-
65
from pybind11_tests import local_bindings as m
76

87

tests/test_methods_and_attributes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import pytest
33

44
import env # noqa: F401
5-
6-
from pybind11_tests import methods_and_attributes as m
75
from pybind11_tests import ConstructorStats
6+
from pybind11_tests import methods_and_attributes as m
87

98

109
def test_methods_and_attributes():

tests/test_modules.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2+
from pybind11_tests import ConstructorStats
23
from pybind11_tests import modules as m
34
from pybind11_tests.modules import subsubmodule as ms
4-
from pybind11_tests import ConstructorStats
55

66

77
def test_nested_modules():
@@ -54,18 +54,20 @@ def test_reference_internal():
5454

5555

5656
def test_importing():
57-
from pybind11_tests.modules import OD
5857
from collections import OrderedDict
5958

59+
from pybind11_tests.modules import OD
60+
6061
assert OD is OrderedDict
6162
assert str(OD([(1, "a"), (2, "b")])) == "OrderedDict([(1, 'a'), (2, 'b')])"
6263

6364

6465
def test_pydoc():
6566
"""Pydoc needs to be able to provide help() for everything inside a pybind11 module"""
66-
import pybind11_tests
6767
import pydoc
6868

69+
import pybind11_tests
70+
6971
assert pybind11_tests.__name__ == "pybind11_tests"
7072
assert pybind11_tests.__doc__ == "pybind11 test module"
7173
assert pydoc.text.docmodule(pybind11_tests)

tests/test_multiple_inheritance.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import pytest
33

44
import env # noqa: F401
5-
65
from pybind11_tests import ConstructorStats
76
from pybind11_tests import multiple_inheritance as m
87

tests/test_numpy_array.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import pytest
33

44
import env # noqa: F401
5-
65
from pybind11_tests import numpy_array as m
76

87
np = pytest.importorskip("numpy")

0 commit comments

Comments
 (0)