diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-05-28 07:10:59 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-05-28 07:19:38 -0400 |
commit | 11051abd79b04782d759720a4d9dac2d2bbbf49c (patch) | |
tree | 5f8fe1d80b5ab97d5a7525f250dd1fce9e8bcdfa | |
parent | 41732cd23ba41c7f399f15504ab2ef3792b58624 (diff) | |
download | external_python_setuptools-11051abd79b04782d759720a4d9dac2d2bbbf49c.tar.gz external_python_setuptools-11051abd79b04782d759720a4d9dac2d2bbbf49c.tar.bz2 external_python_setuptools-11051abd79b04782d759720a4d9dac2d2bbbf49c.zip |
Extract _parents function and _set_egg method. Reword comment.
-rw-r--r-- | pkg_resources/__init__.py | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index edd3d2e8..2e7d5059 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -1577,6 +1577,17 @@ is not allowed. register_loader_type(object, NullProvider) +def _parents(path): + """ + yield all parents of path including path + """ + last = None + while path != last: + yield path + last = path + path, _ = os.path.split(path) + + class EggProvider(NullProvider): """Provider based on a virtual filesystem""" @@ -1585,18 +1596,16 @@ class EggProvider(NullProvider): self._setup_prefix() def _setup_prefix(self): - # we assume here that our metadata may be nested inside a "basket" - # of multiple eggs; that's why we use module_path instead of .archive - path = self.module_path - old = None - while path != old: - if _is_egg_path(path): - self.egg_name = os.path.basename(path) - self.egg_info = os.path.join(path, 'EGG-INFO') - self.egg_root = path - break - old = path - path, base = os.path.split(path) + # Assume that metadata may be nested inside a "basket" + # of multiple eggs and use module_path instead of .archive. + eggs = filter(_is_egg_path, _parents(self.module_path)) + egg = next(eggs, None) + egg and self._set_egg(egg) + + def _set_egg(self, path): + self.egg_name = os.path.basename(path) + self.egg_info = os.path.join(path, 'EGG-INFO') + self.egg_root = path class DefaultProvider(EggProvider): |