From b582a82b40d70af4e416c81763dba5707b5edc05 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Mon, 1 Feb 2021 04:29:44 +0100 Subject: [PATCH] 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 (cherry picked from commit 49926cf2bcc8b44d9b8f148d81979ada191dd9d5) Co-authored-by: Ronald Oussoren --- Lib/distutils/spawn.py | 4 ++-- Lib/distutils/tests/test_build_ext.py | 4 ++-- Lib/sysconfig.py | 12 ++++++++++++ Lib/test/test_posix.py | 2 +- .../macOS/2021-01-26-14-36-11.bpo-42504.ZxWt71.rst | 3 +++ setup.py | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/macOS/2021-01-26-14-36-11.bpo-42504.ZxWt71.rst diff --git a/Lib/distutils/spawn.py b/Lib/distutils/spawn.py index f50edd2da97100..0d1bd0391e6f11 100644 --- a/Lib/distutils/spawn.py +++ b/Lib/distutils/spawn.py @@ -54,8 +54,8 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0): global _cfg_target, _cfg_target_split if _cfg_target is None: from distutils import sysconfig - _cfg_target = str(sysconfig.get_config_var( - 'MACOSX_DEPLOYMENT_TARGET') or '') + _cfg_target = sysconfig.get_config_var( + 'MACOSX_DEPLOYMENT_TARGET') or '' if _cfg_target: _cfg_target_split = [int(x) for x in _cfg_target.split('.')] if _cfg_target: diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py index 1b034c93025213..808c0dc2874cd5 100644 --- a/Lib/distutils/tests/test_build_ext.py +++ b/Lib/distutils/tests/test_build_ext.py @@ -455,7 +455,7 @@ def test_deployment_target_higher_ok(self): deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') if deptarget: # increment the minor version number (i.e. 10.6 -> 10.7) - deptarget = [int(x) for x in str(deptarget).split('.')] + deptarget = [int(x) for x in deptarget.split('.')] deptarget[-1] += 1 deptarget = '.'.join(str(i) for i in deptarget) self._try_compile_deployment_target('<', deptarget) @@ -488,7 +488,7 @@ def _try_compile_deployment_target(self, operator, target): # get the deployment target that the interpreter was built with target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') - target = tuple(map(int, str(target).split('.')[0:2])) + target = tuple(map(int, target.split('.')[0:2])) # format the target value as defined in the Apple # Availability Macros. We can't use the macro names since # at least one value we test with will not exist yet. diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index 59da8e529025d2..e3f79bfde52948 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -18,6 +18,11 @@ 'parse_config_h', ] +# Keys for get_config_var() that are never converted to Python integers. +_ALWAYS_STR = { + 'MACOSX_DEPLOYMENT_TARGET', +} + _INSTALL_SCHEMES = { 'posix_prefix': { 'stdlib': '{installed_base}/{platlibdir}/python{py_version_short}', @@ -240,6 +245,9 @@ def _parse_makefile(filename, vars=None): notdone[n] = v else: try: + if n in _ALWAYS_STR: + raise ValueError + v = int(v) except ValueError: # insert literal `$' @@ -298,6 +306,8 @@ def _parse_makefile(filename, vars=None): notdone[name] = value else: try: + if name in _ALWAYS_STR: + raise ValueError value = int(value) except ValueError: done[name] = value.strip() @@ -459,6 +469,8 @@ def parse_config_h(fp, vars=None): if m: n, v = m.group(1, 2) try: + if n in _ALWAYS_STR: + raise ValueError v = int(v) except ValueError: pass diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index bfbcbab3b62f96..f4edb8bd9575f4 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1045,7 +1045,7 @@ def test_getgroups(self): if sys.platform == 'darwin': import sysconfig dt = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') or '10.0' - if tuple(int(n) for n in str(dt).split('.')[0:2]) < (10, 6): + if tuple(int(n) for n in dt.split('.')[0:2]) < (10, 6): raise unittest.SkipTest("getgroups(2) is broken prior to 10.6") # 'id -G' and 'os.getgroups()' should return the same diff --git a/Misc/NEWS.d/next/macOS/2021-01-26-14-36-11.bpo-42504.ZxWt71.rst b/Misc/NEWS.d/next/macOS/2021-01-26-14-36-11.bpo-42504.ZxWt71.rst new file mode 100644 index 00000000000000..a47776effe905e --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2021-01-26-14-36-11.bpo-42504.ZxWt71.rst @@ -0,0 +1,3 @@ +Ensure that the value of +sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') is always a string, +even in when the value is parsable as an integer. diff --git a/setup.py b/setup.py index bd5f73692441cb..d42eb9d1174ec5 100644 --- a/setup.py +++ b/setup.py @@ -1013,7 +1013,7 @@ def detect_readline_curses(self): os_release = int(os.uname()[2].split('.')[0]) dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') if (dep_target and - (tuple(int(n) for n in str(dep_target).split('.')[0:2]) + (tuple(int(n) for n in dep_target.split('.')[0:2]) < (10, 5) ) ): os_release = 8 if os_release < 9: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy