[py-svn] r34622 - py/dist/py/test

fijal at codespeak.net fijal at codespeak.net
Wed Nov 15 12:00:17 CET 2006


Author: fijal
Date: Wed Nov 15 12:00:13 2006
New Revision: 34622

Modified:
   py/dist/py/test/config.py
Log:
Cache config paths.


Modified: py/dist/py/test/config.py
==============================================================================
--- py/dist/py/test/config.py	(original)
+++ py/dist/py/test/config.py	Wed Nov 15 12:00:13 2006
@@ -26,6 +26,8 @@
 class Config(object): 
     """ central hub for dealing with configuration/initialization data. """ 
     Option = optparse.Option
+    configs_cache = {}
+    values_cache = {}
 
     def __init__(self): 
         self.option = optparse.Values()
@@ -41,13 +43,25 @@
         """ return 'name' value looked up from the first conftest file 
             found up the path (including the path itself). 
         """
+        #try:
+        #    return cls.values_cache[name]
+        #except KeyError:
+        #    pass
         configpaths = guessconfigpaths(path) 
-        if trydefaultconfig: 
+        if trydefaultconfig:
             configpaths.append(defaultconfig) 
-        for p in configpaths: 
-            mod = importconfig(p) 
-            if hasattr(mod, name): 
-                return getattr(mod, name) 
+        for p in configpaths:
+            try:
+                mod = cls.configs_cache[p]
+            except KeyError:
+                mod = importconfig(p) 
+                cls.configs_cache[p] = mod
+            try:
+                retval = getattr(mod, name)
+                cls.values_cache[name] = retval
+                return retval
+            except AttributeError:
+                pass
         if default is not dummy: 
             return default 
         raise ValueError("config value not found: %r, path=%r" % (name, path))


More information about the py-svn mailing list