Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pkg_resources with importlib.metadata. #203

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions flake8_import_order/styles.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import sys
from collections import namedtuple

from pkg_resources import iter_entry_points
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
Loading