mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-19 20:11:12 +08:00
move load_module to imports
This commit is contained in:
@@ -56,7 +56,6 @@ import os
|
|||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi.common import source_to_unicode
|
from jedi.common import source_to_unicode
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
from jedi import modules
|
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.parser import fast as fast_parser
|
from jedi.parser import fast as fast_parser
|
||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default
|
||||||
@@ -84,7 +83,8 @@ def get_directory_modules_for_name(mods, name):
|
|||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
source = source_to_unicode(f.read())
|
source = source_to_unicode(f.read())
|
||||||
if name in source:
|
if name in source:
|
||||||
return modules.load_module(path, source)
|
from jedi.evaluate import imports
|
||||||
|
return imports.load_module(path, source)
|
||||||
|
|
||||||
# skip non python modules
|
# skip non python modules
|
||||||
mods = set(m for m in mods if m.path is None or m.path.endswith('.py'))
|
mods = set(m for m in mods if m.path is None or m.path.endswith('.py'))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from jedi._compatibility import find_module
|
|||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi import modules
|
from jedi.parser import fast
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
from jedi.evaluate import sys_path
|
from jedi.evaluate import sys_path
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ class ImportPath(pr.Base):
|
|||||||
if self._is_relative_import():
|
if self._is_relative_import():
|
||||||
rel_path = self._get_relative_path() + '/__init__.py'
|
rel_path = self._get_relative_path() + '/__init__.py'
|
||||||
if os.path.exists(rel_path):
|
if os.path.exists(rel_path):
|
||||||
m = modules.load_module(rel_path)
|
m = load_module(rel_path)
|
||||||
names += m.get_defined_names()
|
names += m.get_defined_names()
|
||||||
else:
|
else:
|
||||||
if on_import_stmt and isinstance(scope, pr.Module) \
|
if on_import_stmt and isinstance(scope, pr.Module) \
|
||||||
@@ -359,9 +359,9 @@ class ImportPath(pr.Base):
|
|||||||
else:
|
else:
|
||||||
source = current_namespace[0].read()
|
source = current_namespace[0].read()
|
||||||
current_namespace[0].close()
|
current_namespace[0].close()
|
||||||
return modules.load_module(path, source), rest
|
return load_module(path, source), rest
|
||||||
else:
|
else:
|
||||||
return modules.load_module(name=path), rest
|
return load_module(name=path), rest
|
||||||
|
|
||||||
|
|
||||||
def strip_imports(evaluator, scopes):
|
def strip_imports(evaluator, scopes):
|
||||||
@@ -395,3 +395,22 @@ def remove_star_imports(evaluator, scope, ignored_modules=()):
|
|||||||
|
|
||||||
# Filter duplicate modules.
|
# Filter duplicate modules.
|
||||||
return set(modules)
|
return set(modules)
|
||||||
|
|
||||||
|
|
||||||
|
def load_module(path=None, source=None, name=None):
|
||||||
|
def load(source):
|
||||||
|
if path is not None and path.endswith('.py'):
|
||||||
|
if source is None:
|
||||||
|
with open(path) as f:
|
||||||
|
source = f.read()
|
||||||
|
else:
|
||||||
|
# TODO refactoring remove
|
||||||
|
from jedi.evaluate import builtin
|
||||||
|
return builtin.BuiltinModule(path, name).parser.module
|
||||||
|
p = path or name
|
||||||
|
p = fast.FastParser(common.source_to_unicode(source), p)
|
||||||
|
cache.save_parser(path, name, p)
|
||||||
|
return p.module
|
||||||
|
|
||||||
|
cached = cache.load_parser(path, name)
|
||||||
|
return load(source) if cached is None else cached.module
|
||||||
|
|||||||
@@ -18,31 +18,10 @@ import sys
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi.common import source_to_unicode
|
|
||||||
from jedi.parser import tokenize
|
from jedi.parser import tokenize
|
||||||
from jedi.parser import fast
|
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
|
|
||||||
|
|
||||||
def load_module(path=None, source=None, name=None):
|
|
||||||
def load(source):
|
|
||||||
if path is not None and path.endswith('.py'):
|
|
||||||
if source is None:
|
|
||||||
with open(path) as f:
|
|
||||||
source = f.read()
|
|
||||||
else:
|
|
||||||
# TODO refactoring remove
|
|
||||||
from jedi.evaluate import builtin
|
|
||||||
return builtin.BuiltinModule(path, name).parser.module
|
|
||||||
p = path or name
|
|
||||||
p = fast.FastParser(source_to_unicode(source), p)
|
|
||||||
cache.save_parser(path, name, p)
|
|
||||||
return p.module
|
|
||||||
|
|
||||||
cached = cache.load_parser(path, name)
|
|
||||||
return load(source) if cached is None else cached.module
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleWithCursor(object):
|
class ModuleWithCursor(object):
|
||||||
"""
|
"""
|
||||||
Manages all files, that are parsed and caches them.
|
Manages all files, that are parsed and caches them.
|
||||||
|
|||||||
Reference in New Issue
Block a user