Skip to content

Commit 64f3647

Browse files
Replace pkg_resources with importlib.metadata
As of setuptools 68.0.0, the entire pkg_resources library is deprecated. Switch away from pkg_resources.iter_entry_points and instead use importlib.metadata.entry_points(), which provides the same information in a slightly different format. Closes #203 Signed-off-by: Chris Lalancette <clalancette@gmail.com> Co-authored-by: Ian Stapleton Cordasco <graffatcolmingov@gmail.com>
1 parent 0ed972a commit 64f3647

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# To enable this pre-commit hook run:
22
# `pip install pre-commit` or `brew install pre-commit`
33
# Then run `pre-commit install`
4+
exclude: 'tests\/test_cases'
45

56
# Learn more about this config here: https://pre-commit.com/
67
repos:
@@ -32,7 +33,7 @@ repos:
3233
rev: v3.20.0
3334
hooks:
3435
- id: pyupgrade
35-
args: [--py37-plus]
36+
args: [--py39-plus]
3637

3738
- repo: https://github.com/PyCQA/isort
3839
rev: 6.0.1
@@ -43,7 +44,6 @@ repos:
4344
rev: 25.1.0
4445
hooks:
4546
- id: black
46-
exclude: 'tests/test_cases'
4747

4848
# - repo: https://github.com/pre-commit/mirrors-mypy
4949
# rev: v1.16.0

flake8_import_order/styles.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import importlib.metadata
12
from collections import namedtuple
23

3-
from pkg_resources import iter_entry_points
4-
54
from flake8_import_order import ClassifiedImport
65
from flake8_import_order import ImportType
76
from flake8_import_order import NewLine
@@ -10,16 +9,18 @@
109

1110

1211
def list_entry_points():
13-
return iter_entry_points("flake8_import_order.styles")
12+
entry_points = importlib.metadata.entry_points()
13+
if not hasattr(entry_points, "select"):
14+
return entry_points.get("flake8_import_order.styles", [])
15+
return entry_points.select(group="flake8_import_order.styles")
1416

1517

1618
def lookup_entry_point(name):
17-
try:
18-
return next(
19-
iter_entry_points("flake8_import_order.styles", name=name)
20-
)
21-
except StopIteration:
22-
raise LookupError(f"Unknown style {name}")
19+
for style in list_entry_points():
20+
if style.name == name:
21+
return style
22+
23+
raise LookupError(f"Unknown style {name}")
2324

2425

2526
class Style:
@@ -88,9 +89,9 @@ def _check_I100(self, previous_import, current_import): # noqa: N802
8889
message = f"{message} and in a different group."
8990
yield Error(current_import.lineno, "I100", message)
9091

91-
def _check_I201(
92+
def _check_I201( # noqa: N802
9293
self, previous_import, previous, current_import
93-
): # noqa: N802,E501
94+
):
9495
same_section = self.same_section(previous_import, current_import)
9596
has_newline = isinstance(previous, NewLine)
9697
if not same_section and not has_newline:
@@ -105,9 +106,9 @@ def _check_I201(
105106
),
106107
)
107108

108-
def _check_I202(
109+
def _check_I202( # noqa: N802
109110
self, previous_import, previous, current_import
110-
): # noqa: N802,E501
111+
):
111112
same_section = self.same_section(previous_import, current_import)
112113
has_newline = isinstance(previous, NewLine)
113114
if same_section and has_newline:
@@ -207,9 +208,9 @@ def import_key(import_):
207208
class Edited(Smarkets):
208209
accepts_application_package_names = True
209210

210-
def _check_I202(
211+
def _check_I202( # noqa: N802
211212
self, previous_import, previous, current_import
212-
): # noqa: N802,E501
213+
):
213214
same_section = self.same_section(previous_import, current_import)
214215
has_newline = isinstance(previous, NewLine)
215216
optional_split = (

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ ignore = tox.ini
6060
[flake8]
6161
exclude = .tox,*.egg,tests/test_cases/
6262
select = E,W,F,N,I
63+
ignore = W503
6364
application-import-names = flake8_import_order,tests
65+
max-line-length = 88
66+
max-complexity = 10
6467

6568
[coverage:run]
6669
source = flake8_import_order

tests/test_stdlib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import ast
22

3+
# isort: off
34
import pycodestyle
5+
46
import pytest
57

8+
# isort: on
9+
610
from flake8_import_order import STDLIB_NAMES
711
from flake8_import_order.checker import ImportOrderChecker
812

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ deps =
1515
flake8
1616
flake8-import-order
1717
pep8-naming
18-
commands = flake8 --ignore=W503 --max-line-length=88 --max-complexity=10 flake8_import_order/ tests/
18+
commands = flake8 flake8_import_order/ tests/
1919

2020
[testenv:setuppy]
2121
deps =

0 commit comments

Comments
 (0)