summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.rst7
-rw-r--r--pkg_resources/__init__.py14
2 files changed, 20 insertions, 1 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 8130511e..011e19ff 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,10 @@
+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
-------
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 0f5dd238..68349df4 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -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 (