Skip to content

Commit 49926cf

Browse files
bpo-42504: Ensure that get_config_var('MACOSX_DEPLOYMENT_TARGET') is a string (GH-24341)
* bpo-42504: Ensure that get_config_var('MACOSX_DEPLOYMENT_TARGET') is a string
1 parent a776da9 commit 49926cf

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
@@ -456,7 +456,7 @@ def test_deployment_target_higher_ok(self):
456456
deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
457457
if deptarget:
458458
# increment the minor version number (i.e. 10.6 -> 10.7)
459-
deptarget = [int(x) for x in str(deptarget).split('.')]
459+
deptarget = [int(x) for x in deptarget.split('.')]
460460
deptarget[-1] += 1
461461
deptarget = '.'.join(str(i) for i in deptarget)
462462
self._try_compile_deployment_target('<', deptarget)
@@ -489,7 +489,7 @@ def _try_compile_deployment_target(self, operator, target):
489489

490490
# get the deployment target that the interpreter was built with
491491
target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
492-
target = tuple(map(int, str(target).split('.')[0:2]))
492+
target = tuple(map(int, target.split('.')[0:2]))
493493
# format the target value as defined in the Apple
494494
# Availability Macros. We can't use the macro names since
495495
# 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}',
@@ -252,6 +257,9 @@ def _parse_makefile(filename, vars=None):
252257
notdone[n] = v
253258
else:
254259
try:
260+
if n in _ALWAYS_STR:
261+
raise ValueError
262+
255263
v = int(v)
256264
except ValueError:
257265
# insert literal `$'
@@ -310,6 +318,8 @@ def _parse_makefile(filename, vars=None):
310318
notdone[name] = value
311319
else:
312320
try:
321+
if name in _ALWAYS_STR:
322+
raise ValueError
313323
value = int(value)
314324
except ValueError:
315325
done[name] = value.strip()
@@ -472,6 +482,8 @@ def parse_config_h(fp, vars=None):
472482
if m:
473483
n, v = m.group(1, 2)
474484
try:
485+
if n in _ALWAYS_STR:
486+
raise ValueError
475487
v = int(v)
476488
except ValueError:
477489
pass

Lib/test/test_posix.py

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

10771077
# '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
@@ -1072,7 +1072,7 @@ def detect_readline_curses(self):
10721072
os_release = int(os.uname()[2].split('.')[0])
10731073
dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
10741074
if (dep_target and
1075-
(tuple(int(n) for n in str(dep_target).split('.')[0:2])
1075+
(tuple(int(n) for n in dep_target.split('.')[0:2])
10761076
< (10, 5) ) ):
10771077
os_release = 8
10781078
if os_release < 9:

0 commit comments

Comments
 (0)