From 3126031ff2b7d6ba141478ef86bfed0e926eda36 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 7 Jan 2014 15:20:00 +0100 Subject: [PATCH] move module checking again - probably the last time (resolves an import issue) --- jedi/api.py | 5 ++--- jedi/evaluate/dynamic.py | 3 ++- jedi/evaluate/helpers.py | 48 ---------------------------------------- jedi/evaluate/imports.py | 45 +++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 52 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index 6e4aa25a..9f6a1da5 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -744,7 +744,7 @@ def usages(evaluator, definitions, search_name, mods): compare_definitions = compare_array(definitions) mods |= set([d.get_parent_until() for d in definitions]) names = [] - for m in helpers.get_modules_containing_name(mods, search_name): + for m in imports.get_modules_containing_name(mods, search_name): try: stmts = m.used_names[search_name] except KeyError: @@ -766,8 +766,7 @@ def usages(evaluator, definitions, search_name, mods): if set(f) & set(definitions): names.append(api_classes.Usage(evaluator, name_part, stmt)) else: - for call in helpers.scan_statements(stmt, search_name, - assignment_details=True): + for call in helpers.scan_statement_for_calls(stmt, search_name, assignment_details=True): names += check_call(call) return names diff --git a/jedi/evaluate/dynamic.py b/jedi/evaluate/dynamic.py index 767913da..b01c0ce5 100644 --- a/jedi/evaluate/dynamic.py +++ b/jedi/evaluate/dynamic.py @@ -55,6 +55,7 @@ from jedi.parser import representation as pr from jedi import settings from jedi.evaluate import helpers from jedi.evaluate.cache import memoize_default +from jedi.evaluate import imports # This is something like the sys.path, but only for searching params. It means # that this is the order in which Jedi searches params. @@ -173,7 +174,7 @@ def search_params(evaluator, param): result = [] # This is like backtracking: Get the first possible result. - for mod in helpers.get_modules_containing_name([current_module], func_name): + for mod in imports.get_modules_containing_name([current_module], func_name): result = get_params_for_module(mod) if result: break diff --git a/jedi/evaluate/helpers.py b/jedi/evaluate/helpers.py index 131347a5..cf2cf916 100644 --- a/jedi/evaluate/helpers.py +++ b/jedi/evaluate/helpers.py @@ -1,55 +1,7 @@ -import os import copy -from jedi import cache from jedi import common from jedi.parser import representation as pr -from jedi.common import source_to_unicode -from jedi import settings - - -def get_modules_containing_name(mods, name): - """ - Search a name in the directories of modules. - """ - def check_python_file(path): - try: - return cache.parser_cache[path].parser.module - except KeyError: - try: - return check_fs(path) - except IOError: - return None - - def check_fs(path): - with open(path) as f: - source = source_to_unicode(f.read()) - if name in source: - from jedi.evaluate import imports - return imports.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')) - mod_paths = set() - for m in mods: - mod_paths.add(m.path) - yield m - - if settings.dynamic_params_for_other_modules: - paths = set(settings.additional_dynamic_modules) - for p in mod_paths: - if p is not None: - d = os.path.dirname(p) - for entry in os.listdir(d): - if entry not in mod_paths: - if entry.endswith('.py'): - paths.add(d + os.path.sep + entry) - - for p in sorted(paths): - # make testing easier, sort it - same results on every interpreter - c = check_python_file(p) - if c is not None and c not in mods: - yield c def fast_parent_copy(obj): diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index e2a95346..c2aa22f7 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -25,6 +25,8 @@ from jedi import cache from jedi.parser import fast from jedi.parser import representation as pr from jedi.evaluate import sys_path +from jedi import settings +from jedi.common import source_to_unicode class ModuleNotFound(Exception): @@ -414,3 +416,46 @@ def load_module(path=None, source=None, name=None): cached = cache.load_parser(path, name) return load(source) if cached is None else cached.module + + +def get_modules_containing_name(mods, name): + """ + Search a name in the directories of modules. + """ + def check_python_file(path): + try: + return cache.parser_cache[path].parser.module + except KeyError: + try: + return check_fs(path) + except IOError: + return None + + def check_fs(path): + with open(path) as f: + source = source_to_unicode(f.read()) + if name in source: + return 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')) + mod_paths = set() + for m in mods: + mod_paths.add(m.path) + yield m + + if settings.dynamic_params_for_other_modules: + paths = set(settings.additional_dynamic_modules) + for p in mod_paths: + if p is not None: + d = os.path.dirname(p) + for entry in os.listdir(d): + if entry not in mod_paths: + if entry.endswith('.py'): + paths.add(d + os.path.sep + entry) + + for p in sorted(paths): + # make testing easier, sort it - same results on every interpreter + c = check_python_file(p) + if c is not None and c not in mods: + yield c