Skip to content

Commit 0ed972a

Browse files
committed
Add auto-formatting
Update pre-commit hooks Fix typo Fix build metadata problems
1 parent 4467390 commit 0ed972a

16 files changed

+300
-165
lines changed

.pre-commit-config.yaml

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,66 @@
55
# Learn more about this config here: https://pre-commit.com/
66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v4.4.0
8+
rev: v5.0.0
99
hooks:
10-
- id: check-yaml
11-
- id: detect-private-key
12-
- id: end-of-file-fixer
13-
- id: mixed-line-ending
14-
- id: trailing-whitespace
10+
- id: check-added-large-files
11+
- id: check-toml
12+
types: [toml]
13+
- id: check-yaml
14+
types: [yaml]
15+
- id: end-of-file-fixer
16+
types: [text]
17+
stages: [pre-commit, pre-push, manual]
18+
- id: trailing-whitespace
19+
types: [text]
20+
stages: [pre-commit, pre-push, manual]
21+
- id: detect-private-key
22+
- id: mixed-line-ending
1523

1624
- repo: https://github.com/codespell-project/codespell
17-
rev: v2.2.2
25+
rev: v2.4.1
1826
hooks:
19-
- id: codespell
20-
additional_dependencies:
21-
- tomli
27+
- id: codespell
28+
additional_dependencies:
29+
- tomli
2230

2331
- repo: https://github.com/asottile/pyupgrade
24-
rev: v3.2.3
32+
rev: v3.20.0
2533
hooks:
26-
- id: pyupgrade
27-
args:
28-
- --py37-plus
34+
- id: pyupgrade
35+
args: [--py37-plus]
36+
37+
- repo: https://github.com/PyCQA/isort
38+
rev: 6.0.1
39+
hooks:
40+
- id: isort
41+
42+
- repo: https://github.com/psf/black
43+
rev: 25.1.0
44+
hooks:
45+
- id: black
46+
exclude: 'tests/test_cases'
47+
48+
# - repo: https://github.com/pre-commit/mirrors-mypy
49+
# rev: v1.16.0
50+
# hooks:
51+
# - id: mypy
52+
# additional_dependencies:
53+
# - types-python-dateutil
54+
# - types-requests
55+
# exclude: ^(docs/|tests/)
56+
# - repo: https://github.com/jorisroovers/gitlint
57+
# rev: v0.19.1
58+
# hooks:
59+
# - id: gitlint
60+
#
61+
- repo: https://github.com/asottile/setup-cfg-fmt
62+
rev: v2.8.0
63+
hooks:
64+
- id: setup-cfg-fmt
65+
args: [--min-py3-version, '3.9']
66+
67+
- repo: https://github.com/gitleaks/gitleaks
68+
rev: v8.27.2
69+
hooks:
70+
- id: gitleaks

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
custom styles (that use the nodes directly). This also drops the
4141
asttokens dependency as it is no longer required.
4242
* Understand the existence of namespaced packages, thereby allowing
43-
different namespaced pacakages to be defined as local or third party.
43+
different namespaced packages to be defined as local or third party.
4444

4545
0.15 2017-11-06
4646
---------------

flake8_import_order/__about__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
__all__ = [
2-
"__title__", "__summary__", "__uri__", "__version__", "__author__",
3-
"__email__", "__license__", "__copyright__", '__maintainer__',
4-
'__maintainer_email__',
2+
"__title__",
3+
"__summary__",
4+
"__uri__",
5+
"__version__",
6+
"__author__",
7+
"__email__",
8+
"__license__",
9+
"__copyright__",
10+
"__maintainer__",
11+
"__maintainer_email__",
512
]
613

714
__title__ = "flake8-import-order"
@@ -15,8 +22,8 @@
1522
__author__ = "Alex Stapleton"
1623
__email__ = "alexs@prol.etari.at"
1724

18-
__maintainer__ = 'Phil Jones'
19-
__maintainer_email__ = 'philip.graham.jones+flake8-import@gmail.com'
25+
__maintainer__ = "Phil Jones"
26+
__maintainer_email__ = "philip.graham.jones+flake8-import@gmail.com"
2027

2128
__license__ = "LGPLv3"
2229
__copyright__ = "Copyright 2013-2016 %s" % __author__

flake8_import_order/__init__.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22
from collections import namedtuple
33
from enum import IntEnum
44

