Skip to content

Commit 1b8b2c8

Browse files
committed
ansible_mitogen: Rename Mitogen interpreter discovery attributes
This makes their nature and ownership/responsibility much more explicit.
1 parent d3da3ff commit 1b8b2c8

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

ansible_mitogen/mixins.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ def __init__(self, task, connection, *args, **kwargs):
103103

104104
# required for python interpreter discovery
105105
connection.templar = self._templar
106-
self._finding_python_interpreter = False
107-
self._rediscovered_python = False
106+
107+
self._mitogen_discovering_interpreter = False
108+
self._mitogen_interpreter_candidate = None
109+
self._mitogen_rediscovered_interpreter = False
108110

109111
def run(self, tmp=None, task_vars=None):
110112
"""
@@ -397,7 +399,7 @@ def _execute_module(self, module_name=None, module_args=None, tmp=None,
397399
# only cache discovered_interpreter if we're not running a rediscovery
398400
# rediscovery happens in places like docker connections that could have different
399401
# python interpreters than the main host
400-
if not self._rediscovered_python:
402+
if not self._mitogen_rediscovered_interpreter:
401403
result['ansible_facts'][self._discovered_interpreter_key] = self._discovered_interpreter
402404

403405
if self._discovery_warnings:
@@ -457,7 +459,7 @@ def _low_level_execute_command(self, cmd, sudoable=True, in_data=None,
457459
# calling exec_command until we run into the right python we'll use
458460
# chicken-and-egg issue, mitogen needs a python to run low_level_execute_command
459461
# which is required by Ansible's discover_interpreter function
460-
if self._finding_python_interpreter:
462+
if self._mitogen_discovering_interpreter:
461463
possible_pythons = [
462464
'/usr/bin/python',
463465
'python3',
@@ -484,7 +486,7 @@ def _run_cmd():
484486

485487
for possible_python in possible_pythons:
486488
try:
487-
self._possible_python_interpreter = possible_python
489+
self._mitogen_interpreter_candidate = possible_python
488490
rc, stdout, stderr = _run_cmd()
489491
# TODO: what exception is thrown?
490492
except:

ansible_mitogen/transport_config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
8787
it could be different than what's ran on the host
8888
"""
8989
# keep trying different interpreters until we don't error
90-
if action._finding_python_interpreter:
91-
return action._possible_python_interpreter
90+
if action._mitogen_discovering_interpreter:
91+
return action._mitogen_interpreter_candidate
9292

9393
if s in ['auto', 'auto_legacy', 'auto_silent', 'auto_legacy_silent']:
9494
# python is the only supported interpreter_name as of Ansible 2.8.8
@@ -102,13 +102,13 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
102102
# if we're rediscovering python then chances are we're running something like a docker connection
103103
# this will handle scenarios like running a playbook that does stuff + then dynamically creates a docker container,
104104
# then runs the rest of the playbook inside that container, and then rerunning the playbook again
105-
action._rediscovered_python = True
105+
action._mitogen_rediscovered_interpreter = True
106106

107107
# blow away the discovered_interpreter_config cache and rediscover
108108
del task_vars['ansible_facts'][discovered_interpreter_config]
109109

110110
if discovered_interpreter_config not in task_vars['ansible_facts']:
111-
action._finding_python_interpreter = True
111+
action._mitogen_discovering_interpreter = True
112112
# fake pipelining so discover_interpreter can be happy
113113
action._connection.has_pipelining = True
114114
s = ansible.executor.interpreter_discovery.discover_interpreter(
@@ -128,7 +128,7 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
128128
action._discovered_interpreter_key = discovered_interpreter_config
129129
action._discovered_interpreter = s
130130

131-
action._finding_python_interpreter = False
131+
action._mitogen_discovering_interpreter = False
132132
return s
133133

134134

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ In progress (unreleased)
2828
* :gh:issue:`1213` tests: Fix unclosed file in fd_check script
2929
* :gh:issue:`1213` :mod:`ansible_mitogen`: Don't redeclare Ansible interpreter
3030
discovery attributes
31+
* :gh:issue:`1213` :mod:`ansible_mitogen`: Rename Mitogen interpreter discovery
32+
attributes
3133

3234

3335
v0.3.21 (2025-01-20)

tests/ansible/tests/connection_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def make_connection(self):
4545
conn = self.klass(play_context, new_stdin=False)
4646
# conn functions don't fetch ActionModuleMixin objs from _get_task_vars()
4747
# through the usual walk-the-stack approach so we'll not run interpreter discovery here
48-
conn._action = mock.MagicMock(_possible_python_interpreter=testlib.base_executable())
48+
conn._action = mock.MagicMock(
49+
_mitogen_interpreter_candidate=testlib.base_executable(),
50+
)
4951
conn.on_action_run(
5052
task_vars={},
5153
delegate_to_hostname=None,

0 commit comments

Comments
 (0)