From e32d812769aaa96c82aa455ce415fc69e913b9d3 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Fri, 16 Feb 2018 12:03:43 +0545 Subject: [PATCH] core: add a nasty hack for Ansible modules. --- mitogen/core.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mitogen/core.py b/mitogen/core.py index 2e1ad8aa..b2b7e0df 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -546,7 +546,13 @@ class Importer(object): self._present[fullname] = pkg_present else: mod.__package__ = fullname.rpartition('.')[0] or None - code = compile(self.get_source(fullname), mod.__file__, 'exec') + + # TODO: monster hack: work around modules now being imported as their + # actual name, so when Ansible "apt.py" tries to "import apt", it gets + # itself. Instead force absolute imports during compilation. + flags = 0x4000 if fullname.startswith('ansible') else 0 + source = self.get_source(fullname) + code = compile(source, mod.__file__, 'exec', flags, True) exec code in vars(mod) return mod