summaryrefslogtreecommitdiff
path: root/pkg_resources.py
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2005-08-06 02:30:52 +0000
committerPJ Eby <distutils-sig@python.org>2005-08-06 02:30:52 +0000
commit34e9acb9b0572b1f0503ee9e56439b768e575e83 (patch)
treeaeb731ec04d726e270432ee5dd40a69a4676c375 /pkg_resources.py
parentc9c1087c11cf7c487b85b599071bedbbcdbbc6d1 (diff)
downloadpython-setuptools-git-34e9acb9b0572b1f0503ee9e56439b768e575e83.tar.gz
Performance boosts: don't create environment during require()/resolve()
if all requirements can be met with items already in the working set. Don't eagerly determine whether a path is a directory. Avoid redundant path operations, etc. These changes dropped the test suite runtime from over 3.4 seconds to around .34 seconds. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041176
Diffstat (limited to 'pkg_resources.py')
-rw-r--r--pkg_resources.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/pkg_resources.py b/pkg_resources.py
index af47d367..1a9b594c 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -460,8 +460,6 @@ class WorkingSet(object):
already-installed distribution; it should return a ``Distribution`` or
``None``.
"""
- if env is None:
- env = AvailableDistributions(self.entries)
requirements = list(requirements)[::-1] # set up the stack
processed = {} # set of processed requirements
@@ -477,6 +475,8 @@ class WorkingSet(object):
dist = best.get(req.key)
if dist is None:
# Find the best distribution and add it to the map
+ if env is None:
+ env = AvailableDistributions(self.entries)
dist = best[req.key] = env.best_match(req, self, installer)
if dist is None:
raise DistributionNotFound(req) # XXX put more info here
@@ -1232,8 +1232,6 @@ class ImpWrapper:
"""PEP 302 Importer that wraps Python's "normal" import algorithm"""
def __init__(self, path=None):
- if path is not None and not os.path.isdir(path):
- raise ImportError
self.path = path
def find_module(self, fullname, path=None):
@@ -1269,6 +1267,8 @@ class ImpLoader:
return mod
+
+
def get_importer(path_item):
"""Retrieve a PEP 302 "importer" for the given path item
@@ -1357,9 +1357,8 @@ register_finder(object,find_nothing)
def find_on_path(importer, path_item, only=False):
"""Yield distributions accessible on a sys.path directory"""
- if not os.path.exists(path_item):
- return
path_item = normalize_path(path_item)
+
if os.path.isdir(path_item):
if path_item.lower().endswith('.egg'):
# unpacked egg
@@ -1370,10 +1369,10 @@ def find_on_path(importer, path_item, only=False):
)
else:
# scan for .egg and .egg-info in directory
- for entry in os.listdir(path_item):
- fullpath = os.path.join(path_item, entry)
+ for entry in os.listdir(path_item):
lower = entry.lower()
if lower.endswith('.egg-info'):
+ fullpath = os.path.join(path_item, entry)
if os.path.isdir(fullpath):
# development egg
metadata = PathMetadata(path_item, fullpath)
@@ -1382,16 +1381,17 @@ def find_on_path(importer, path_item, only=False):
path_item, metadata, project_name=dist_name
)
elif not only and lower.endswith('.egg'):
- for dist in find_distributions(fullpath):
+ for dist in find_distributions(os.path.join(path_item, entry)):
yield dist
elif not only and lower.endswith('.egg-link'):
- for line in file(fullpath):
+ for line in file(os.path.join(path_item, entry)):
if not line.strip(): continue
for item in find_distributions(line.rstrip()):
yield item
register_finder(ImpWrapper,find_on_path)
+
_namespace_handlers = {}
_namespace_packages = {}