Skip to content

Commit

Permalink
Replace pkg_resources with importlib.metadata.
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Jan 26, 2024
1 parent 77de645 commit 22858e3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions flake8_import_order/styles.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
from collections import namedtuple

from pkg_resources import iter_entry_points
import sys

if sys.version_info >= (3, 8):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata

from flake8_import_order import ClassifiedImport, ImportType, NewLine

Error = namedtuple('Error', ['lineno', 'code', 'message'])


def list_entry_points():
return iter_entry_points('flake8_import_order.styles')
entry_points = importlib_metadata.entry_points()
if hasattr(entry_points, 'select'):
styles_groups = entry_points.select(group='flake8_import_order.styles')
else:
styles_groups = entry_points.get('flake8_import_order.styles', [])

return styles_groups


def lookup_entry_point(name):
try:
return next(iter_entry_points('flake8_import_order.styles', name=name))
except StopIteration:
raise LookupError(f'Unknown style {name}')
for style in list_entry_points():
if style.name == name:
return style

raise LookupError('Unknown style {}'.format(name))


class Style:
Expand Down

0 comments on commit 22858e3

Please sign in to comment.