1
0
forked from VimPlug/jedi

Created find_module helper to handle compatibility with python 3.3

Moved package checking logic in follow_str function

Created find_module compatibility helper method

Conditional implementation of load_module for python 3.3
This commit is contained in:
Aldo Stracquadanio
2013-03-22 13:39:07 +00:00
parent 6c998067e8
commit d481a7aae4
2 changed files with 56 additions and 7 deletions
+14 -6
View File
@@ -21,6 +21,7 @@ import imp
import sys
import itertools
from jedi._compatibility import find_module
from jedi import modules
from jedi import debug
from jedi import parsing_representation as pr
@@ -238,20 +239,22 @@ class ImportPath(pr.Base):
global imports_processed
imports_processed += 1
importing = None
if path is not None:
return imp.find_module(string, [path])
importing = find_module(string, [path])
else:
debug.dbg('search_module', string, self.file_path)
# Override the sys.path. It works only good that way.
# Injecting the path directly into `find_module` did not work.
sys.path, temp = sys_path_mod, sys.path
try:
i = imp.find_module(string)
importing = find_module(string)
except ImportError:
sys.path = temp
raise
sys.path = temp
return i
return importing
if self.file_path:
sys_path_mod = list(self.sys_path_with_modifications())
@@ -259,6 +262,9 @@ class ImportPath(pr.Base):
else:
sys_path_mod = list(modules.get_sys_path())
def module_not_found():
raise ModuleNotFound('The module you searched has not been found')
current_namespace = (None, None, None)
# now execute those paths
rest = []
@@ -277,12 +283,14 @@ class ImportPath(pr.Base):
if current_namespace[1]:
rest = self.import_path[i:]
else:
raise ModuleNotFound(
'The module you searched has not been found')
module_not_found()
if current_namespace == (None, None, False):
module_not_found()
sys_path_mod.pop(0) # TODO why is this here?
path = current_namespace[1]
is_package_directory = current_namespace[2][2] == imp.PKG_DIRECTORY
is_package_directory = current_namespace[2]
f = None
if is_package_directory or current_namespace[0]: