8000 gh-96305: Fix AIX build by avoiding subprocess during bootstrap (#96429) · python/cpython@ba4731d · GitHub
[go: up one dir, main page]

Skip to content

Commit ba4731d

Browse files
authored
gh-96305: Fix AIX build by avoiding subprocess during bootstrap (#96429)
* Fix AIX build by avoiding `subprocess` during bootstrap.
1 parent 24cbc7a commit ba4731d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+2
lines changed

Lib/_aix_support.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
"""Shared AIX support functions."""
22

3-
import subprocess
43
import sys
54
import sysconfig
65

76

7+
# Taken from _osx_support _read_output function
8+
def _read_cmd_output(commandstring, capture_stderr=False):
9+
"""Output from successful command execution or None"""
10+
# Similar to os.popen(commandstring, "r").read(),
11+
# but without actually using os.popen because that
12+
# function is not usable during python bootstrap.
13+
import os
14+
import contextlib
15+
fp = open("/tmp/_aix_support.%s"%(
16+
os.getpid(),), "w+b")
17+
18+
with contextlib.closing(fp) as fp:
19+
if capture_stderr:
20+
cmd = "%s >'%s' 2>&1" % (commandstring, fp.name)
21+
else:
22+
cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
23+
return fp.read() if not os.system(cmd) else None
24+
25+
826
def _aix_tag(vrtl, bd):
927
# type: (List[int], int) -> str
1028
# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
@@ -30,7 +48,12 @@ def _aix_bos_rte():
3048
If no builddate is found give a value that will satisfy pep425 related queries
3149
"""
3250
# All AIX systems to have lslpp installed in this location
33-
out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.rte"])
51+
# subprocess may not be available during python bootstrap
52+
try:
53+
import subprocess
54+
out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.rte"])
55+
except ImportError:
56+
out = _read_cmd_output("/usr/bin/lslpp -Lqc bos.rte")
3457
out = out.decode("utf-8")
3558
out = out.strip().split(":") # type: ignore
3659
_bd = int(out[-1]) if out[-1] != '' else 9988
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``_aix_support`` now uses a simple code to get platform details rather than
2+
the now non-existent ``_bootsubprocess`` during bootstrap.

0 commit comments

Comments
 (0)
0