summaryrefslogtreecommitdiffstats
path: root/Lib/_aix_support.py
diff options
context:
space:
mode:
authorAyappan Perumal <ayappap2@in.ibm.com>2023-02-02 20:30:49 (GMT)
committerGitHub <noreply@github.com>2023-02-02 20:30:49 (GMT)
commitba4731d149185894c77d201bc5804da90ff45eee (patch)
tree59ecf396e410a1ba3467be0c816946611837761c /Lib/_aix_support.py
parent24cbc7a2a09bf22ff8122c1d50135e1c56622c95 (diff)
downloadcpython-ba4731d149185894c77d201bc5804da90ff45eee.zip
cpython-ba4731d149185894c77d201bc5804da90ff45eee.tar.gz
cpython-ba4731d149185894c77d201bc5804da90ff45eee.tar.bz2
gh-96305: Fix AIX build by avoiding subprocess during bootstrap (#96429)
* Fix AIX build by avoiding `subprocess` during bootstrap.
Diffstat (limited to 'Lib/_aix_support.py')
-rw-r--r--Lib/_aix_support.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/Lib/_aix_support.py b/Lib/_aix_support.py
index 18533e7..dadc75c 100644
--- a/Lib/_aix_support.py
+++ b/Lib/_aix_support.py
@@ -1,10 +1,28 @@
"""Shared AIX support functions."""
-import subprocess
import sys
import sysconfig
+# Taken from _osx_support _read_output function
+def _read_cmd_output(commandstring, capture_stderr=False):
+ """Output from successful command execution or None"""
+ # Similar to os.popen(commandstring, "r").read(),
+ # but without actually using os.popen because that
+ # function is not usable during python bootstrap.
+ import os
+ import contextlib
+ fp = open("/tmp/_aix_support.%s"%(
+ os.getpid(),), "w+b")
+
+ with contextlib.closing(fp) as fp:
+ if capture_stderr:
+ cmd = "%s >'%s' 2>&1" % (commandstring, fp.name)
+ else:
+ cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
+ return fp.read() if not os.system(cmd) else None
+
+
def _aix_tag(vrtl, bd):
# type: (List[int], int) -> str
# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
@@ -30,7 +48,12 @@ def _aix_bos_rte():
If no builddate is found give a value that will satisfy pep425 related queries
"""
# All AIX systems to have lslpp installed in this location
- out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.rte"])
+ # subprocess may not be available during python bootstrap
+ try:
+ import subprocess
+ out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.rte"])
+ except ImportError:
+ out = _read_cmd_output("/usr/bin/lslpp -Lqc bos.rte")
out = out.decode("utf-8")
out = out.strip().split(":") # type: ignore
_bd = int(out[-1]) if out[-1] != '' else 9988