Skip to content

Commit 92ac716

Browse files
committed
Merge remote-tracking branch 'origin/issue590'
* origin/issue590: issue #590: disable distro test on vanilla ci: Ansible 2.8 jobs aren't running against all host types. tests: Py3.x fix. issue #590: fix test for <2.8 Ansibles. tests: Py3.x fix. issue #590: actually run Ansible test. tests: Py3.x fix. master: sysconfig did not exist until 2.7. tests: rearrange test modules again, they're used in multiple places module_finder_test: mask one more difference between unit2 vs. direct start master: fix _is_stdlib_path() failure on Ubuntu. issue #590: add dummy package for new test. issue #590: add FinderMethod docstrings. issue #590: update comment to indicate the hack is permanent issue #590: move example modules to module_finder/, fix/add tests issue #590: refactor ModuleFinder and teach it a new special case. issue #590: Ansible test for module_utils.distro use. issue #590: teach importer to handle self-replacing modules
2 parents d71d0ea + fe7c361 commit 92ac716

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+297
-111
lines changed

.ci/azure-pipelines.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ jobs:
9292
python.version: '2.7'
9393
MODE: ansible
9494
VER: 2.8.0
95-
DISTROS: debian
9695

9796
Ansible_280_35:
9897
python.version: '3.5'
9998
MODE: ansible
10099
VER: 2.8.0
101-
DISTROS: debian

ansible_mitogen/runner.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,16 @@ def _setup_imports(self):
763763
try:
764764
mitogen.core.import_module(fullname)
765765
except ImportError:
766-
# TODO: this is a huge hack to work around issue #590.
766+
# #590: Ansible 2.8 module_utils.distro is a package that
767+
# replaces itself in sys.modules with a non-package during
768+
# import. Prior to replacement, it is a real package containing
769+
# a '_distro' submodule which is used on 2.x. Given a 2.x
770+
# controller and 3.x target, the import hook never needs to run
771+
# again before this replacement occurs, and 'distro' is
772+
# replaced with a module from the stdlib. In this case as this
773+
# loop progresses to the next entry and attempts to preload
774+
# 'distro._distro', the import mechanism will fail. So here we
775+
# silently ignore any failure for it.
767776
if fullname != 'ansible.module_utils.distro._distro':
768777
raise
769778

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Enhancements
3030
<https://docs.ansible.com/ansible/latest/plugins/become.html>`_
3131
functionality, which will be addressed in a future release.
3232

33+
Fixes
34+
^^^^^
35+
36+
* `#590 <https://github.com/dw/mitogen/issues/590>`_: the importer can handle
37+
modules that replace themselves in :mod:`sys.modules` during import.
38+
3339

3440
Thanks!
3541
~~~~~~~

mitogen/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,10 @@ def load_module(self, fullname):
13551355
exec(code, vars(mod))
13561356
else:
13571357
exec('exec code in vars(mod)')
1358-
return mod
1358+
1359+
# #590: if a module replaces itself in sys.modules during import, below
1360+
# is necessary. This matches PyImport_ExecCodeModuleEx()
1361+
return sys.modules.get(fullname, mod)
13591362

13601363
def get_filename(self, fullname):
13611364
if fullname in self._cache:

0 commit comments

Comments
 (0)