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

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎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-
importsubprocess
43
importsys
54
importsysconfig
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+
importos
14+
importcontextlib
15+
fp=open("/tmp/_aix_support.%s"%(
16+
os.getpid(),), "w+b")
17+
18+
withcontextlib.closing(fp) asfp:
19+
ifcapture_stderr:
20+
cmd="%s >'%s' 2>&1"% (commandstring, fp.name)
21+
else:
22+
cmd="%s 2>/dev/null >'%s'"% (commandstring, fp.name)
23+
returnfp.read() ifnotos.system(cmd) elseNone
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+
importsubprocess
54+
out=subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.rte"])
55+
exceptImportError:
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]) ifout[-1] !=''else9988
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)