[py-svn] r34414 - py/dist/py/path/local
fijal at codespeak.net
fijal at codespeak.net
Thu Nov 9 15:20:09 CET 2006
Author: fijal
Date: Thu Nov 9 15:20:05 2006
New Revision: 34414
Modified:
py/dist/py/path/local/local.py
Log:
Make pyimport cache modules. This speeds up py.test --collectonly about 3 times.
Modified: py/dist/py/path/local/local.py
==============================================================================
--- py/dist/py/path/local/local.py (original)
+++ py/dist/py/path/local/local.py Thu Nov 9 15:20:05 2006
@@ -19,6 +19,8 @@
""" Local path implementation offering access/modification
methods similar to os.path.
"""
+ _path_cache = {}
+
sep = os.sep
class Checkers(common.FSCheckers):
def _stat(self):
@@ -53,6 +55,10 @@
Note also that passing in a local path object will simply return
the exact same path object. Use new() to get a new copy.
"""
+ #try:
+ # return cls._path_cache[path]
+ #except KeyError:
+ # pass
if isinstance(path, common.FSPathBase):
if path.__class__ == cls:
return path
@@ -68,6 +74,7 @@
"can only pass None, Path instances "
"or non-empty strings to LocalPath")
assert isinstance(self.strpath, str)
+ #cls._path_cache[path] = self
return self
def __hash__(self):
@@ -120,7 +127,7 @@
obj.strpath = os.path.normpath(
"%(drive)s%(dirname)s%(sep)s%(basename)s" % kw)
return obj
-
+
def _getbyspec(self, spec):
""" return a sequence of specified path parts. 'spec' is
a comma separated string containing path part names.
@@ -374,6 +381,11 @@
#print "trying to import", self
pkgpath = None
if modname is None:
+ if modname is None:
+ try:
+ return self.module
+ except AttributeError:
+ pass
pkgpath = self.pypkgpath()
if pkgpath is not None:
if ensuresyspath:
@@ -394,7 +406,9 @@
if ensuresyspath:
self._prependsyspath(self.dirpath())
modname = self.purebasename
- return __import__(modname, None, None, ['__doc__'])
+ mod = __import__(modname, None, None, ['__doc__'])
+ self.module = mod
+ return mod
else:
try:
return sys.modules[modname]
More information about the pytest-commit
mailing list