1
1
"""Shared AIX support functions."""
2
2
3
3
import sys
4
- from sysconfig import get_config_var
4
+ import sysconfig
5
5
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
9
6
try :
10
7
import subprocess
11
- _have_subprocess = True
12
- _tmp_bd = get_config_var ("AIX_BUILDDATE" )
13
- _bgt = get_config_var ("BUILD_GNU_TYPE" )
14
8
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
29
12
30
13
31
14
def _aix_tag (vrtl , bd ):
32
15
# 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
33
18
# vrtl[version, release, technology_level]
34
19
return "aix-{:1x}{:1d}{:02d}-{:04d}-{}" .format (vrtl [0 ], vrtl [1 ], vrtl [2 ], bd , _sz )
35
20
@@ -48,17 +33,12 @@ def _aix_bosmp64():
48
33
The fileset bos.mp64 is the AIX kernel. It's VRMF and builddate
49
34
reflect the current ABI levels of the runtime environment.
50
35
"""
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 ]))
62
42
63
43
64
44
def aix_platform ():
@@ -87,13 +67,23 @@ def aix_platform():
87
67
# extract vrtl from the BUILD_GNU_TYPE as an int
88
68
def _aix_bgt ():
89
69
# 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 )
92
74
93
75
94
76
def aix_buildtag ():
95
77
# type: () -> str
96
78
"""
97
79
Return the platform_tag of the system Python was built on.
98
80
"""
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 )
0 commit comments