Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ def find_module_path_and_all(module: str, pyversion: Tuple[int, int],
try:
mod = importlib.import_module(module)
except Exception:
# Print some debugging output that might help diagnose problems.
print('=== debug dump follows ===')
traceback.print_exc()
dump_sys_path()
print('PYTHONPATH: %s' % os.getenv("PYTHONPATH"))
dump_dir(os.getcwd())
print('=== end of debug dump ===')
raise CantImport(module)
if is_c_module(mod):
return None
Expand All @@ -175,31 +168,6 @@ def find_module_path_and_all(module: str, pyversion: Tuple[int, int],
return module_path, module_all


def dump_sys_path() -> None:
print('sys.path:')
for entry in sys.path:
print(' %r' % entry)
if entry in sys.path_importer_cache:
x = sys.path_importer_cache[entry]
print(' path_importer: %r / %r' % (x, getattr(x, '__dict__', None)))
try:
print(' stat: %s ' % str(os.stat(entry)))
except Exception as e:
pass


def dump_dir(path: str) -> None:
for root, dirs, files in os.walk(os.getcwd()):
print('%s:' % root)
for d in dirs:
print(' %s/' % d)
for f in files:
path = os.path.join(root, f)
print(' %s (%d bytes)' % (f, os.path.getsize(path)))
if not dirs and not files:
print(' (empty)')


def load_python_module_info(module: str, interpreter: str) -> Tuple[str, Optional[List[str]]]:
"""Return tuple (module path, module __all__) for a Python 2 module.

Expand Down
18 changes: 11 additions & 7 deletions mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import glob
import importlib
import os.path
import shutil
import sys
Expand Down Expand Up @@ -125,7 +124,7 @@ def test_stubgen(testcase: DataDrivenTestCase) -> None:
handle.close()
# Without this we may sometimes be unable to import the module below, as importlib
# caches os.listdir() results in Python 3.3+ (Guido explained this to me).
reset_importlib_caches()
reset_importlib_cache('stubgen-test-path')
try:
if testcase.name.endswith('_import'):
generate_stub_for_module(name, out_dir, quiet=True,
Expand All @@ -145,11 +144,16 @@ def test_stubgen(testcase: DataDrivenTestCase) -> None:
shutil.rmtree(out_dir)


def reset_importlib_caches() -> None:
try:
importlib.invalidate_caches()
except (ImportError, AttributeError):
pass
def reset_importlib_cache(entry: str) -> None:
# importlib.invalidate_caches() is insufficient, since it doesn't
# clear cache entries that indicate that a directory on the path
# does not exist, which can cause failures. Just directly clear
# the sys.path_importer_cache entry ourselves. Other possible
# workarounds include always using different paths in the sys.path
# (perhaps by using the full path name) or removing the entry from
# sys.path after each run.
if entry in sys.path_importer_cache:
del sys.path_importer_cache[entry]


def load_output(dirname: str) -> List[str]:
Expand Down