Skip to content

Commit 5a10920

Browse files
rwemystor
andauthored
lint: use isort to normalize import order (#119)
* doc: fix tox environment names in contributing.rst * lint: use `isort` to normalize import order Note that `pylint` already depends on `isort`. Using it makes import sorting unambiguous and automatic. It's a little ambiguous whether it should be in the "lint" or "format" tox command, or another one altogether. It's included in "lint" here, because pylint already uses isort internally to catch coarse-grained "wrong-import-order" warnings. Co-authored-by: Nika Layzell <[email protected]>
1 parent 0556c78 commit 5a10920

File tree

16 files changed

+73
-71
lines changed

16 files changed

+73
-71
lines changed

.isort.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
profile = black

docs/contributing.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Running Tests
55
-------------
66

77
:command:`tox` is used to run tests. It will run :command:`mypy` for type
8-
checking, :command:`pylint` for linting, :command:`pytest` for testing, and
9-
:command:`black` for code formatting.
8+
checking, :command:`isort` and :command:`pylint` for linting, :command:`pytest`
9+
for testing, and :command:`black` for code formatting.
1010

1111
.. code-block:: shell
1212
@@ -16,16 +16,17 @@ checking, :command:`pylint` for linting, :command:`pytest` for testing, and
1616
$ tox -e py310 # Python 3.10
1717
1818
$ tox -e mypy # Mypy Typechecking
19-
$ tox -e pylint # Linting
20-
$ tox -e black # Check Formatting
19+
$ tox -e lint # Linting
20+
$ tox -e format # Check Formatting
2121
2222
Code Formatting
2323
---------------
2424

25-
This project uses ``black`` for code formatting.
25+
This project uses ``isort`` and ``black`` for code formatting.
2626

2727
.. code-block:: shell
2828
29+
$ isort . # sort imports
2930
$ black . # format all python code
3031
3132
Building Documentation

gitrevise/merge.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212

1313
from __future__ import annotations
1414

15-
from typing import Iterator, Optional, Tuple, TypeVar
16-
from pathlib import Path
17-
from subprocess import CalledProcessError
1815
import hashlib
1916
import os
2017
import sys
18+
from pathlib import Path
19+
from subprocess import CalledProcessError
20+
from typing import Iterator, Optional, Tuple, TypeVar
2121

22-
from .odb import Tree, Blob, Commit, Entry, Mode, Repository
22+
from .odb import Blob, Commit, Entry, Mode, Repository, Tree
2323
from .utils import edit_file
2424

25-
2625
T = TypeVar("T") # pylint: disable=invalid-name
2726

2827

gitrevise/odb.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,28 @@
55
from __future__ import annotations
66

77
import hashlib
8-
import re
98
import os
9+
import re
10+
import sys
11+
from collections import defaultdict
12+
from enum import Enum
13+
from pathlib import Path
14+
from subprocess import DEVNULL, PIPE, CalledProcessError, Popen, run
15+
from tempfile import TemporaryDirectory
16+
from types import TracebackType
1017
from typing import (
1118
TYPE_CHECKING,
12-
TypeVar,
13-
Type,
1419
Dict,
15-
Union,
16-
Sequence,
17-
Optional,
18-
Mapping,
1920
Generic,
21+
Mapping,
22+
Optional,
23+
Sequence,
2024
Tuple,
25+
Type,
26+
TypeVar,
27+
Union,
2128
cast,
2229
)
23-
import sys
24-
from types import TracebackType
25-
from pathlib import Path
26-
from enum import Enum
27-
from subprocess import DEVNULL, Popen, run, PIPE, CalledProcessError
28-
from collections import defaultdict
29-
from tempfile import TemporaryDirectory
30-
3130

3231
if TYPE_CHECKING:
3332
from subprocess import _FILE

gitrevise/todo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from enum import Enum
55
from typing import List, Optional
66

7-
from .odb import Commit, Repository, MissingObject
8-
from .utils import run_editor, run_sequence_editor, edit_commit_message, cut_commit
7+
from .odb import Commit, MissingObject, Repository
8+
from .utils import cut_commit, edit_commit_message, run_editor, run_sequence_editor
99

1010

1111
class StepKind(Enum):

gitrevise/tui.py

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

3-
from typing import Optional, List
3+
import sys
44
from argparse import ArgumentParser, Namespace
55
from subprocess import CalledProcessError
6-
import sys
6+
from typing import List, Optional
77

8-
from .odb import Repository, Commit, Reference
8+
from . import __version__
9+
from .merge import MergeConflict
10+
from .odb import Commit, Reference, Repository
11+
from .todo import apply_todos, autosquash_todos, build_todos, edit_todos
912
from .utils import (
1013
EditorError,
1114
commit_range,
12-
edit_commit_message,
13-
update_head,
1415
cut_commit,
16+
edit_commit_message,
1517
local_commits,
18+
update_head,
1619
)
17-
from .todo import apply_todos, build_todos, edit_todos, autosquash_todos
18-
from .merge import MergeConflict
19-
from . import __version__
2020

2121

2222
def build_parser() -> ArgumentParser:

gitrevise/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from __future__ import annotations
22

3-
from typing import Any, List, Optional, Sequence, Tuple, TYPE_CHECKING
4-
from subprocess import run, CalledProcessError
5-
from pathlib import Path
6-
import textwrap
7-
import sys
83
import os
94
import re
5+
import sys
6+
import textwrap
7+
from pathlib import Path
8+
from subprocess import CalledProcessError, run
9+
from typing import TYPE_CHECKING, Any, List, Optional, Sequence, Tuple
1010

11-
from .odb import Repository, Commit, Tree, Oid, Reference
12-
11+
from .odb import Commit, Oid, Reference, Repository, Tree
1312

1413
if TYPE_CHECKING:
1514
from subprocess import CompletedProcess

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
23
from setuptools import setup
34

45
import gitrevise

tests/conftest.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import tempfile
66
import textwrap
77
import traceback
8-
98
from concurrent.futures import CancelledError, Future
109
from concurrent.futures.thread import ThreadPoolExecutor
1110
from contextlib import contextmanager
@@ -14,26 +13,20 @@
1413
from queue import Empty, Queue
1514
from threading import Thread
1615
from types import TracebackType
17-
from typing import (
18-
Generator,
19-
Optional,
20-
Sequence,
21-
Type,
22-
Union,
23-
TYPE_CHECKING,
24-
)
16+
from typing import TYPE_CHECKING, Generator, Optional, Sequence, Type, Union
2517

2618
import pytest
2719

2820
from gitrevise.odb import Repository
2921
from gitrevise.utils import sh_path
30-
from . import dummy_editor
3122

23+
from . import dummy_editor
3224

3325
if TYPE_CHECKING:
34-
from _typeshed import StrPath
3526
from typing import Any, Tuple
3627

28+
from _typeshed import StrPath
29+
3730

3831
@pytest.fixture(name="hermetic_seal", autouse=True)
3932
def fixture_hermetic_seal(

tests/test_cut.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from gitrevise.odb import Repository
2+
23
from .conftest import bash, editor_main
34

45

0 commit comments

Comments
 (0)