Skip to content

Commit c846ef0

Browse files
authored
bpo-39936: _aix_support uses _bootsubprocess (GH-18970)
AIX: Fix _aix_support module when the subprocess is not available, when building Python from scratch. It now uses new private _bootsubprocess module, rather than having two implementations depending if subprocess is available or not. So _aix_support.aix_platform() result is now the same if subprocess is available or not.
1 parent 1ae9cde commit c846ef0

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

Lib/_aix_support.py

+25-35
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
11
"""Shared AIX support functions."""
22

33
import sys
4-
from sysconfig import get_config_var
4+
import sysconfig
55

6-
# subprocess is not necessarily available early in the build process
7-
# if not available, the config_vars are also definitely not available
8-
# supply substitutes to bootstrap the build
96
try:
107
import subprocess
11-
_have_subprocess = True
12-
_tmp_bd = get_config_var("AIX_BUILDDATE")
13-
_bgt = get_config_var("BUILD_GNU_TYPE")
148
except ImportError: # pragma: no cover
15-
_have_subprocess = False
16-
_tmp_bd = None
17-
_bgt = "powerpc-ibm-aix6.1.7.0"
18-
19-
# if get_config_var("AIX_BUILDDATE") was unknown, provide a substitute,
20-
# impossible builddate to specify 'unknown'
21-
_MISSING_BD = 9898
22-
try:
23-
_bd = int(_tmp_bd)
24-
except TypeError:
25-
_bd = _MISSING_BD
26-
27-
# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
28-
_sz = 32 if sys.maxsize == (2**31-1) else 64
9+
# _aix_support is used in distutils by setup.py to build C extensions,
10+
# before subprocess dependencies like _posixsubprocess are available.
11+
import _bootsubprocess as subprocess
2912

3013

3114
def _aix_tag(vrtl, bd):
3215
# type: (List[int], int) -> str
16+
# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
17+
_sz = 32 if sys.maxsize == (2**31-1) else 64
3318
# vrtl[version, release, technology_level]
3419
return "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(vrtl[0], vrtl[1], vrtl[2], bd, _sz)
3520

@@ -48,17 +33,12 @@ def _aix_bosmp64():
4833
The fileset bos.mp64 is the AIX kernel. It's VRMF and builddate
4934
reflect the current ABI levels of the runtime environment.
5035
"""
51-
if _have_subprocess:
52-
# We expect all AIX systems to have lslpp installed in this location
53-
out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.mp64"])
54-
out = out.decode("utf-8").strip().split(":") # type: ignore
55-
# Use str() and int() to help mypy see types
56-
return str(out[2]), int(out[-1])
57-
else:
58-
from os import uname
59-
60-
osname, host, release, version, machine = uname()
61-
return "{}.{}.0.0".format(version, release), _MISSING_BD
36+
# We expect all AIX systems to have lslpp installed in this location
37+
out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.mp64"])
38+
out = out.decode("utf-8")
39+
out = out.strip().split(":") # type: ignore
40+
# Use str() and int() to help mypy see types
41+
return (str(out[2]), int(out[-1]))
6242

6343

6444
def aix_platform():
@@ -87,13 +67,23 @@ def aix_platform():
8767
# extract vrtl from the BUILD_GNU_TYPE as an int
8868
def _aix_bgt():
8969
# type: () -> List[int]
90-
assert _bgt
91-
return _aix_vrtl(vrmf=_bgt)
70+
gnu_type = sysconfig.get_config_var("BUILD_GNU_TYPE")
71+
if not gnu_type:
72+
raise ValueError("BUILD_GNU_TYPE is not defined")
73+
return _aix_vrtl(vrmf=gnu_type)
9274

9375

9476
def aix_buildtag():
9577
# type: () -> str
9678
"""
9779
Return the platform_tag of the system Python was built on.
9880
"""
99-
return _aix_tag(_aix_bgt(), _bd)
81+
# AIX_BUILDDATE is defined by configure with:
82+
# lslpp -Lcq bos.mp64 | awk -F: '{ print $NF }'
83+
build_date = sysconfig.get_config_var("AIX_BUILDDATE")
84+
try:
85+
build_date = int(build_date)
86+
except (ValueError, TypeError):
87+
raise ValueError(f"AIX_BUILDDATE is not defined or invalid: "
88+
f"{build_date!r}")
89+
return _aix_tag(_aix_bgt(), build_date)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AIX: Fix _aix_support module when the subprocess is not available, when
2+
building Python from scratch. It now uses new private _bootsubprocess
3+
module, rather than having two implementations depending if subprocess is
4+
available or not. So _aix_support.aix_platform() result is now the same if
5+
subprocess is available or not.

0 commit comments

Comments
 (0)