|
|
@ -430,8 +430,8 @@ class FinderMethod(object):
|
|
|
|
|
|
|
|
|
|
|
|
def find(self, fullname):
|
|
|
|
def find(self, fullname):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Accept a canonical module name and return `(path, source, is_pkg)`
|
|
|
|
Accept a canonical module name as would be found in :data:`sys.modules`
|
|
|
|
tuples, where:
|
|
|
|
and return a `(path, source, is_pkg)` tuple, where:
|
|
|
|
|
|
|
|
|
|
|
|
* `path`: Unicode string containing path to source file.
|
|
|
|
* `path`: Unicode string containing path to source file.
|
|
|
|
* `source`: Bytestring containing source file's content.
|
|
|
|
* `source`: Bytestring containing source file's content.
|
|
|
@ -447,10 +447,13 @@ class DefectivePython3xMainMethod(FinderMethod):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Recent versions of Python 3.x introduced an incomplete notion of
|
|
|
|
Recent versions of Python 3.x introduced an incomplete notion of
|
|
|
|
importer specs, and in doing so created permanent asymmetry in the
|
|
|
|
importer specs, and in doing so created permanent asymmetry in the
|
|
|
|
:mod:`pkgutil` interface handling for the `__main__` module. Therefore
|
|
|
|
:mod:`pkgutil` interface handling for the :mod:`__main__` module. Therefore
|
|
|
|
we must handle `__main__` specially.
|
|
|
|
we must handle :mod:`__main__` specially.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def find(self, fullname):
|
|
|
|
def find(self, fullname):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Find :mod:`__main__` using its :data:`__file__` attribute.
|
|
|
|
|
|
|
|
"""
|
|
|
|
if fullname != '__main__':
|
|
|
|
if fullname != '__main__':
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
@ -477,6 +480,9 @@ class PkgutilMethod(FinderMethod):
|
|
|
|
be the only required implementation of get_module().
|
|
|
|
be the only required implementation of get_module().
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def find(self, fullname):
|
|
|
|
def find(self, fullname):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Find `fullname` using :func:`pkgutil.find_loader`.
|
|
|
|
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# Pre-'import spec' this returned None, in Python3.6 it raises
|
|
|
|
# Pre-'import spec' this returned None, in Python3.6 it raises
|
|
|
|
# ImportError.
|
|
|
|
# ImportError.
|
|
|
@ -522,10 +528,13 @@ class PkgutilMethod(FinderMethod):
|
|
|
|
|
|
|
|
|
|
|
|
class SysModulesMethod(FinderMethod):
|
|
|
|
class SysModulesMethod(FinderMethod):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Attempt to fetch source code via sys.modules. This is specifically to
|
|
|
|
Attempt to fetch source code via :data:`sys.modules`. This was originally
|
|
|
|
support __main__, but it may catch a few more cases.
|
|
|
|
specifically to support :mod:`__main__`, but it may catch a few more cases.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def find(self, fullname):
|
|
|
|
def find(self, fullname):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Find `fullname` using its :data:`__file__` attribute.
|
|
|
|
|
|
|
|
"""
|
|
|
|
module = sys.modules.get(fullname)
|
|
|
|
module = sys.modules.get(fullname)
|
|
|
|
LOG.debug('_get_module_via_sys_modules(%r) -> %r', fullname, module)
|
|
|
|
LOG.debug('_get_module_via_sys_modules(%r) -> %r', fullname, module)
|
|
|
|
if getattr(module, '__name__', None) != fullname:
|
|
|
|
if getattr(module, '__name__', None) != fullname:
|
|
|
@ -566,14 +575,17 @@ class ParentEnumerationMethod(FinderMethod):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Attempt to fetch source code by examining the module's (hopefully less
|
|
|
|
Attempt to fetch source code by examining the module's (hopefully less
|
|
|
|
insane) parent package. Required for older versions of
|
|
|
|
insane) parent package. Required for older versions of
|
|
|
|
ansible.compat.six and plumbum.colors, and Ansible 2.8
|
|
|
|
:mod:`ansible.compat.six`, :mod:`plumbum.colors`, and Ansible 2.8
|
|
|
|
ansible.module_utils.distro.
|
|
|
|
:mod:`ansible.module_utils.distro`.
|
|
|
|
|
|
|
|
|
|
|
|
For cases like module_utils.distro, this must handle cases where a package
|
|
|
|
For cases like :mod:`ansible.module_utils.distro`, this must handle cases
|
|
|
|
transmuted itself into a totally unrelated module during import and vice
|
|
|
|
where a package transmuted itself into a totally unrelated module during
|
|
|
|
versa.
|
|
|
|
import and vice versa.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def find(self, fullname):
|
|
|
|
def find(self, fullname):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
See implementation for a description of how this works.
|
|
|
|
|
|
|
|
"""
|
|
|
|
if fullname not in sys.modules:
|
|
|
|
if fullname not in sys.modules:
|
|
|
|
# Don't attempt this unless a module really exists in sys.modules,
|
|
|
|
# Don't attempt this unless a module really exists in sys.modules,
|
|
|
|
# else we could return junk.
|
|
|
|
# else we could return junk.
|
|
|
|