Skip to content

Commit

Permalink
vendor lookup_entry_point to avoid pgk_resources deprecation warnings (
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT authored Aug 16, 2023
1 parent d6af4ad commit 5ff1faf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ install_requires =
pyflakes
flake8-import-order
tomli
importlib-metadata;python_version<"3.10"

[options.entry_points]
console_scripts =
Expand Down
3 changes: 2 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def import_module(name):
return self.mock_sqlalchemy
elif name == "sqlalchemy.orm":
return self.mock_sqlalchemy_orm
elif name == "zimports":
return __import__("zimports")
else:
raise ImportError(name)

Expand Down Expand Up @@ -51,7 +53,6 @@ def _assert_file(
encoding="utf-8",
checkfile=None,
):

with self._simulate_importlib(), self._capture_stdout() as buf:
zimports.main(
["test_files/%s" % filename]
Expand Down
16 changes: 16 additions & 0 deletions zimports/vendored/flake8_import_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys

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


def lookup_entry_point(name):
try:
(ep,) = importlib_metadata.entry_points(
name=name, group="flake8_import_order.styles"
)
return ep
except ValueError:
raise LookupError("Unknown style {}".format(name))
6 changes: 1 addition & 5 deletions zimports/zimports.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
from typing import Tuple

import flake8_import_order as f8io
from flake8_import_order.styles import lookup_entry_point
import pyflakes.checker
import pyflakes.messages

from .vendored.flake8 import matches_filename
from .vendored.flake8 import normalize_path
from .vendored.flake8_import_order import lookup_entry_point


class RewritePass(enum.Enum):
Expand Down Expand Up @@ -673,7 +673,6 @@ def _remove_unused_names(
def _dedupe_single_imports(
import_nodes: Iterable[ClassifiedImport], stats: dict
):

seen = {}
orig_order: List[Tuple[ClassifiedImport, Any]] = []

Expand Down Expand Up @@ -713,7 +712,6 @@ def _as_single_imports(
stats: dict,
expand_stars: bool = False,
):

for import_node in import_nodes:
if not import_node.is_from:
for ast_name in import_node.ast_names:
Expand Down Expand Up @@ -885,7 +883,6 @@ def _parse_magic_encoding_comment(fp):


def _run_file(options, filename):

lines, encoding_comment = _read_python_source(filename)
source_lines = [line.rstrip() for line in lines]

Expand Down Expand Up @@ -922,7 +919,6 @@ def _run_file(options, filename):
)

if not options.statsonly:

if options.diff:
sys.stdout.writelines(
difflib.unified_diff(
Expand Down

0 comments on commit 5ff1faf

Please sign in to comment.