1
0
forked from VimPlug/jedi

probably finished the load_module method migration

This commit is contained in:
Dave Halter
2014-01-05 01:37:43 +01:00
parent 29e661ea74
commit 4d7349411e
6 changed files with 55 additions and 34 deletions

View File

@@ -35,10 +35,12 @@ import inspect
from jedi import common
from jedi import debug
from jedi.parser import Parser
from jedi.parser import fast
from jedi import modules
from jedi import cache
class BuiltinModule(modules.CachedModule):
class BuiltinModule(object):
"""
This module is a parser for all builtin modules, which are programmed in
C/C++. It should also work on third party modules.
@@ -69,14 +71,32 @@ class BuiltinModule(modules.CachedModule):
def __init__(self, path=None, name=None, sys_path=None):
if sys_path is None:
sys_path = modules.get_sys_path()
self.sys_path = list(sys_path)
if not name:
name = os.path.basename(path)
name = name.rpartition('.')[0] # cut file type (normally .so)
super(BuiltinModule, self).__init__(path=path, name=name)
self.name = name
self.sys_path = list(sys_path)
self.path = path and os.path.abspath(path)
self._parser = None
self._module = None
@property
def parser(self):
""" get the parser lazy """
if self._parser is None:
self._parser = cache.load_parser(self.path, self.name) \
or self._load_module()
return self._parser
def _load_module(self):
source = _generate_code(self.module, self._load_mixins())
p = self.path or self.name
p = fast.FastParser(source, p)
cache.save_parser(self.path, self.name, p)
return p
@property
def module(self):
def load_module(name, path):
@@ -118,10 +138,6 @@ class BuiltinModule(modules.CachedModule):
load_module(name, path)
return self._module
def _get_source(self):
""" Override this abstract method """
return _generate_code(self.module, self._load_mixins())
def _load_mixins(self):
"""
Load functions that are mixed in to the standard library.
@@ -158,14 +174,14 @@ class BuiltinModule(modules.CachedModule):
raise NotImplementedError()
return funcs
try:
name = self.name
# sometimes there are stupid endings like `_sqlite3.cpython-32mu`
name = re.sub(r'\..*', '', name)
name = self.name
# sometimes there are stupid endings like `_sqlite3.cpython-32mu`
name = re.sub(r'\..*', '', name)
if name == '__builtin__' and not is_py3k:
name = 'builtins'
path = os.path.dirname(os.path.abspath(__file__))
if name == '__builtin__' and not is_py3k:
name = 'builtins'
path = os.path.dirname(os.path.abspath(__file__))
try:
with open(os.path.join(path, 'mixin', name) + '.pym') as f:
s = f.read()
except IOError:

View File

@@ -83,7 +83,7 @@ def get_directory_modules_for_name(mods, name):
with open(path) as f:
source = modules.source_to_unicode(f.read())
if name in source:
return modules.Module(path, source).parser.module
return modules.load_module(path, source)
# skip non python modules
mods = set(m for m in mods if m.path is None or m.path.endswith('.py'))

View File

@@ -110,9 +110,9 @@ class ImportPath(pr.Base):
if self._is_relative_import():
rel_path = self._get_relative_path() + '/__init__.py'
with common.ignored(IOError):
m = modules.Module(rel_path)
names += m.parser.module.get_defined_names()
if os.path.exists(rel_path):
m = modules.load_module(rel_path)
names += m.get_defined_names()
else:
if on_import_stmt and isinstance(scope, pr.Module) \
and scope.path.endswith('__init__.py'):