[Python-checkins] python/nondist/sandbox/setuptools pkg_resources.py, 1.56, 1.57 setuptools.txt, 1.24, 1.25

pje@users.sourceforge.net pje at users.sourceforge.net
Sat Aug 6 04:30:55 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/setuptools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4617

Modified Files:
	pkg_resources.py setuptools.txt 
Log Message:
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.


Index: pkg_resources.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- pkg_resources.py	3 Aug 2005 13:18:50 -0000	1.56
+++ pkg_resources.py	6 Aug 2005 02:30:52 -0000	1.57
@@ -460,8 +460,6 @@
         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 @@
             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 @@
     """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 @@
         return mod
 
 
+
+
 def get_importer(path_item):
     """Retrieve a PEP 302 "importer" for the given path item
 
@@ -1357,9 +1357,8 @@
 
 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 @@
             )
         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 @@
                             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 = {}
 

Index: setuptools.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools.txt,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- setuptools.txt	25 Jul 2005 03:12:51 -0000	1.24
+++ setuptools.txt	6 Aug 2005 02:30:52 -0000	1.25
@@ -1597,6 +1597,10 @@
    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.



More information about the Python-checkins mailing list