Skip to content

Commit a2ccf3a

Browse files
committed
Extract search method on FastPath.
1 parent 32854a0 commit a2ccf3a

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

importlib_metadata/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,18 @@ def is_egg(self, search):
421421
or root_n_low.startswith(search.prefix)
422422
and root_n_low.endswith('.egg'))
423423

424+
def search(self, name):
425+
for child in self.children():
426+
n_low = child.lower()
427+
if (n_low in name.exact_matches
428+
or n_low.startswith(name.prefix)
429+
and n_low.endswith(name.suffixes)
430+
# legacy case:
431+
or self.is_egg(name) and n_low == 'egg-info'):
432+
yield self.path_type(self.root, child)
433+
424434

425-
class FastSearch:
435+
class Prepared:
426436
"""
427437
Micro-optimized class for searching for an
428438
optional package name in list of children.
@@ -466,21 +476,10 @@ def find_distributions(self, context=DistributionFinder.Context()):
466476
def _search_paths(cls, name, paths):
467477
"""Find metadata directories in paths heuristically."""
468478
return itertools.chain.from_iterable(
469-
cls._search_path(path, FastSearch(name))
479+
path.search(Prepared(name))
470480
for path in map(FastPath, paths)
471481
)
472482

473-
@classmethod
474-
def _search_path(cls, root, name):
475-
for child in root.children():
476-
n_low = child.lower()
477-
if (n_low in name.exact_matches
478-
or n_low.startswith(name.prefix)
479-
and n_low.endswith(name.suffixes)
480-
# legacy case:
481-
or root.is_egg(name) and n_low == 'egg-info'):
482-
yield root.path_type(root.root, child)
483-
484483

485484
class PathDistribution(Distribution):
486485
def __init__(self, path):

0 commit comments

Comments
 (0)