Skip to content

Commit d87acc2

Browse files
committed
Extract is_egg method
1 parent 11c147f commit d87acc2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

importlib_metadata/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ def zip_children(self):
413413
for child in names
414414
)
415415

416+
def is_egg(self, normalized, prefix):
417+
root_n_low = os.path.split(self.root)[1].lower()
418+
419+
return (
420+
root_n_low == normalized + '.egg'
421+
or root_n_low.startswith(prefix) and root_n_low.endswith('.egg'))
422+
416423

417424
@install
418425
class MetadataPathFinder(NullFinder, DistributionFinder):
@@ -451,16 +458,13 @@ def _search_path(cls, root, name):
451458
normalized = prefix = ''
452459
suffixes = ('.dist-info', '.egg-info')
453460
exact_matches = [normalized + suffix for suffix in suffixes]
454-
root_n_low = os.path.split(root.root)[1].lower()
455-
root_is_egg = (
456-
root_n_low == normalized + '.egg'
457-
or root_n_low.startswith(prefix) and root_n_low.endswith('.egg'))
458461
for child in root.children():
459462
n_low = child.lower()
460463
if (n_low in exact_matches
461464
or n_low.startswith(prefix) and n_low.endswith(suffixes)
462465
# legacy case:
463-
or root_is_egg and n_low == 'egg-info'):
466+
or root.is_egg(normalized, prefix)
467+
and n_low == 'egg-info'):
464468
yield root.path_type(root.root, child)
465469

466470

0 commit comments

Comments
 (0)