From 518324c371fa633eeead8bf85e225a6d89540cea Mon Sep 17 00:00:00 2001 From: Steven Robertson Date: Sat, 24 Oct 2020 17:28:26 -0700 Subject: [PATCH] fix regression in Darwin 19 (OSX 10.15+) ansible python interpreter detection --- mitogen/parent.py | 6 +++++- tests/ansible/lib/modules/test_echo_module.py | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mitogen/parent.py b/mitogen/parent.py index 630e3de1..3b4dca8a 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -42,6 +42,7 @@ import heapq import inspect import logging import os +import platform import re import signal import socket @@ -1434,7 +1435,10 @@ class Connection(object): os.close(r) os.close(W) os.close(w) - if sys.platform == 'darwin' and sys.executable == '/usr/bin/python': + # this doesn't apply anymore to Mac OSX 10.15+ (Darwin 19+), new interpreter looks like this: + # /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python + if sys.platform == 'darwin' and sys.executable == '/usr/bin/python' and \ + int(platform.release()[:2]) < 19: sys.executable += sys.version[:3] os.environ['ARGV0']=sys.executable os.execl(sys.executable,sys.executable+'(mitogen:CONTEXT_NAME)') diff --git a/tests/ansible/lib/modules/test_echo_module.py b/tests/ansible/lib/modules/test_echo_module.py index beb4cc70..37ab655c 100644 --- a/tests/ansible/lib/modules/test_echo_module.py +++ b/tests/ansible/lib/modules/test_echo_module.py @@ -9,6 +9,7 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +import platform import sys from ansible.module_utils.basic import AnsibleModule @@ -23,7 +24,12 @@ def main(): result['ansible_facts'] = module.params['facts'] # revert the Mitogen OSX tweak since discover_interpreter() doesn't return this info if sys.platform == 'darwin' and sys.executable != '/usr/bin/python': - sys.executable = sys.executable[:-3] + if int(platform.release()[:2]) < 19: + sys.executable = sys.executable[:-3] + else: + # only for tests to check version of running interpreter -- Mac 10.15+ changed python2 + # so it looks like it's /usr/bin/python but actually it's /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python + sys.executable = "/usr/bin/python" result['running_python_interpreter'] = sys.executable module.exit_json(**result)