diff --git a/builtin.py b/builtin.py index 902f10b0..d0788399 100644 --- a/builtin.py +++ b/builtin.py @@ -8,19 +8,10 @@ import parsing class CachedModule(object): cache = {} - def __init__(self, name=None, path=None, sys_path=sys.path): + def __init__(self, path=None, name=None): self.path = path - if name: - self.name = name - else: - name = os.path.basename(self.path) - self.name = name.rpartition('.')[0] # cut file type (normally .so) - self.path = os.path.dirname(self.path) - #print self.name, self.path - self._content = {} + self.name = name self._parser = None - self._module = None - self.sys_path = sys_path @property def parser(self): @@ -79,21 +70,17 @@ class Parser(CachedModule): } module_cache = {} - def __init__(self, name=None, path=None, sys_path=sys.path): - super(Parser, self).__init__(name, path) - - self.path = path - if name: - self.name = name - else: - name = os.path.basename(self.path) - self.name = name.rpartition('.')[0] # cut file type (normally .so) - self.path = os.path.dirname(self.path) + def __init__(self, path=None, name=None, sys_path=sys.path): + if not name: + name = os.path.basename(path) + name = name.rpartition('.')[0] # cut file type (normally .so) + path = os.path.dirname(path) #print self.name, self.path - self._content = {} - self._parser = None - self._module = None + super(Parser, self).__init__(path=path, name=name) + self.sys_path = sys_path + self._content = {} + self._module = None @property def module(self): diff --git a/functions.py b/functions.py index 44269533..a40d1a74 100644 --- a/functions.py +++ b/functions.py @@ -12,23 +12,23 @@ __all__ = ['complete', 'get_completion_parts', 'set_debug_function'] class FileWithCursor(modules.Module): """ Manages all files, that are parsed and caches them. - Important are the params source and module_path, one of them has to + Important are the params source and path, one of them has to be there. :param source: The source code of the file. - :param module_path: The module name of the file. + :param path: The module path of the file. :param row: The row, the user is currently in. Only important for the \ main file. """ - def __init__(self, module_path, source, row): - super(FileWithCursor, self).__init__(module_path, source) + def __init__(self, path, source, row): + super(FileWithCursor, self).__init__(path, source) self.row = row # this two are only used, because there is no nonlocal in Python 2 self._row_temp = None self._relevant_temp = None - self._parser = parsing.PyFuzzyParser(source, module_path, row) + self._parser = parsing.PyFuzzyParser(source, path, row) def get_row_path(self, column): """ Get the path under the cursor. """ diff --git a/modules.py b/modules.py index 9572a615..8bc3883a 100644 --- a/modules.py +++ b/modules.py @@ -20,39 +20,25 @@ class Module(builtin.CachedModule): Manages all files, that are parsed and caches them. :param source: The source code of the file. - :param module_path: The module path of the file. + :param path: The module path of the file. """ module_cache = {} - def __init__(self, module_path, source): + def __init__(self, path, source): + super(Module, self).__init__(path=path) self.source = source - self.module_path = module_path self._line_cache = None - self._parser = None - - @property - def parser(self): - if not self._parser: - # check the cache - try: - timestamp, _parser = Module.module_cache[self.module_path] - if timestamp == os.path.getmtime(self.module_path): - debug.dbg('hit module cache') - return _parser - except KeyError: - self._load_module() - return self._parser def _get_source(self): return self.source def _load_module(self): - self._parser = parsing.PyFuzzyParser(self.source, self.module_path) + self._parser = parsing.PyFuzzyParser(self.source, self.path) del self.source # efficiency # insert into cache - to_cache = (os.path.getmtime(self.module_path), self._parser) - Module.module_cache[self.module_path] = to_cache + to_cache = (os.path.getmtime(self.path), self._parser) + Module.module_cache[self.path] = to_cache def find_module(current_module, point_path): @@ -73,7 +59,7 @@ def find_module(current_module, point_path): else: path = None debug.dbg('search_module', string, path, - current_module.module_path) + current_module.path) try: i = imp.find_module(string, path) except ImportError: @@ -83,7 +69,7 @@ def find_module(current_module, point_path): # TODO handle relative paths - they are included in the import object current_namespace = None - module_find_path.insert(0, os.path.dirname(current_module.module_path)) + module_find_path.insert(0, os.path.dirname(current_module.path)) # now execute those paths rest = [] for i, s in enumerate(point_path): diff --git a/parsing.py b/parsing.py index ccb77829..dd07214d 100644 --- a/parsing.py +++ b/parsing.py @@ -218,7 +218,7 @@ class Scope(Simple): try: name = self.command except AttributeError: - name = self.module_path + name = self.path return "<%s: %s@%s-%s>" % \ (self.__class__.__name__, name, self.line_nr, self.line_end) @@ -226,12 +226,12 @@ class Scope(Simple): class GlobalScope(Scope): """ - The top scope, which is a module. + The top scope, which is always a module. I don't know why I didn't name it Module :-) """ - def __init__(self, module_path, docstr=''): - super(GlobalScope, self).__init__(module_path, docstr) - self.module_path = module_path + def __init__(self, path, docstr=''): + super(GlobalScope, self).__init__(path, docstr) + self.path = path self.global_vars = [] def add_global(self, name):