Skip to content

Commit dd6d73d

Browse files
committed
mitogen.parent: Eliminate use of platform module in first stage
This reduces the size of the initial SSH command by 204 bytes, & may fix errors running Mitogen on macOS. AFAICT platform was used but not imported. Before ``` $ python ./preamble_size.py SSH command size: 833 Bootstrap (mitogen.core) size: 17007 (16.61KiB) Original Minimized Compressed mitogen.parent 97565 95.3KiB 50427 49.2KiB 51.7% 12689 12.4KiB 13.0% mitogen.fork 8436 8.2KiB 4130 4.0KiB 49.0% 1648 1.6KiB 19.5% mitogen.ssh 10892 10.6KiB 6952 6.8KiB 63.8% 2113 2.1KiB 19.4% mitogen.sudo 12089 11.8KiB 5924 5.8KiB 49.0% 2249 2.2KiB 18.6% mitogen.select 12325 12.0KiB 2929 2.9KiB 23.8% 964 0.9KiB 7.8% mitogen.service 41644 40.7KiB 22431 21.9KiB 53.9% 5886 5.7KiB 14.1% mitogen.fakessh 15599 15.2KiB 8011 7.8KiB 51.4% 2624 2.6KiB 16.8% mitogen.master 48732 47.6KiB 24569 24.0KiB 50.4% 6768 6.6KiB 13.9% ``` After ``` $ python preamble_size.py SSH command size: 629 Bootstrap (mitogen.core) size: 17007 (16.61KiB) Original Minimized Compressed mitogen.parent 97543 95.3KiB 50357 49.2KiB 51.6% 12665 12.4KiB 13.0% mitogen.fork 8436 8.2KiB 4130 4.0KiB 49.0% 1648 1.6KiB 19.5% mitogen.ssh 10892 10.6KiB 6952 6.8KiB 63.8% 2113 2.1KiB 19.4% mitogen.sudo 12089 11.8KiB 5924 5.8KiB 49.0% 2249 2.2KiB 18.6% mitogen.select 12325 12.0KiB 2929 2.9KiB 23.8% 964 0.9KiB 7.8% mitogen.service 41644 40.7KiB 22431 21.9KiB 53.9% 5886 5.7KiB 14.1% mitogen.fakessh 15599 15.2KiB 8011 7.8KiB 51.4% 2624 2.6KiB 16.8% mitogen.master 48732 47.6KiB 24569 24.0KiB 50.4% 6768 6.6KiB 13.9% ```
1 parent 59e6fe5 commit dd6d73d

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ v0.3.1.dev0 (unreleased)
2525
* :gh:issue:`869` Continuous Integration tests are now run with Tox
2626
* :gh:issue:`869` Continuous Integration tests now cover CentOS 6 & 8, Debian 9 & 11, Ubuntu 16.04 & 20.04
2727
* :gh:issue:`860` Add initial support for podman connection (w/o Ansible support yet)
28+
* :gh:issue:`873` `python -c ...` first stage no longer uses :py:mod:`platform`` to detect the macOS release
2829

2930

3031
v0.3.0 (2021-11-24)

mitogen/parent.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import inspect
4343
import logging
4444
import os
45-
import platform
4645
import re
4746
import signal
4847
import socket
@@ -1410,9 +1409,12 @@ def __repr__(self):
14101409
# their respective values.
14111410
# * CONTEXT_NAME must be prefixed with the name of the Python binary in
14121411
# order to allow virtualenvs to detect their install prefix.
1413-
# * For Darwin, OS X installs a craptacular argv0-introspecting Python
1414-
# version switcher as /usr/bin/python. Override attempts to call it
1415-
# with an explicit call to python2.7
1412+
# * macOS <= 10.14 (Darwin <= 18) install an unreliable Python version
1413+
# switcher as /usr/bin/python, which introspects argv0. To workaround
1414+
# it we redirect attempts to call /usr/bin/python with an explicit
1415+
# call to /usr/bin/python2.7. macOS 10.15+ (Darwin 19+) removed it.
1416+
# On these versions /usr/bin/python is a symlink to
1417+
# /System/Library/Frameworks/Python.framework/Versions/2.7/.../Python
14161418
#
14171419
# Locals:
14181420
# R: read side of interpreter stdin.
@@ -1435,11 +1437,7 @@ def _first_stage():
14351437
os.close(r)
14361438
os.close(W)
14371439
os.close(w)
1438-
# this doesn't apply anymore to Mac OSX 10.15+ (Darwin 19+), new interpreter looks like this:
1439-
# /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
1440-
if sys.platform == 'darwin' and sys.executable == '/usr/bin/python' and \
1441-
int(platform.release()[:2]) < 19:
1442-
sys.executable += sys.version[:3]
1440+
if sys.executable+sys.platform=='/usr/bin/pythondarwin'and os.uname()[2]<'19':sys.executable+='2.7'
14431441
os.environ['ARGV0']=sys.executable
14441442
os.execl(sys.executable,sys.executable+'(mitogen:CONTEXT_NAME)')
14451443
os.write(1,'MITO000\n'.encode())

0 commit comments

Comments
 (0)