Commit 34e9acb9 authored by PJ Eby's avatar PJ Eby

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
parent c9c1087c
......@@ -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 = {}
......
......@@ -1597,6 +1597,10 @@ Release Notes/Change History
containing ``setup.py``, not the highest revision number in the project.
* Added ``eager_resources`` setup argument
* Enhanced performance of ``require()`` and related operations when all
requirements are already in the working set, and enhanced performance of
directory scanning for distributions.
* Fixed some problems using ``pkg_resources`` w/PEP 302 loaders other than
``zipimport``, and the previously-broken "eager resource" support.
......
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