forked from VimPlug/jedi
Fix test_imports tests, now zip imports work again
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
from parso.file_io import KnownContentFileIO
|
||||
|
||||
from jedi._compatibility import find_module, cast_path, force_unicode, \
|
||||
iter_modules, all_suffixes, print_to_stderr
|
||||
from jedi.evaluate.compiled import access
|
||||
@@ -29,23 +31,40 @@ def create_simple_object(evaluator, obj):
|
||||
|
||||
|
||||
def get_module_info(evaluator, sys_path=None, full_name=None, **kwargs):
|
||||
"""
|
||||
Returns Tuple[Union[NamespaceInfo, FileIO, None], Optional[bool]]
|
||||
"""
|
||||
if sys_path is not None:
|
||||
sys.path, temp = sys_path, sys.path
|
||||
try:
|
||||
module_file, module_path, is_pkg = find_module(full_name=full_name, **kwargs)
|
||||
return find_module(full_name=full_name, **kwargs)
|
||||
except ImportError:
|
||||
return None, None, None
|
||||
return None, None
|
||||
finally:
|
||||
if sys_path is not None:
|
||||
sys.path = temp
|
||||
|
||||
code = None
|
||||
# Unfortunately we are reading unicode here already, not bytes.
|
||||
# It seems however hard to get bytes, because the zip importer
|
||||
# logic just unpacks the zip file and returns a file descriptor
|
||||
# that we cannot as easily access. Therefore we just read it as
|
||||
# a string.
|
||||
code = module_file.read()
|
||||
module_path = cast_path(module_path)
|
||||
if module_path.endswith(('.zip', '.egg')):
|
||||
file_io = ZipFileIO(module_path, code, x)
|
||||
else:
|
||||
file_io = KnownContentFileIO(module_path, code)
|
||||
return code, module_path, is_pkg
|
||||
if is_pkg:
|
||||
# In this case, we don't have a file yet. Search for the
|
||||
# __init__ file.
|
||||
if module_path.endswith(('.zip', '.egg')):
|
||||
code = module_file.loader.get_source(full_name)
|
||||
print(module_path)
|
||||
else:
|
||||
print('xxxx')
|
||||
raise 1
|
||||
module_path = _get_init_path(module_path)
|
||||
elif module_file:
|
||||
if module_path.endswith(('.zip', '.egg')):
|
||||
|
||||
Reference in New Issue
Block a user