5-
from .__about__ import (
6-
__author__, __copyright__, __email__, __license__, __summary__, __title__,
7-
__uri__, __version__,
8-
)
5+
from .__about__ import __author__
6+
from .__about__ import __copyright__
7+
from .__about__ import __email__
8+
from .__about__ import __license__
9+
from .__about__ import __summary__
10+
from .__about__ import __title__
11+
from .__about__ import __uri__
12+
from .__about__ import __version__
913
from .stdlib_list import STDLIB_NAMES
1014

1115
__all__ = [
12-
"__title__", "__summary__", "__uri__", "__version__", "__author__",
13-
"__email__", "__license__", "__copyright__",
16+
"__title__",
17+
"__summary__",
18+
"__uri__",
19+
"__version__",
20+
"__author__",
21+
"__email__",
22+
"__license__",
23+
"__copyright__",
1424
]
1525

16-
DEFAULT_IMPORT_ORDER_STYLE = 'cryptography'
26+
DEFAULT_IMPORT_ORDER_STYLE = "cryptography"
1727

1828
ClassifiedImport = namedtuple(
19-
'ClassifiedImport',
20-
['type', 'is_from', 'modules', 'names', 'lineno', 'level', 'package'],
29+
"ClassifiedImport",
30+
["type", "is_from", "modules", "names", "lineno", "level", "package"],
2131
)
22-
NewLine = namedtuple('NewLine', ['lineno'])
32+
NewLine = namedtuple("NewLine", ["lineno"])
2333

2434

2535
class ImportType(IntEnum):
@@ -48,7 +58,7 @@ def get_package_names(name):
4858
package_names = [last_package_name]
4959

5060
for part in reversed(parts):
51-
last_package_name = f'{last_package_name}.{part}'
61+
last_package_name = f"{last_package_name}.{part}"
5262
package_names.append(last_package_name)
5363

5464
return package_names
@@ -79,22 +89,31 @@ def visit_Import(self, node): # noqa: N802
7989
else:
8090
type_ = ImportType.MIXED
8191
classified_import = ClassifiedImport(
82-
type_, False, modules, [], node.lineno, 0,
92+
type_,
93+
False,
94+
modules,
95+
[],
96+
node.lineno,
97+
0,
8398
root_package_name(modules[0]),
8499
)
85100
self.imports.append(classified_import)
86101

87102
def visit_ImportFrom(self, node): # noqa: N802
88103
if node.col_offset == 0:
89-
module = node.module or ''
104+
module = node.module or ""
90105
if node.level > 0:
91106
type_ = ImportType.APPLICATION_RELATIVE
92107
else:
93108
type_ = self._classify_type(module)
94109
names = [alias.name for alias in node.names]
95110
classified_import = ClassifiedImport(
96-
type_, True, [module], names,
97-
node.lineno, node.level,
111+
type_,
112+
True,
113+
[module],
114+
names,
115+
node.lineno,
116+
node.level,
98117
root_package_name(module),
99118
)
100119
self.imports.append(classified_import)

flake8_import_order/checker.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
import pycodestyle
66

7-
from flake8_import_order import ImportVisitor, NewLine
7+
from flake8_import_order import ImportVisitor
8+
from flake8_import_order import NewLine
89
from flake8_import_order.styles import lookup_entry_point
910

10-
DEFAULT_IMPORT_ORDER_STYLE = 'cryptography'
11+
DEFAULT_IMPORT_ORDER_STYLE = "cryptography"
1112
NOQA_INLINE_REGEXP = re.compile(
1213
# We're looking for items that look like this:
1314
# ``# noqa``
@@ -18,11 +19,11 @@
1819
# We do not care about the ``: `` that follows ``noqa``
1920
# We do not care about the casing of ``noqa``
2021
# We want a comma-separated list of errors
21-
r'# noqa(?:: (?P<codes>([A-Z][0-9]+(?:[,\s]+)?)+))?',
22-
re.IGNORECASE
22+
r"# noqa(?:: (?P<codes>([A-Z][0-9]+(?:[,\s]+)?)+))?",
23+
re.IGNORECASE,
2324
)
24-
COMMA_SEPARATED_LIST_RE = re.compile(r'[,\s]')
25-
BLANK_LINE_RE = re.compile(r'\s*\n')
25+
COMMA_SEPARATED_LIST_RE = re.compile(r"[,\s]")
26+
BLANK_LINE_RE = re.compile(r"\s*\n")
2627

2728

2829
class ImportOrderChecker:
@@ -42,7 +43,7 @@ def load_file(self):
4243
self.lines = pycodestyle.readlines(self.filename)
4344

4445
if self.tree is None:
45-
self.tree = ast.parse(''.join(self.lines))
46+
self.tree = ast.parse("".join(self.lines))
4647

4748
def error(self, error):
4849
return error
@@ -52,19 +53,19 @@ def check_order(self):
5253
self.load_file()
5354

5455
try:
55-
style_entry_point = self.options['import_order_style']
56+
style_entry_point = self.options["import_order_style"]
5657
except KeyError:
5758
style_entry_point = lookup_entry_point(DEFAULT_IMPORT_ORDER_STYLE)
5859
style_cls = style_entry_point.load()
5960

6061
if style_cls.accepts_application_package_names:
6162
visitor = self.visitor_class(
62-
self.options.get('application_import_names', []),
63-
self.options.get('application_package_names', []),
63+
self.options.get("application_import_names", []),
64+
self.options.get("application_package_names", []),
6465
)
6566
else:
6667
visitor = self.visitor_class(
67-
self.options.get('application_import_names', []),
68+
self.options.get("application_import_names", []),
6869
[],
6970
)
7071
visitor.visit(self.tree)
@@ -90,7 +91,7 @@ def error_is_ignored(self, error):
9091
if noqa_match is None:
9192
return False
9293

93-
codes_str = noqa_match.group('codes')
94+
codes_str = noqa_match.group("codes")
9495
if codes_str is None:
9596
return True
9697

flake8_import_order/flake8_linter.py

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

33
from flake8_import_order import __version__
4-
from flake8_import_order.checker import (
5-
DEFAULT_IMPORT_ORDER_STYLE, ImportOrderChecker,
6-
)
7-
from flake8_import_order.styles import list_entry_points, lookup_entry_point
4+
from flake8_import_order.checker import DEFAULT_IMPORT_ORDER_STYLE
5+
from flake8_import_order.checker import ImportOrderChecker
6+
from flake8_import_order.styles import list_entry_points
7+
from flake8_import_order.styles import lookup_entry_point
88

99

1010
class Linter(ImportOrderChecker):
@@ -99,9 +99,9 @@ def register_opt(parser, *args, **kwargs):
9999
parser.add_option(*args, **kwargs)
100100
except (optparse.OptionError, TypeError):
101101
# Flake8 2.x registration
102-
parse_from_config = kwargs.pop('parse_from_config', False)
103-
kwargs.pop('comma_separated_list', False)
104-
kwargs.pop('normalize_paths', False)
102+
parse_from_config = kwargs.pop("parse_from_config", False)
103+
kwargs.pop("comma_separated_list", False)
104+
kwargs.pop("normalize_paths", False)
105105
parser.add_option(*args, **kwargs)
106106
if parse_from_config:
107-
parser.config_options.append(args[-1].lstrip('-'))
107+
parser.config_options.append(args[-1].lstrip("-"))

flake8_import_order/pylama_linter.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from pylama.lint import Linter as BaseLinter
22

33
from flake8_import_order import __version__
4-
from flake8_import_order.checker import (
5-
DEFAULT_IMPORT_ORDER_STYLE, ImportOrderChecker,
6-
)
4+
from flake8_import_order.checker import DEFAULT_IMPORT_ORDER_STYLE
5+
from flake8_import_order.checker import ImportOrderChecker
76
from flake8_import_order.styles import lookup_entry_point
87

98

@@ -19,18 +18,18 @@ def allow(self, path):
1918

2019
def error(self, error):
2120
return {
22-
'lnum': error.lineno,
23-
'col': 0,
24-
'text': error.message,
25-
'type': error.code,
21+
"lnum": error.lineno,
22+
"col": 0,
23+
"text": error.message,
24+
"type": error.code,
2625
}
2726

2827
def run(self, path, **meta):
2928
self.filename = path
3029
self.ast_tree = None
31-
meta.setdefault('import_order_style', DEFAULT_IMPORT_ORDER_STYLE)
32-
meta['import_order_style'] = lookup_entry_point(
33-
meta['import_order_style']
30+
meta.setdefault("import_order_style", DEFAULT_IMPORT_ORDER_STYLE)
31+
meta["import_order_style"] = lookup_entry_point(
32+
meta["import_order_style"]
3433
)
3534
self.options = meta
3635

0 commit comments

Comments
 (0)