diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2017-09-09 11:31:50 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2017-09-09 11:31:50 -0400 |
| commit | 7e173ffb2da7cbdbf0c90b491779402aa74a6b42 (patch) | |
| tree | 60c9b04b8b64035355ffe5db44f71b90a5d8d333 /pkg_resources/__init__.py | |
| parent | f24868e7921d960ea4d63958e7090522ada8f2d0 (diff) | |
| download | python-setuptools-git-7e173ffb2da7cbdbf0c90b491779402aa74a6b42.tar.gz | |
Extract distributions_from_metadata
Diffstat (limited to 'pkg_resources/__init__.py')
| -rw-r--r-- | pkg_resources/__init__.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index cbf0a6a5..7b5043dc 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2050,17 +2050,9 @@ def find_on_path(importer, path_item, only=False): lower = entry.lower() fullpath = os.path.join(path_item, entry) if lower.endswith('.egg-info') or lower.endswith('.dist-info'): - if os.path.isdir(fullpath): - # egg-info directory, allow getting metadata - if len(os.listdir(fullpath)) == 0: - # Empty egg directory, skip. - continue - metadata = PathMetadata(path_item, fullpath) - else: - metadata = FileMetadata(fullpath) - yield Distribution.from_location( - path_item, entry, metadata, precedence=DEVELOP_DIST - ) + dists = distributions_from_metadata(fullpath) + for dist in dists: + yield dist elif not only and _is_egg_path(entry): dists = find_distributions(fullpath) for dist in dists: @@ -2071,6 +2063,21 @@ def find_on_path(importer, path_item, only=False): yield dist +def distributions_from_metadata(path): + root = os.path.dirname(path) + if os.path.isdir(path): + if len(os.listdir(path)) == 0: + # empty metadata dir; skip + return + metadata = PathMetadata(root, path) + else: + metadata = FileMetadata(path) + entry = os.path.basename(path) + yield Distribution.from_location( + root, entry, metadata, precedence=DEVELOP_DIST, + ) + + def non_empty_lines(path): """ Yield non-empty lines from file at path |
