|
|
@ -310,11 +310,13 @@ class ModuleFinder(object):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
path = self._py_filename(loader.get_filename(fullname))
|
|
|
|
path = self._py_filename(loader.get_filename(fullname))
|
|
|
|
source = loader.get_source(fullname)
|
|
|
|
source = loader.get_source(fullname)
|
|
|
|
if path is not None and source is not None:
|
|
|
|
is_pkg = loader.is_package(fullname)
|
|
|
|
return path, source, loader.is_package(fullname)
|
|
|
|
|
|
|
|
except AttributeError:
|
|
|
|
except AttributeError:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if path is not None and source is not None:
|
|
|
|
|
|
|
|
return path, source, is_pkg
|
|
|
|
|
|
|
|
|
|
|
|
def _get_module_via_sys_modules(self, fullname):
|
|
|
|
def _get_module_via_sys_modules(self, fullname):
|
|
|
|
"""Attempt to fetch source code via sys.modules. This is specifically
|
|
|
|
"""Attempt to fetch source code via sys.modules. This is specifically
|
|
|
|
to support __main__, but it may catch a few more cases."""
|
|
|
|
to support __main__, but it may catch a few more cases."""
|
|
|
@ -324,22 +326,21 @@ class ModuleFinder(object):
|
|
|
|
fullname)
|
|
|
|
fullname)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
modpath = self._py_filename(getattr(module, '__file__', ''))
|
|
|
|
path = self._py_filename(getattr(module, '__file__', ''))
|
|
|
|
if not modpath:
|
|
|
|
if not path:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
is_pkg = hasattr(module, '__path__')
|
|
|
|
is_pkg = hasattr(module, '__path__')
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
source = inspect.getsource(module)
|
|
|
|
source = inspect.getsource(module)
|
|
|
|
except IOError:
|
|
|
|
except IOError:
|
|
|
|
# Work around inspect.getsourcelines() bug.
|
|
|
|
# Work around inspect.getsourcelines() bug for 0-byte __init__.py
|
|
|
|
|
|
|
|
# files.
|
|
|
|
if not is_pkg:
|
|
|
|
if not is_pkg:
|
|
|
|
raise
|
|
|
|
raise
|
|
|
|
source = '\n'
|
|
|
|
source = '\n'
|
|
|
|
|
|
|
|
|
|
|
|
return (module.__file__.rstrip('co'),
|
|
|
|
return path, source, is_pkg
|
|
|
|
source,
|
|
|
|
|
|
|
|
hasattr(module, '__path__'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_module_methods = [_get_module_via_pkgutil,
|
|
|
|
get_module_methods = [_get_module_via_pkgutil,
|
|
|
|
_get_module_via_sys_modules]
|
|
|
|
_get_module_via_sys_modules]
|
|
|
|