Commit f24868e7 authored by Jason R. Coombs's avatar Jason R. Coombs

Extract functions for resolving egg_link and reading non-empty lines from a file.

parent 0a614125
...@@ -2048,8 +2048,8 @@ def find_on_path(importer, path_item, only=False): ...@@ -2048,8 +2048,8 @@ def find_on_path(importer, path_item, only=False):
path_item_entries = _by_version_descending(entries) path_item_entries = _by_version_descending(entries)
for entry in path_item_entries: for entry in path_item_entries:
lower = entry.lower() lower = entry.lower()
fullpath = os.path.join(path_item, entry)
if lower.endswith('.egg-info') or lower.endswith('.dist-info'): if lower.endswith('.egg-info') or lower.endswith('.dist-info'):
fullpath = os.path.join(path_item, entry)
if os.path.isdir(fullpath): if os.path.isdir(fullpath):
# egg-info directory, allow getting metadata # egg-info directory, allow getting metadata
if len(os.listdir(fullpath)) == 0: if len(os.listdir(fullpath)) == 0:
...@@ -2062,20 +2062,34 @@ def find_on_path(importer, path_item, only=False): ...@@ -2062,20 +2062,34 @@ def find_on_path(importer, path_item, only=False):
path_item, entry, metadata, precedence=DEVELOP_DIST path_item, entry, metadata, precedence=DEVELOP_DIST
) )
elif not only and _is_egg_path(entry): elif not only and _is_egg_path(entry):
dists = find_distributions(os.path.join(path_item, entry)) dists = find_distributions(fullpath)
for dist in dists: for dist in dists:
yield dist yield dist
elif not only and lower.endswith('.egg-link'): elif not only and lower.endswith('.egg-link'):
with open(os.path.join(path_item, entry)) as entry_file: dists = resolve_egg_link(fullpath)
entry_lines = entry_file.readlines() for dist in dists:
for line in entry_lines: yield dist
if not line.strip():
continue
path = os.path.join(path_item, line.rstrip()) def non_empty_lines(path):
dists = find_distributions(path) """
for item in dists: Yield non-empty lines from file at path
yield item """
break return (line.rstrip() for line in open(path) if line.strip())
def resolve_egg_link(path):
"""
Given a path to an .egg-link, resolve distributions
present in the referenced path.
"""
referenced_paths = non_empty_lines(path)
resolved_paths = (
os.path.join(os.path.dirname(path), ref)
for ref in referenced_paths
)
dist_groups = map(find_distributions, resolved_paths)
return next(dist_groups, ())
register_finder(pkgutil.ImpImporter, find_on_path) register_finder(pkgutil.ImpImporter, find_on_path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment