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

Screen entries before sorting in find_on_path. Ref #1134.

parent 6f10cff4
v36.5.0
-------
* Inspired by #1134, performed substantial refactoring of
``pkg_resources.find_on_path`` to facilitate an optimization
for paths with many non-version entries.
v36.4.0
-------
......
......@@ -2032,8 +2032,17 @@ def find_on_path(importer, path_item, only=False):
entries = safe_listdir(path_item)
# for performance, before sorting by version,
# screen entries for only those that will yield
# distributions
filtered = (
entry
for entry in entries
if dist_factory(path_item, entry, only)
)
# scan for .egg and .egg-info in directory
path_item_entries = _by_version_descending(entries)
path_item_entries = _by_version_descending(filtered)
for entry in path_item_entries:
fullpath = os.path.join(path_item, entry)
factory = dist_factory(path_item, entry, only)
......@@ -2042,6 +2051,9 @@ def find_on_path(importer, path_item, only=False):
def dist_factory(path_item, entry, only):
"""
Return a dist_factory for a path_item and entry
"""
lower = entry.lower()
is_meta = any(map(lower.endswith, ('.egg-info', '.dist-info')))
return (
......
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