From 0b3b3ef4dfc5028ea656227f5f8630a9c1272412 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 4 May 2025 13:22:36 +0200 Subject: [PATCH] chore: sort all imports using `isort` + check in CI https://pycqa.github.io/isort/ --- .github/workflows/isort.yml | 23 +++++++++++++++++++++++ Makefile | 6 ++++++ pydifact/__init__.py | 2 +- pydifact/parser.py | 6 +++--- pydifact/segmentcollection.py | 3 +-- pydifact/segments.py | 6 +++--- pydifact/serializer.py | 2 +- pydifact/syntax/common.py | 2 +- pydifact/syntax/v1/__init__.py | 8 ++++---- pydifact/syntax/v4/__init__.py | 5 +++-- pydifact/tokenizer.py | 2 +- pyproject.toml | 8 ++++++-- tests/messagetypes/paxlst/test_una.py | 1 + tests/test_characters.py | 1 + tests/test_parser.py | 5 +++-- tests/test_sage_coala.py | 2 +- tests/test_segment.py | 1 - tests/test_serializer.py | 3 ++- tests/test_syntax_v1.py | 4 ++-- tests/test_tokenizer.py | 3 +-- 20 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/isort.yml diff --git a/.github/workflows/isort.yml b/.github/workflows/isort.yml new file mode 100644 index 0000000..f5666dc --- /dev/null +++ b/.github/workflows/isort.yml @@ -0,0 +1,23 @@ +name: "isort check" + +on: [push, pull_request] +jobs: + pytest: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ["3.13"] + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dev Dependencies + run: | + python -m pip install --upgrade pip + pip install .[dev] + - name: Check Import Order + run: | + make check-isort diff --git a/Makefile b/Makefile index c27ca0c..d1bfc68 100644 --- a/Makefile +++ b/Makefile @@ -18,3 +18,9 @@ mypy: test-extended: pytest + +run-isort: + isort . + +check-isort: + isort . --check \ No newline at end of file diff --git a/pydifact/__init__.py b/pydifact/__init__.py index 4b87ca9..bc48b2e 100644 --- a/pydifact/__init__.py +++ b/pydifact/__init__.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from pydifact import segmentcollection, parser, segments, serializer, token, tokenizer +from pydifact import parser, segmentcollection, segments, serializer, token, tokenizer __version__ = "0.1.8" diff --git a/pydifact/parser.py b/pydifact/parser.py index 9a38ba6..51f9855 100644 --- a/pydifact/parser.py +++ b/pydifact/parser.py @@ -22,11 +22,11 @@ from collections.abc import Iterator +from pydifact.control import Characters from pydifact.exceptions import EDISyntaxError -from pydifact.tokenizer import Tokenizer -from pydifact.token import Token from pydifact.segments import Element, Elements, Segment, SegmentFactory -from pydifact.control import Characters +from pydifact.token import Token +from pydifact.tokenizer import Tokenizer class Parser: diff --git a/pydifact/segmentcollection.py b/pydifact/segmentcollection.py index 2791678..83a2cad 100644 --- a/pydifact/segmentcollection.py +++ b/pydifact/segmentcollection.py @@ -24,10 +24,9 @@ import datetime from collections.abc import Callable, Iterable, Iterator, Sequence from typing import Type, TypeVar -from collections.abc import Callable, Iterable -from pydifact.exceptions import EDISyntaxError from pydifact.control import Characters +from pydifact.exceptions import EDISyntaxError from pydifact.parser import Parser from pydifact.segments import Element, Elements, Segment from pydifact.serializer import Serializer diff --git a/pydifact/segments.py b/pydifact/segments.py index e027e3f..f3c9ab9 100644 --- a/pydifact/segments.py +++ b/pydifact/segments.py @@ -27,11 +27,11 @@ from pydifact.constants import EDI_DEFAULT_VERSION, M from pydifact.exceptions import ( - ValidationError, - MissingImplementationWarning, EDISyntaxError, + MissingImplementationWarning, + ValidationError, ) -from pydifact.syntax.common import DataElement, CompositeDataElement +from pydifact.syntax.common import CompositeDataElement, DataElement class Segment: diff --git a/pydifact/serializer.py b/pydifact/serializer.py index fc99e9a..f2caddb 100644 --- a/pydifact/serializer.py +++ b/pydifact/serializer.py @@ -19,9 +19,9 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from pydifact.control.characters import Characters import re +from pydifact.control.characters import Characters from pydifact.segments import Segment diff --git a/pydifact/syntax/common.py b/pydifact/syntax/common.py index da92baa..e081493 100644 --- a/pydifact/syntax/common.py +++ b/pydifact/syntax/common.py @@ -12,7 +12,7 @@ import re import warnings -from typing import Optional, Type, TypeAlias, TypeVar, NamedTuple +from typing import NamedTuple, Optional, Type, TypeAlias, TypeVar from pydifact.constants import EDI_DEFAULT_VERSION from pydifact.exceptions import ValidationError diff --git a/pydifact/syntax/v1/__init__.py b/pydifact/syntax/v1/__init__.py index b6e2e5e..6ac7864 100644 --- a/pydifact/syntax/v1/__init__.py +++ b/pydifact/syntax/v1/__init__.py @@ -1,15 +1,15 @@ +from pydifact.constants import C, M +from pydifact.segments import Segment from pydifact.syntax.common import ( - DataElement, CompositeDataElement, + DataElement, SyntaxVersionNumber, ) -from pydifact.constants import M, C -from pydifact.segments import Segment __version__ = 1 -from .data import partner_identification_codes from ... import Characters +from .data import partner_identification_codes class ServiceStringAdvice(DataElement): diff --git a/pydifact/syntax/v4/__init__.py b/pydifact/syntax/v4/__init__.py index 7843a13..041f49b 100644 --- a/pydifact/syntax/v4/__init__.py +++ b/pydifact/syntax/v4/__init__.py @@ -1,12 +1,13 @@ from typing import NamedTuple -from pydifact.constants import M, C +from pydifact.constants import C, M from pydifact.syntax import v1, v2, v3 from pydifact.syntax.common import ( - DataElement, CompositeDataElement, + DataElement, SyntaxVersionNumber, ) + from .data import partner_identification_codes __version__ = 4 diff --git a/pydifact/tokenizer.py b/pydifact/tokenizer.py index 23b7233..420bf56 100644 --- a/pydifact/tokenizer.py +++ b/pydifact/tokenizer.py @@ -21,9 +21,9 @@ # THE SOFTWARE. from collections.abc import Iterator +from pydifact.control.characters import Characters from pydifact.exceptions import EDISyntaxError from pydifact.token import Token -from pydifact.control.characters import Characters class Tokenizer: diff --git a/pyproject.toml b/pyproject.toml index a17a0eb..f46358b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,8 +33,12 @@ dev = [ "sphinx-rtd-theme>=2.0.0", "build", "twine", - "mypy>=1.15.0" - ] + "mypy>=1.15.0", + "isort==6.0.1" +] + +[tool.isort] +profile = "black" [project.urls] Documentation = "https://pydifact.readthedocs.io" diff --git a/tests/messagetypes/paxlst/test_una.py b/tests/messagetypes/paxlst/test_una.py index 2b6a871..fcad7eb 100644 --- a/tests/messagetypes/paxlst/test_una.py +++ b/tests/messagetypes/paxlst/test_una.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . import pytest + from pydifact.control import Characters diff --git a/tests/test_characters.py b/tests/test_characters.py index 86e7d2e..dc38b60 100644 --- a/tests/test_characters.py +++ b/tests/test_characters.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import pytest + from pydifact.control import Characters diff --git a/tests/test_parser.py b/tests/test_parser.py index a22ad66..d90a79f 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -13,11 +13,12 @@ # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +import pytest + +from pydifact.control.characters import Characters from pydifact.exceptions import EDISyntaxError from pydifact.parser import Parser from pydifact.segments import Segment -from pydifact.control.characters import Characters -import pytest # @pytest.fixture # def mocked_tokenizer(mocker): diff --git a/tests/test_sage_coala.py b/tests/test_sage_coala.py index 7dec6ad..91ff933 100644 --- a/tests/test_sage_coala.py +++ b/tests/test_sage_coala.py @@ -14,10 +14,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . import os + from pydifact.segmentcollection import Interchange from pydifact.segments import Segment - path = os.path.dirname(os.path.realpath(__file__)) + "/data" diff --git a/tests/test_segment.py b/tests/test_segment.py index 15d40af..1541781 100644 --- a/tests/test_segment.py +++ b/tests/test_segment.py @@ -17,7 +17,6 @@ from pydifact.segments import Segment - elements = ["field1", ["field2", "extra"], "stuff"] diff --git a/tests/test_serializer.py b/tests/test_serializer.py index b9f8475..1856120 100644 --- a/tests/test_serializer.py +++ b/tests/test_serializer.py @@ -15,9 +15,10 @@ # along with this program. If not, see . import copy import datetime + import pytest -from pydifact.segmentcollection import RawSegmentCollection, Interchange +from pydifact.segmentcollection import Interchange, RawSegmentCollection from pydifact.segments import Segment from pydifact.serializer import Serializer diff --git a/tests/test_syntax_v1.py b/tests/test_syntax_v1.py index 522a064..88e567c 100644 --- a/tests/test_syntax_v1.py +++ b/tests/test_syntax_v1.py @@ -1,8 +1,8 @@ +import pytest + from pydifact import Serializer from pydifact.exceptions import ValidationError from pydifact.segments import Segment -import pytest - from pydifact.syntax.v1 import UNASegment default_characters = ":+,? '" diff --git a/tests/test_tokenizer.py b/tests/test_tokenizer.py index d34c469..15b08f3 100644 --- a/tests/test_tokenizer.py +++ b/tests/test_tokenizer.py @@ -15,12 +15,11 @@ # along with this program. If not, see . import pytest +from pydifact.control import Characters from pydifact.exceptions import EDISyntaxError from pydifact.token import Token from pydifact.tokenizer import Tokenizer -from pydifact.control import Characters - @pytest.fixture def tokenizer() -> Tokenizer: