Skip to content

Commit 1b98081

Browse files
committed
isort
1 parent c1ac304 commit 1b98081

28 files changed

+90
-56
lines changed

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SHELL=/bin/bash -e
22

33
help:
44
@echo - make black ------ Format code
5+
@echo - make isort ------ Sort imports
56
@echo - make clean ------ Clean virtual environment
67
@echo - make coverage --- Run tests coverage
78
@echo - make docs ------- Make docs
@@ -11,8 +12,13 @@ help:
1112
@echo - make typecheck -- Typecheck
1213
@echo - make venv ------- Create virtual environment
1314

14-
black:
15-
black -S cstruct tests examples setup.py
15+
.PHONY: isort
16+
isort:
17+
@isort --profile black cstruct tests examples setup.py
18+
19+
.PHONY: black
20+
black: isort
21+
@black -S cstruct tests examples setup.py
1622

1723
clean:
1824
-rm -rf build dist

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ C-style structs for Python
88
[![PyPI](https://img.shields.io/pypi/pyversions/cstruct.svg)](https://pypi.org/project/cstruct)
99
[![Downloads](https://pepy.tech/badge/cstruct/month)](https://pepy.tech/project/cstruct)
1010
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
11+
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
1112
[![Known Vulnerabilities](https://snyk.io/test/github/andreax79/python-cstruct/badge.svg)](https://snyk.io/test/github/andreax79/python-cstruct)
1213
[![Documentation](https://readthedocs.org/projects/python-cstruct/badge/?version=latest)](https://python-cstruct.readthedocs.io/en/latest/)
1314

cstruct/__init__.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@
2828
__date__ = "15 August 2013"
2929

3030
from typing import Any, Dict, Optional, Type, Union
31+
32+
from .abstract import AbstractCEnum, AbstractCStruct, CStructMeta
3133
from .base import (
32-
LITTLE_ENDIAN,
3334
BIG_ENDIAN,
35+
CHAR_ZERO,
36+
DEFINES,
37+
ENUMS,
38+
LITTLE_ENDIAN,
3439
NATIVE_ORDER,
3540
STRUCTS,
36-
ENUMS,
37-
DEFINES,
3841
TYPEDEFS,
39-
CHAR_ZERO,
4042
)
41-
from .abstract import CStructMeta, AbstractCStruct, AbstractCEnum
42-
from .cstruct import CStruct
4343
from .c_parser import parse_struct_def
44-
from .mem_cstruct import MemCStruct
4544
from .cenum import CEnum
45+
from .cstruct import CStruct
46+
from .mem_cstruct import MemCStruct
4647
from .native_types import get_native_type
4748

4849
__all__ = [

cstruct/abstract.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@
2424
# IN THE SOFTWARE.
2525
#
2626

27+
import hashlib
28+
import struct
2729
from abc import ABCMeta
2830
from collections import OrderedDict
29-
from typing import Any, BinaryIO, List, Dict, Optional, Type, Tuple, Union
30-
import hashlib
31+
from enum import EnumMeta, IntEnum, _EnumDict
3132
from io import StringIO
32-
from enum import IntEnum, EnumMeta, _EnumDict
33-
import struct
34-
from .base import STRUCTS, ENUMS, DEFAULT_ENUM_SIZE, ENUM_SIZE_TO_C_TYPE
35-
from .c_parser import parse_struct, parse_struct_def, parse_enum_def, parse_enum, Tokens
36-
from .field import calculate_padding, FieldType
37-
from .native_types import get_native_type
33+
from typing import Any, BinaryIO, Dict, List, Optional, Tuple, Type, Union
34+
35+
from .base import DEFAULT_ENUM_SIZE, ENUM_SIZE_TO_C_TYPE, ENUMS, STRUCTS
36+
from .c_parser import Tokens, parse_enum, parse_enum_def, parse_struct, parse_struct_def
3837
from .exceptions import CStructException, ParserError
38+
from .field import FieldType, calculate_padding
39+
from .native_types import get_native_type
3940

4041
__all__ = ["CStructMeta", "AbstractCStruct", "CEnumMeta", "AbstractCEnum"]
4142

cstruct/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
# IN THE SOFTWARE.
2323
#
2424

25-
from typing import Any, Dict, Type, TYPE_CHECKING
25+
from typing import TYPE_CHECKING, Any, Dict, Type
2626

2727
if TYPE_CHECKING:
28-
from .abstract import AbstractCStruct, AbstractCEnum
28+
from .abstract import AbstractCEnum, AbstractCStruct
2929

3030
__all__ = [
3131
"LITTLE_ENDIAN",

cstruct/c_expr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
import ast
2626
import operator
27-
from typing import Any, Callable, Dict, Union, Type, TYPE_CHECKING
27+
from typing import TYPE_CHECKING, Any, Callable, Dict, Type, Union
28+
2829
from .base import DEFINES, STRUCTS
2930
from .exceptions import EvalError
3031

cstruct/c_parser.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424

2525
import re
2626
from collections import OrderedDict
27-
from typing import Union, Optional, Any, Dict, List, Type, TYPE_CHECKING
28-
from .base import DEFINES, ENUMS, TYPEDEFS, STRUCTS
29-
from .field import calculate_padding, Kind, FieldType
27+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, Union
28+
29+
from .base import DEFINES, ENUMS, STRUCTS, TYPEDEFS
3030
from .c_expr import c_eval
3131
from .exceptions import CStructException, ParserError
32+
from .field import FieldType, Kind, calculate_padding
3233
from .native_types import get_native_type
3334

3435
if TYPE_CHECKING:
35-
from .abstract import AbstractCStruct, AbstractCEnum
36+
from .abstract import AbstractCEnum, AbstractCStruct
3637

3738
__all__ = ["parse_struct", "parse_struct_def", "parse_enum_def", "Tokens"]
3839

cstruct/cstruct.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#
2424

2525
from typing import List, Optional
26-
from .base import CHAR_ZERO
26+
2727
from .abstract import AbstractCStruct
28+
from .base import CHAR_ZERO
2829

2930

3031
class CStruct(AbstractCStruct):

cstruct/field.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
import copy
2626
import struct
2727
from enum import Enum
28-
from typing import Optional, Any, List, Type, TYPE_CHECKING
28+
from typing import TYPE_CHECKING, Any, List, Optional, Type
29+
2930
from .base import NATIVE_ORDER
30-
from .native_types import get_native_type
3131
from .exceptions import ParserError
32+
from .native_types import get_native_type
3233

3334
if TYPE_CHECKING:
3435
from .abstract import AbstractCStruct

cstruct/mem_cstruct.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
# IN THE SOFTWARE.
2323
#
2424

25-
from typing import Any, List, Optional
2625
import ctypes
2726
import struct
27+
from typing import Any, List, Optional
28+
2829
from .abstract import AbstractCStruct
2930

3031

cstruct/native_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import struct
2626
from abc import ABCMeta
27-
from typing import Any, Dict, Type, Tuple
27+
from typing import Any, Dict, Tuple, Type
2828

2929
__all__ = [
3030
"get_native_type",

examples/dir.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python
2-
import cstruct
32
import ctypes
43
import sys
54

5+
import cstruct
6+
67
libc = ctypes.cdll.LoadLibrary("libc.so.6")
78
# opendir
89
libc.opendir.argtypes = [ctypes.c_char_p]

examples/fdisk.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python
22

3-
from pathlib import Path
43
import argparse
5-
import cstruct
64
import sys
5+
from pathlib import Path
6+
7+
import cstruct
78

89
UNITS = ['B', 'K', 'M', 'G', 'T']
910
SECTOR_SIZE = 512

examples/flexible_array.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python
22

33
import random
4-
from cstruct import MemCStruct
54
from pathlib import Path
65

6+
from cstruct import MemCStruct
7+
78

89
class FlexArray(MemCStruct):
910
__def__ = """

examples/who.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22

3-
from cstruct import parse, getdef, MemCStruct, NATIVE_ORDER
4-
from pathlib import Path
53
import argparse
64
import sys
75
import time
6+
from pathlib import Path
7+
8+
from cstruct import NATIVE_ORDER, MemCStruct, getdef, parse
89

910
DEFAULT_FILENAME = "/var/run/utmp"
1011

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ source = ["cstruct"]
1010

1111
[tool.coverage.report]
1212
exclude_lines = [ "# pragma: no cover", "if TYPE_CHECKING:" ]
13+
14+
[tool.isort]
15+
profile = "black"

requirements-dev.txt

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
black
2+
build
13
coverage[toml]
2-
pytest-cov
34
flake8
4-
mypy
5-
tox
6-
black
7-
twine<3.4
8-
pytest
5+
isort
6+
markdown_include
97
mkdocs
10-
mkdocstrings[python]
118
mkdocs-material
12-
markdown_include
13-
build
9+
mkdocstrings[python]
10+
mypy
11+
pytest
12+
pytest-cov
1413
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
14+
tox
15+
twine<3.4

tests/test_alignment.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
# *****************************************************************************
2727

2828
import sys
29-
from cstruct import sizeof, typedef, define, CStruct, NATIVE_ORDER
29+
30+
from cstruct import NATIVE_ORDER, CStruct, define, sizeof, typedef
3031

3132
IS_64BITS = sys.maxsize > 2**32
3233

tests/test_c_expr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#
2626
# *****************************************************************************
2727

28-
from cstruct import parse, getdef, define
28+
from cstruct import define, getdef, parse
2929
from cstruct.c_expr import c_eval
3030

3131

tests/test_cenum.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from enum import Enum
2+
13
import pytest
4+
25
import cstruct
36
from cstruct import CEnum
4-
from enum import Enum
57

68

79
class Dummy(CEnum):

tests/test_cstruct.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
#
2626
# *****************************************************************************
2727

28-
import pytest
29-
import cstruct
30-
from cstruct import sizeof, typedef
3128
import io
3229
import os
3330
from pathlib import Path
31+
32+
import pytest
33+
34+
import cstruct
35+
from cstruct import sizeof, typedef
3436
from cstruct.exceptions import ParserError
3537

3638
MBR_DATA = (Path(__file__).parent.parent / "mbr").read_bytes()

tests/test_define.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
# *****************************************************************************
2727

2828
import sys
29+
2930
import pytest
31+
3032
import cstruct
31-
from cstruct import define, undef, sizeof, typedef
33+
from cstruct import define, sizeof, typedef, undef
3234
from cstruct.exceptions import ParserError
3335

3436
IS_64BITS = sys.maxsize > 2**32

tests/test_get_type.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# *****************************************************************************
2727

2828
import pytest
29+
2930
import cstruct
3031

3132

tests/test_memcstruct.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
#
2626
# *****************************************************************************
2727

28+
import os
29+
from pathlib import Path
30+
2831
import pytest
32+
2933
import cstruct
3034
from cstruct import sizeof, typedef
31-
import os
32-
from pathlib import Path
3335
from cstruct.exceptions import ParserError
3436

3537
MBR_DATA = (Path(__file__).parent.parent / "mbr").read_bytes()

tests/test_nested.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
# *****************************************************************************
2727

2828
import pytest
29+
2930
import cstruct
3031
from cstruct import sizeof
3132
from cstruct.exceptions import ParserError
3233

33-
3434
INVALID_ANONYMOUS = """
3535
struct NestedStruct {
3636
struct {

tests/test_pickle.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
import pickle
4+
45
import cstruct
56

67

tests/test_typdef.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#
2626
# *****************************************************************************
2727

28-
from cstruct import MemCStruct, NATIVE_ORDER
28+
from cstruct import NATIVE_ORDER, MemCStruct
2929
from cstruct.base import TYPEDEFS
3030

3131

tests/test_union.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
#
2626
# *****************************************************************************
2727

28+
import struct
29+
2830
import cstruct
2931
from cstruct import sizeof
30-
import struct
3132

3233

3334
class Position(cstruct.MemCStruct):

0 commit comments

Comments
 (0)