master: tidy up trixxy importer syntax slightly

This commit is contained in:
David Wilson 2018-02-28 13:59:11 +05:45
parent 7080751f13
commit d348a826ff
1 changed files with 9 additions and 8 deletions

View File

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