Skip to content

Commit 09a698b

Browse files
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. (cherry picked from commit 5291639) Co-authored-by: FX Coudert <[email protected]>
1 parent 9b34f34 commit 09a698b

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
@@ -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 deptarget.split('.')]
458+
deptarget = [int(x) for x in str(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, target.split('.')[0:2]))
491+
target = tuple(map(int, str(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.
@@ -497,7 +497,11 @@ def _try_compile_deployment_target(self, operator, target):
497497
target = '%02d%01d0' % target
498498
else:
499499
# for 10.10 and beyond -> "10nn00"
500-
target = '%02d%02d00' % target
500+
if len(target) >= 2:
501+
target = '%02d%02d00' % target
502+
else:
503+
# 11 and later can have no minor version (11 instead of 11.0)
504+
target = '%02d0000' % target
501505
deptarget_ext = Extension(
502506
'deptarget',
503507
[deptarget_c],

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 dt.split('.')[0:2]) < (10, 6):
1048+
if tuple(int(n) for n in str(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: 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
@@ -1012,7 +1012,7 @@ def detect_readline_curses(self):
10121012
os_release = int(os.uname()[2].split('.')[0])
10131013
dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
10141014
if (dep_target and
1015-
(tuple(int(n) for n in dep_target.split('.')[0:2])
1015+
(tuple(int(n) for n in str(dep_target).split('.')[0:2])
10161016
< (10, 5) ) ):
10171017
os_release = 8
10181018
if os_release < 9:

0 commit comments

Comments
 (0)