Skip to content

Commit d6675fe

Browse files
bpo-42504: Ensure that get_config_var('MACOSX_DEPLOYMENT_TARGET') is a string (GH-24341) (GH-24410)
* bpo-42504: Ensure that get_config_var('MACOSX_DEPLOYMENT_TARGET') is a string (cherry picked from commit 49926cf) Co-authored-by: Ronald Oussoren <[email protected]>
1 parent 3c8d693 commit d6675fe

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

Lib/distutils/spawn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0):
5454
global _cfg_target, _cfg_target_split
5555
if _cfg_target is None:
5656
from distutils import sysconfig
57-
_cfg_target = str(sysconfig.get_config_var(
58-
'MACOSX_DEPLOYMENT_TARGET') or '')
57+
_cfg_target = sysconfig.get_config_var(
58+
'MACOSX_DEPLOYMENT_TARGET') or ''
5959
if _cfg_target:
6060
_cfg_target_split = [int(x) for x in _cfg_target.split('.')]
6161
if _cfg_target:

Lib/distutils/tests/test_build_ext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def test_deployment_target_higher_ok(self):
455455
deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
456456
if deptarget:
457457
# increment the minor version number (i.e. 10.6 -> 10.7)
458-
deptarget = [int(x) for x in str(deptarget).split('.')]
458+
deptarget = [int(x) for x in deptarget.split('.')]
459459
deptarget[-1] += 1
460460
deptarget = '.'.join(str(i) for i in deptarget)
461461
self._try_compile_deployment_target('<', deptarget)
@@ -488,7 +488,7 @@ def _try_compile_deployment_target(self, operator, target):
488488

489489
# get the deployment target that the interpreter was built with
490490
target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
491-
target = tuple(map(int, str(target).split('.')[0:2]))
491+
target = tuple(map(int, target.split('.')[0:2]))
492492
# format the target value as defined in the Apple
493493
# Availability Macros. We can't use the macro names since
494494
# at least one value we test with will not exist yet.

Lib/sysconfig.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
'parse_config_h',
1919
]
2020

21+
# Keys for get_config_var() that are never converted to Python integers.
22+
_ALWAYS_STR = {
23+
'MACOSX_DEPLOYMENT_TARGET',
24+
}
25+
2126
_INSTALL_SCHEMES = {
2227
'posix_prefix': {
2328
'stdlib': '{installed_base}/{platlibdir}/python{py_version_short}',
@@ -240,6 +245,9 @@ def _parse_makefile(filename, vars=None):
240245
notdone[n] = v
241246
else:
242247
try:
248+
if n in _ALWAYS_STR:
249+
raise ValueError
250+
243251
v = int(v)
244252
except ValueError:
245253
# insert literal `$'
@@ -298,6 +306,8 @@ def _parse_makefile(filename, vars=None):
298306
notdone[name] = value
299307
else:
300308
try:
309+
if name in _ALWAYS_STR:
310+
raise ValueError
301311
value = int(value)
302312
except ValueError:
303313
done[name] = value.strip()
@@ -459,6 +469,8 @@ def parse_config_h(fp, vars=None):
459469
if m:
460470
n, v = m.group(1, 2)
461471
try:
472+
if n in _ALWAYS_STR:
473+
raise ValueError
462474
v = int(v)
463475
except ValueError:
464476
pass

Lib/test/test_posix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ def test_getgroups(self):
10451045
if sys.platform == 'darwin':
10461046
import sysconfig
10471047
dt = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') or '10.0'
1048-
if tuple(int(n) for n in str(dt).split('.')[0:2]) < (10, 6):
1048+
if tuple(int(n) for n in dt.split('.')[0:2]) < (10, 6):
10491049
raise unittest.SkipTest("getgroups(2) is broken prior to 10.6")
10501050

10511051
# 'id -G' and 'os.getgroups()' should return the same
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ensure that the value of
2+
sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') is always a string,
3+
even in when the value is parsable as an integer.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ def detect_readline_curses(self):
10131013
os_release = int(os.uname()[2].split('.')[0])
10141014
dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
10151015
if (dep_target and
1016-
(tuple(int(n) for n in str(dep_target).split('.')[0:2])
1016+
(tuple(int(n) for n in dep_target.split('.')[0:2])
10171017
< (10, 5) ) ):
10181018
os_release = 8
10191019
if os_release < 9:

0 commit comments

Comments
 (0)