From e4aedf3e48007f70ec00a83f17a3419845dba831 Mon Sep 17 00:00:00 2001 From: Ayappan P Date: Tue, 30 Aug 2022 09:33:54 -0400 Subject: [PATCH 1/2] Fix AIX build by avoiding subprocess during bootstrap --- Lib/_aix_support.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Lib/_aix_support.py b/Lib/_aix_support.py index 1d8482ff382507..dadc75c2bf4200 100644 --- a/Lib/_aix_support.py +++ b/Lib/_aix_support.py @@ -3,12 +3,24 @@ import sys import sysconfig -try: - import subprocess -except ImportError: # pragma: no cover - # _aix_support is used in distutils by setup.py to build C extensions, - # before subprocess dependencies like _posixsubprocess are available. - import _bootsubprocess as subprocess + +# 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): @@ -36,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 From 5108cadaec86953702c59a222da166cd1d8a9e0f Mon Sep 17 00:00:00 2001 From: Ayappan P Date: Tue, 30 Aug 2022 10:18:35 -0400 Subject: [PATCH 2/2] Add news entry --- .../next/Build/2022-08-30-10-16-31.gh-issue-96305.274i8B.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2022-08-30-10-16-31.gh-issue-96305.274i8B.rst diff --git a/Misc/NEWS.d/next/Build/2022-08-30-10-16-31.gh-issue-96305.274i8B.rst b/Misc/NEWS.d/next/Build/2022-08-30-10-16-31.gh-issue-96305.274i8B.rst new file mode 100644 index 00000000000000..64a48da658f21f --- /dev/null +++ b/Misc/NEWS.d/next/Build/2022-08-30-10-16-31.gh-issue-96305.274i8B.rst @@ -0,0 +1,2 @@ +``_aix_support`` now uses a simple code to get platform details rather than +the now non-existent ``_bootsubprocess`` during bootstrap.