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 | b6a3ccf987ce2f8d13e1520563223bd76460744a (patch) | |
| tree | d67b09af754bd18c733288725353ca177b12d5a7 | |
| parent | a88effc90cdc99974ae65c008238566cdab4b98e (diff) | |
| download | python-setuptools-git-b6a3ccf987ce2f8d13e1520563223bd76460744a.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() |
