Skip to content

Commit

Permalink
Precompute egg_prefix and versionless_egg_name.
Browse files Browse the repository at this point in the history
  • Loading branch information
anntzer committed Jan 10, 2021
1 parent c9c0909 commit 7fc4f11
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions importlib_metadata/__init__.py
Expand Up @@ -495,6 +495,8 @@ class Prepared:
normalized = None
suffixes = 'dist-info', 'egg-info'
exact_matches = [''][:0]
egg_prefix = ''
versionless_egg_name = ''

def __init__(self, name):
self.name = name
Expand All @@ -504,6 +506,9 @@ def __init__(self, name):
self.exact_matches = [
self.normalized + '.' + suffix for suffix in self.suffixes
]
legacy_normalized = self.legacy_normalize(self.name)
self.egg_prefix = legacy_normalized + '-'
self.versionless_egg_name = legacy_normalized + '.egg'

@staticmethod
def normalize(name):
Expand Down Expand Up @@ -536,12 +541,9 @@ def matches(self, cand, base):
)

def is_egg(self, base):
normalized = self.legacy_normalize(self.name or '')
prefix = normalized + '-' if normalized else ''
versionless_egg_name = normalized + '.egg' if self.name else ''
return (
base == versionless_egg_name
or base.startswith(prefix)
base == self.versionless_egg_name
or base.startswith(self.egg_prefix)
and base.endswith('.egg')
)

Expand Down

0 comments on commit 7fc4f11

Please sign in to comment.