[Checkins] SVN: zc.buildout/branches/env-cache/src/zc/buildout/easy_install.py Cache dists on a per-path basis instead of caching envs.

Ross Patterson me at rpatterson.net
Tue Jan 24 06:38:10 UTC 2012


Log message for revision 124153:
  Cache dists on a per-path basis instead of caching envs.

Changed:
  U   zc.buildout/branches/env-cache/src/zc/buildout/easy_install.py

-=-
Modified: zc.buildout/branches/env-cache/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/env-cache/src/zc/buildout/easy_install.py	2012-01-23 17:01:42 UTC (rev 124152)
+++ zc.buildout/branches/env-cache/src/zc/buildout/easy_install.py	2012-01-24 06:38:08 UTC (rev 124153)
@@ -232,33 +232,34 @@
     return index
 
 
-_envs = {}
 def _get_env(executable, path=None):
     python = _get_version(executable)
-    key = python, tuple(path)
-    env = _envs.get(key)
-    if env is None:
-        _envs[key] = env = pkg_resources.Environment(
-            search_path=path, python=python)
+    return pkg_resources.Environment(search_path=path, python=python)
 
-    env_copy = pkg_resources.Environment(search_path=[], python=python)
-    env_copy += env
-    return env_copy
 
+_dists = {}
+_orig_find_distributions = pkg_resources.find_distributions
+def find_distributions(path_item, only=False):
+    """Cache distributions on a per-path basis."""
+    key = (path_item, only)
+    if key in _dists:
+        return _dists[key]
+    dists = _dists[key] = set(
+        _orig_find_distributions(path_item, only=only))
+    return dists
+pkg_resources.find_distributions = find_distributions    
 
-def _update_envs(executable, dest):
-    python = _get_version(executable)
-    for key in _envs.keys():
-        cached_python, cached_path = key
-        if cached_python == python and dest in cached_path:
-            del _envs[key]
-            
 
-def clear_index_cache():
-    _indexes.clear()
-    _envs.clear()
+def update_dist(path_item, dist):
+    for only in (True, False):
+        key = (path_item, only)
+        if key in _dists:
+            _dists[key].add(dist)
 
 
+clear_index_cache = _indexes.clear
+
+
 if is_win32:
     # work around spawn lamosity on windows
     # XXX need safe quoting (see the subprocess.list2cmdline) and test
@@ -640,7 +641,7 @@
                 os.rename(d.location, newloc)
                 [d] = _get_env(self._executable, [newloc])[d.project_name]
                 result.append(d)
-                _update_envs(self._executable, self._dest)
+                update_dist(path_item=self._dest, dist=d)
 
             return result
 
@@ -1201,7 +1202,11 @@
             raise zc.buildout.UserError("Installing develop egg failed")
             
         result = _copyeggs(tmp3, dest, '.egg-link', undo)
-        _update_envs(executable, dest)
+        # From pkg_resources.find_on_path egg-link support
+        for line in open(result):
+            if not line.strip(): continue
+            for dist in find_distributions(os.path.join(dest ,line.rstrip())):
+                update_dist(dest, dist)
         return result
 
     finally:



More information about the checkins mailing list