diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2017-09-09 12:14:46 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2017-09-09 12:14:46 -0400 |
| commit | 6f10cff41ca441a91ddb9182c591a4a2e170633a (patch) | |
| tree | 2e968ab59117e5ab77997482fc3ae659d3ff05a6 /pkg_resources | |
| parent | 9ff9a0d6a79b8d4b610f8e8780586dd2114856d0 (diff) | |
| download | python-setuptools-git-6f10cff41ca441a91ddb9182c591a4a2e170633a.tar.gz | |
Extract function for resolving the dist factory for a path item entry
Diffstat (limited to 'pkg_resources')
| -rw-r--r-- | pkg_resources/__init__.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 82b4ce51..0f5dd238 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2035,22 +2035,26 @@ def find_on_path(importer, path_item, only=False): # scan for .egg and .egg-info in directory path_item_entries = _by_version_descending(entries) for entry in path_item_entries: - lower = entry.lower() fullpath = os.path.join(path_item, entry) - is_meta = any(map(lower.endswith, ('.egg-info', '.dist-info'))) - dists = ( - distributions_from_metadata(fullpath) - if is_meta else - find_distributions(fullpath) - if not only and _is_egg_path(entry) else - resolve_egg_link(fullpath) - if not only and lower.endswith('.egg-link') else - NoDists()(fullpath) - ) - for dist in dists: + factory = dist_factory(path_item, entry, only) + for dist in factory(fullpath): yield dist +def dist_factory(path_item, entry, only): + lower = entry.lower() + is_meta = any(map(lower.endswith, ('.egg-info', '.dist-info'))) + return ( + distributions_from_metadata + if is_meta else + find_distributions + if not only and _is_egg_path(entry) else + resolve_egg_link + if not only and lower.endswith('.egg-link') else + NoDists() + ) + + class NoDists: """ >>> bool(NoDists()) |
