builtin cache reloads modules if they changed

This commit is contained in:
David Halter
2012-04-18 12:26:16 +02:00
parent 832a3cb2c0
commit f0532c6869
3 changed files with 17 additions and 4 deletions

View File

@@ -13,6 +13,8 @@ class Parser(object):
It can be instantiated with either a path or a name of the module. The path
is important for third party modules.
TODO maybe remove some code and merge it with `modules`?
:param name: The name of the module.
:param path: The path of the module.
:param sys_path: The sys.path, which is can be customizable.
@@ -67,7 +69,12 @@ class Parser(object):
""" get the parser lazy """
if not self._parser:
try:
self._parser = Parser.cache[self.name, self.path].parser
timestamp, parser = Parser.cache[self.name, self.path]
if timestamp == os.path.getmtime(self.path):
debug.dbg('hit builtin cache')
self._parser = parser
else:
raise KeyError
except KeyError:
code = self._generate_code(self.module)
try:
@@ -77,7 +84,11 @@ class Parser(object):
#open('builtin_fail', 'w').write(code)
raise
else:
Parser.cache[self.name, self.path] = self
if self.path:
p_time = os.path.getmtime(self.path)
else:
p_time = None
Parser.cache[self.name, self.path] = p_time, self._parser
return self._parser
def _generate_code(self, scope, depth=0):

View File

@@ -16,5 +16,7 @@ code = f.read()
for i in range(1):
completions = functions.complete(code, 150, 200, path)
#print '\n', ', '.join(sorted(str(c) for c in completions))
print '\n', ', '.join(sorted(str(c) for c in completions))
#print [n.name for n in completions]
#print [n.name.get_parent_until() for n in completions]
print '#', len(completions)

View File

@@ -147,4 +147,4 @@ c = b().c3()
1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request;
abc = [1,2+3]; abc[0].
import pylab
pylab.
pylab.one