Skip to content

Commit 313535a

Browse files
committed
Extract method for matching a name in a prepared search.
1 parent 4335def commit 313535a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

importlib_metadata/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,11 @@ def is_egg(self, search):
470470
and base.endswith('.egg'))
471471

472472
def search(self, name):
473-
for child in self.children():
474-
n_low = child.lower()
475-
if (n_low in name.exact_matches
476-
or n_low.replace('.', '_').startswith(name.prefix)
477-
and n_low.endswith(name.suffixes)
478-
# legacy case:
479-
or self.is_egg(name) and n_low == 'egg-info'):
480-
yield self.joinpath(child)
473+
return (
474+
self.joinpath(child)
475+
for child in self.children()
476+
if name.matches(child, self)
477+
)
481478

482479

483480
class Prepared:
@@ -507,6 +504,16 @@ def normalize(name):
507504
"""
508505
return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
509506

507+
def matches(self, name, path):
508+
n_low = name.lower()
509+
return (
510+
n_low in self.exact_matches
511+
or n_low.replace('.', '_').startswith(self.prefix)
512+
and n_low.endswith(self.suffixes)
513+
# legacy case:
514+
or path.is_egg(self) and n_low == 'egg-info'
515+
)
516+
510517

511518
@install
512519
class MetadataPathFinder(NullFinder, DistributionFinder):

0 commit comments

Comments
 (0)