Skip to content

Commit

Permalink
maint(precommit): Apply isort (#3195)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Skylion007 authored Aug 13, 2021
1 parent d6841f6 commit 9df2f1f
Show file tree
Hide file tree
Showing 45 changed files with 72 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ repos:
hooks:
- id: pyupgrade

- repo: https://github.com/PyCQA/isort
rev: 5.9.3
hooks:
- id: isort

# Black, the code formatter, natively supports pre-commit
- repo: https://github.com/psf/black
rev: 21.7b0
Expand Down
4 changes: 2 additions & 2 deletions docs/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import random
import datetime as dt
import os
import random
import time
import datetime as dt

nfns = 4 # Functions per class
nargs = 4 # Arguments per function
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import re
import shlex
import subprocess
import sys
from pathlib import Path
import re

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

Expand Down
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import nox


nox.options.sessions = ["lint", "tests", "tests_packaging"]


Expand Down
5 changes: 2 additions & 3 deletions pybind11/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-

from ._version import version_info, __version__
from .commands import get_include, get_cmake_dir

from ._version import __version__, version_info
from .commands import get_cmake_dir, get_include

__all__ = (
"version_info",
Expand Down
2 changes: 1 addition & 1 deletion pybind11/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import sysconfig

from .commands import get_include, get_cmake_dir
from .commands import get_cmake_dir, get_include


def print_includes():
Expand Down
2 changes: 1 addition & 1 deletion pybind11/_version.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Tuple
from typing import Tuple, Union

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

Expand Down
1 change: 0 additions & 1 deletion pybind11/commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import os


DIR = os.path.abspath(os.path.dirname(__file__))


Expand Down
8 changes: 4 additions & 4 deletions pybind11/setup_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@

import contextlib
import os
import platform
import shutil
import sys
import sysconfig
import tempfile
import threading
import platform
import warnings
import sysconfig

try:
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools import Extension as _Extension
from setuptools.command.build_ext import build_ext as _build_ext
except ImportError:
from distutils.command.build_ext import build_ext as _build_ext
from distutils.extension import Extension as _Extension

import distutils.errors
import distutils.ccompiler
import distutils.errors

WIN = sys.platform.startswith("win32") and "mingw" not in sysconfig.get_platform()
PY2 = sys.version_info[0] < 3
Expand Down
9 changes: 4 additions & 5 deletions pybind11/setup_helpers.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# IMPORTANT: Should stay in sync with setup_helpers.py (mostly checked by CI /
# pre-commit).

from typing import Any, Callable, Dict, Iterator, List, Optional, Type, TypeVar, Union
from types import TracebackType

import contextlib
import distutils.ccompiler
from distutils.command.build_ext import build_ext as _build_ext # type: ignore
from distutils.extension import Extension as _Extension
import distutils.ccompiler
import contextlib
from types import TracebackType
from typing import Any, Callable, Dict, Iterator, List, Optional, Type, TypeVar, Union

WIN: bool
PY2: bool
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ ignore = [
"noxfile.py",
]

[tool.isort]
# Needs the compiled .so modules and env.py from tests
known_first_party = "env,pybind11_cross_module_tests,pybind11_tests,"
# For black compatibility
profile = "black"

[tool.mypy]
files = "pybind11"
python_version = "2.7"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# Setup script for PyPI; use CMakeFile.txt to build extension modules

import contextlib
import io
import os
import re
import shutil
import string
import subprocess
import sys
import tempfile
import io

import setuptools.command.sdist

Expand Down
2 changes: 1 addition & 1 deletion tests/extra_setuptools/test_setuphelper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import os
import sys
import subprocess
import sys
from textwrap import dedent

import pytest
Expand Down
5 changes: 2 additions & 3 deletions tests/test_buffers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-
import ctypes
import io
import struct
import ctypes

import pytest

import env # noqa: F401

from pybind11_tests import buffers as m
from pybind11_tests import ConstructorStats
from pybind11_tests import buffers as m

np = pytest.importorskip("numpy")

Expand Down
3 changes: 1 addition & 2 deletions tests/test_builtin_casters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import pytest

import env # noqa: F401

from pybind11_tests import IncType, UserType
from pybind11_tests import builtin_casters as m
from pybind11_tests import UserType, IncType


def test_simple_string():
Expand Down
3 changes: 1 addition & 2 deletions tests/test_call_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import pytest

import env # noqa: F401

from pybind11_tests import call_policies as m
from pybind11_tests import ConstructorStats
from pybind11_tests import call_policies as m


@pytest.mark.xfail("env.PYPY", reason="sometimes comes out 1 off on PyPy", strict=False)
Expand Down
8 changes: 5 additions & 3 deletions tests/test_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
import pytest
from pybind11_tests import callbacks as m
from threading import Thread
import time
from threading import Thread

import pytest

import env # NOQA: F401
from pybind11_tests import callbacks as m


def test_callbacks():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_chrono.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
from pybind11_tests import chrono as m
import datetime

import pytest

import env # noqa: F401
from pybind11_tests import chrono as m


def test_chrono_system_clock():
Expand Down
3 changes: 1 addition & 2 deletions tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import pytest

import env # noqa: F401

from pybind11_tests import ConstructorStats, UserType
from pybind11_tests import class_ as m
from pybind11_tests import UserType, ConstructorStats


def test_repr():
Expand Down
1 change: 1 addition & 0 deletions tests/test_cmake_build/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys

import test_cmake_build

assert test_cmake_build.add(1, 2) == 3
Expand Down
1 change: 1 addition & 0 deletions tests/test_copy_move.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import copy_move_policies as m


Expand Down
1 change: 1 addition & 0 deletions tests/test_custom_type_casters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import custom_type_casters as m


Expand Down
1 change: 1 addition & 0 deletions tests/test_eigen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import ConstructorStats

np = pytest.importorskip("numpy")
Expand Down
1 change: 1 addition & 0 deletions tests/test_enum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import enums as m


Expand Down
1 change: 0 additions & 1 deletion tests/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest

import env # noqa: F401

from pybind11_tests import eval_ as m


Expand Down
3 changes: 1 addition & 2 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import pytest

import env # noqa: F401

from pybind11_tests import exceptions as m
import pybind11_cross_module_tests as cm
from pybind11_tests import exceptions as m


def test_std_exception(msg):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_factory_constructors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
import pytest
import re

import env # noqa: F401
import pytest

import env # noqa: F401
from pybind11_tests import ConstructorStats
from pybind11_tests import factory_constructors as m
from pybind11_tests.factory_constructors import tag
from pybind11_tests import ConstructorStats


def test_init_factory_basic():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_iostream.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from pybind11_tests import iostream as m
import sys

from contextlib import contextmanager

from pybind11_tests import iostream as m

try:
# Python 3
from io import StringIO
Expand Down
1 change: 0 additions & 1 deletion tests/test_kwargs_and_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest

import env # noqa: F401

from pybind11_tests import kwargs_and_defaults as m


Expand Down
1 change: 0 additions & 1 deletion tests/test_local_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest

import env # noqa: F401

from pybind11_tests import local_bindings as m


Expand Down
3 changes: 1 addition & 2 deletions tests/test_methods_and_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import pytest

import env # noqa: F401

from pybind11_tests import methods_and_attributes as m
from pybind11_tests import ConstructorStats
from pybind11_tests import methods_and_attributes as m


def test_methods_and_attributes():
Expand Down
8 changes: 5 additions & 3 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pybind11_tests import ConstructorStats
from pybind11_tests import modules as m
from pybind11_tests.modules import subsubmodule as ms
from pybind11_tests import ConstructorStats


def test_nested_modules():
Expand Down Expand Up @@ -54,18 +54,20 @@ def test_reference_internal():


def test_importing():
from pybind11_tests.modules import OD
from collections import OrderedDict

from pybind11_tests.modules import OD

assert OD is OrderedDict
assert str(OD([(1, "a"), (2, "b")])) == "OrderedDict([(1, 'a'), (2, 'b')])"


def test_pydoc():
"""Pydoc needs to be able to provide help() for everything inside a pybind11 module"""
import pybind11_tests
import pydoc

import pybind11_tests

assert pybind11_tests.__name__ == "pybind11_tests"
assert pybind11_tests.__doc__ == "pybind11 test module"
assert pydoc.text.docmodule(pybind11_tests)
Expand Down
1 change: 0 additions & 1 deletion tests/test_multiple_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest

import env # noqa: F401

from pybind11_tests import ConstructorStats
from pybind11_tests import multiple_inheritance as m

Expand Down
1 change: 0 additions & 1 deletion tests/test_numpy_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest

import env # noqa: F401

from pybind11_tests import numpy_array as m

np = pytest.importorskip("numpy")
Expand Down
Loading

0 comments on commit 9df2f1f

Please sign in to comment.