ansible_mitogen: Fix ModuleNotFoundError: No module named 'ansible_mitogen'

Loading the ansible_mitogen Ansible plugins apparently doesn't follow the same
rules as importing a Python module. So sys.path manipulations in __init__.py
weren't fired when Ansible tried to load the plugins from a /custom/path that
wasn't already on sys.path.

This wasn't picked up by the test because CI always installs Mitogen as a
Python package (in a virtual env).

This reverses 6145508312.
pull/1352/head
Alex Willmer 4 weeks ago
parent 2305446ab8
commit 85069b28cd

@ -1,11 +0,0 @@
# SPDX-FileCopyrightText: 2025 Mitogen authors <https://github.com/mitogen-hq>
# SPDX-License-Identifier: BSD-3-Clause
# !mitogen: minify_safe
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -30,8 +30,16 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
import ansible.errors
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection
import ansible_mitogen.loaders

@ -30,6 +30,12 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection
import ansible_mitogen.process

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,9 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
from ansible.plugins.connection.ssh import (
DOCUMENTATION as _ansible_ssh_DOCUMENTATION,
)
@ -44,6 +47,10 @@ DOCUMENTATION = """
options:
""" + _ansible_ssh_DOCUMENTATION.partition('options:\n')[2]
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection
import ansible_mitogen.loaders

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -29,6 +29,14 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.connection

@ -1,11 +0,0 @@
# SPDX-FileCopyrightText: 2025 Mitogen authors <https://github.com/mitogen-hq>
# SPDX-License-Identifier: BSD-3-Clause
# !mitogen: minify_safe
import os
import sys
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))

@ -29,6 +29,8 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
#
# This is not the real Strategy implementation module, it simply exists as a
@ -45,6 +47,11 @@ __metaclass__ = type
# debuggers and isinstance() work predictably.
#
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.strategy
import ansible.plugins.strategy.linear

@ -29,6 +29,8 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
#
# This is not the real Strategy implementation module, it simply exists as a
@ -45,6 +47,11 @@ __metaclass__ = type
# debuggers and isinstance() work predictably.
#
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.loaders
import ansible_mitogen.strategy

@ -29,6 +29,8 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
#
# This is not the real Strategy implementation module, it simply exists as a
@ -45,6 +47,11 @@ __metaclass__ = type
# debuggers and isinstance() work predictably.
#
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.loaders
import ansible_mitogen.strategy

@ -29,6 +29,8 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
#
# This is not the real Strategy implementation module, it simply exists as a
@ -45,6 +47,11 @@ __metaclass__ = type
# debuggers and isinstance() work predictably.
#
try:
import ansible_mitogen
except ImportError:
sys.path.insert(0, os.path.abspath(os.path.join(__file__, '../../../..')))
import ansible_mitogen.loaders
import ansible_mitogen.strategy

@ -21,6 +21,9 @@ To avail of fixes in an unreleased version, please download a ZIP file
In progress (unreleased)
------------------------
* :gh:issue:`1350` :mod:`ansible_mitogen`: Fix regression when loading plugins
from ``/custom/path/to/mitogen``
v0.3.30 (2025-10-30)
--------------------

Loading…
Cancel
Save