issue #477: master: ability to override ModuleResponder output.
This is needed to cope Ansible 2.3 doing weird stuff as usual. It serves up __init__.py for ansible and ansible.module_utils as hard-coded namespace packages, the real ansible/__init__.py on disk is not 2.4 compatible.
This commit is contained in:
parent
dd36450daf
commit
5135ff9068
|
@ -491,6 +491,25 @@ class ModuleFinder(object):
|
|||
e = sys.exc_info()[1]
|
||||
LOG.debug('imp.find_module(%r, %r) -> %s', modname, [pkg_path], e)
|
||||
|
||||
def add_source_override(self, fullname, path, source, is_pkg):
|
||||
"""
|
||||
Explicitly install a source cache entry, preventing usual lookup
|
||||
methods from being used.
|
||||
|
||||
Beware the value of `path` is critical when `is_pkg` is specified,
|
||||
since it directs where submodules are searched for.
|
||||
|
||||
:param str fullname:
|
||||
Name of the module to override.
|
||||
:param str path:
|
||||
Module's path as it will appear in the cache.
|
||||
:param bytes source:
|
||||
Module source code as a bytestring.
|
||||
:param bool is_pkg:
|
||||
:data:`True` if the module is a package.
|
||||
"""
|
||||
self._found_cache[fullname] = (path, source, is_pkg)
|
||||
|
||||
get_module_methods = [_get_module_via_pkgutil,
|
||||
_get_module_via_sys_modules,
|
||||
_get_module_via_parent_enumeration]
|
||||
|
@ -643,6 +662,12 @@ class ModuleResponder(object):
|
|||
def __repr__(self):
|
||||
return 'ModuleResponder(%r)' % (self._router,)
|
||||
|
||||
def add_source_override(self, fullname, path, source, is_pkg):
|
||||
"""
|
||||
See :meth:`ModuleFinder.add_source_override.
|
||||
"""
|
||||
self._finder.add_source_override(fullname, path, source, is_pkg)
|
||||
|
||||
MAIN_RE = re.compile(b(r'^if\s+__name__\s*==\s*.__main__.\s*:'), re.M)
|
||||
main_guard_msg = (
|
||||
"A child context attempted to import __main__, however the main "
|
||||
|
|
Loading…
Reference in New Issue