diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 54c19df7..132e6e43 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -2,6 +2,7 @@ To ensure compatibility from Python ``2.7`` - ``3.x``, a module has been created. Clearly there is huge need to use conforming syntax. """ +from __future__ import print_function import errno import sys import os @@ -85,25 +86,6 @@ def find_module_py33(string, path=None, loader=None, full_name=None, is_global_s raise ImportError("Couldn't find a loader for {}".format(string)) return _from_loader(loader, string) - issss - is_package = loader.is_package(string) - if is_package: - if hasattr(loader, 'archive'): - module_file = DummyFile(loader, string) - else: - module_file = None - else: - try: - module_path = loader.get_filename(string) - module_file = DummyFile(loader, string) - except AttributeError: - try: - module_file = DummyFile(loader, string) - except AttributeError: - module_path = string - module_file = None - - return module_file, module_path, is_package class ZipFileIO(KnownContentFileIO): @@ -154,9 +136,9 @@ def _get_source(loader, fullname): path = loader.get_filename(fullname) try: return loader.get_data(path) - except OSError as exc: + except OSError: raise ImportError('source not available through get_data()', - name=fullname) from exc + name=fullname) def find_module_pre_py3(string, path=None, full_name=None, is_global_search=True): @@ -166,9 +148,14 @@ def find_module_pre_py3(string, path=None, full_name=None, is_global_search=True try: module_file, module_path, description = imp.find_module(string, path) module_type = description[2] + is_package = module_type is imp.PKG_DIRECTORY + if module_file is None: + code = None + return None, is_package + with module_file: code = module_file.read() - return KnownContentFileIO(module_path, code), module_type is imp.PKG_DIRECTORY + return KnownContentFileIO(module_path, code), is_package except ImportError: pass @@ -178,6 +165,7 @@ def find_module_pre_py3(string, path=None, full_name=None, is_global_search=True loader = pkgutil.get_importer(item) if loader: loader = loader.find_module(string) + print_to_stderr('lalala') return _from_loader(loader, string) raise ImportError("No module named {}".format(string)) @@ -401,9 +389,7 @@ def no_unicode_pprint(dct): def print_to_stderr(*args): if is_py3: - eval("print(*args, file=sys.stderr)") - else: - print >> sys.stderr, args + print(*args, file=sys.stderr) sys.stderr.flush() diff --git a/jedi/evaluate/compiled/subprocess/functions.py b/jedi/evaluate/compiled/subprocess/functions.py index 10adcf17..1064ce50 100644 --- a/jedi/evaluate/compiled/subprocess/functions.py +++ b/jedi/evaluate/compiled/subprocess/functions.py @@ -1,8 +1,6 @@ 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 @@ -44,47 +42,6 @@ def get_module_info(evaluator, sys_path=None, full_name=None, **kwargs): if sys_path is not None: sys.path = temp - # 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')): - # Unfortunately we are reading unicode here already, not byes. - # 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() - else: - # Read the code with a binary file, because the binary file - # might not be proper unicode. This is handled by the parser - # wrapper. - with open(module_path, 'rb') as f: - code = f.read() - - module_file.close() - - return code, cast_path(module_path), is_pkg - def list_module_names(evaluator, search_path): return [