diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2015-11-22 19:16:09 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-11-22 19:16:09 -0500 |
commit | b6f244b98aaa6a52477f162d10b293bb4ab699e8 (patch) | |
tree | dccd1bb4b1e91064ce29a32a9d3e6a7b3d990a23 | |
parent | 7a16db256d6c8ffb6b19bf324c77f85db05dfdc3 (diff) | |
download | python-setuptools-bitbucket-b6f244b98aaa6a52477f162d10b293bb4ab699e8.tar.gz |
Extract function for detecting unpacked egg. Ref #462.
-rw-r--r-- | pkg_resources/__init__.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index d09e0b6f..0c024f1b 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -1716,7 +1716,7 @@ class EggProvider(NullProvider): path = self.module_path old = None while path!=old: - if path.lower().endswith('.egg'): + if _is_unpacked_egg(path): self.egg_name = os.path.basename(path) self.egg_info = os.path.join(path, 'EGG-INFO') self.egg_root = path @@ -2099,7 +2099,7 @@ def find_eggs_in_zip(importer, path_item, only=False): # don't yield nested distros return for subitem in metadata.resource_listdir('/'): - if subitem.endswith('.egg'): + if _is_unpacked_egg(subitem): subpath = os.path.join(path_item, subitem) for dist in find_eggs_in_zip(zipimport.zipimporter(subpath), subpath): yield dist @@ -2115,8 +2115,7 @@ def find_on_path(importer, path_item, only=False): path_item = _normalize_cached(path_item) if os.path.isdir(path_item) and os.access(path_item, os.R_OK): - if path_item.lower().endswith('.egg'): - # unpacked egg + if _is_unpacked_egg(path_item): yield Distribution.from_filename( path_item, metadata=PathMetadata( path_item, os.path.join(path_item,'EGG-INFO') @@ -2136,7 +2135,7 @@ def find_on_path(importer, path_item, only=False): yield Distribution.from_location( path_item, entry, metadata, precedence=DEVELOP_DIST ) - elif not only and lower.endswith('.egg'): + elif not only and _is_unpacked_egg(entry): dists = find_distributions(os.path.join(path_item, entry)) for dist in dists: yield dist @@ -2283,6 +2282,14 @@ def _normalize_cached(filename, _cache={}): _cache[filename] = result = normalize_path(filename) return result +def _is_unpacked_egg(path): + """ + Determine if given path appears to be an unpacked egg. + """ + return ( + path.lower().endswith('.egg') + ) + def _set_parent_ns(packageName): parts = packageName.split('.') name = parts.pop() |