Skip to content

Commit 5291639

Browse files
authored
bpo-42504: fix for MACOSX_DEPLOYMENT_TARGET=11 (GH-23556)
macOS releases numbering has changed as of macOS 11 Big Sur. Previously, major releases were of the form 10.x, 10.x+1, 10.x+2, etc; as of Big Sur, they are now x, x+1, etc, so, for example, 10.15, 10.15.1, ..., 10.15.7, 11, 11.0.1, 11.1, ..., 12, 12.1, etc. Allow Python to build with single-digit deployment target values. Patch provided by FX Coudert.
1 parent dedc2cd commit 5291639

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
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 = sysconfig.get_config_var(
58-
'MACOSX_DEPLOYMENT_TARGET') or ''
57+
_cfg_target = str(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: 7 additions & 3 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 deptarget.split('.')]
459+
deptarget = [int(x) for x in str(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, target.split('.')[0:2]))
492+
target = tuple(map(int, str(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.
@@ -498,7 +498,11 @@ def _try_compile_deployment_target(self, operator, target):
498498
target = '%02d%01d0' % target
499499
else:
500500
# for 10.10 and beyond -> "10nn00"
501-
target = '%02d%02d00' % target
501+
if len(target) >= 2:
502+
target = '%02d%02d00' % target
503+
else:
504+
# 11 and later can have no minor version (11 instead of 11.0)
505+
target = '%02d0000' % target
502506
deptarget_ext = Extension(
503507
'deptarget',
504508
[deptarget_c],

Lib/test/test_posix.py

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

10671067
# 'id -G' and 'os.getgroups()' should return the same
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix build on macOS Big Sur when MACOSX_DEPLOYMENT_TARGET=11

setup.py

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

0 commit comments

Comments
 (0)