diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -661,29 +661,26 @@ def get_platform(): cfgvars = get_config_vars() macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET') - if True: - # Always calculate the release of the running machine, - # needed to determine if we can build fat binaries or not. + # Always calculate the release of the running machine, + # needed to determine if we can build fat binaries or not. + macrelease = macver - macrelease = macver - # Get the system version. Reading this plist is a documented - # way to get the system version (see the documentation for - # the Gestalt Manager) + # Get the system version. Reading this plist is a documented + # way to get the system version (see the documentation for + # the Gestalt Manager) + fn = '/System/Library/CoreServices/SystemVersion.plist' + if os.path.exists(fn): + import plistlib + plist = plistlib.readPlist(fn) try: - f = open('/System/Library/CoreServices/SystemVersion.plist') - except IOError: - # We're on a plain darwin box, fall back to the default - # behaviour. + text = plist['ProductUserVisibleVersion'] + except KeyError: pass else: - try: - m = re.search(r'ProductUserVisibleVersion\s*' - r'(.*?)', f.read()) - finally: - f.close() - if m is not None: - macrelease = '.'.join(m.group(1).split('.')[:2]) - # else: fall back to the default behaviour + macrelease = '.'.join(text.split('.')[:2]) + # else: We're on a plain darwin box, fall back to the default + # behaviour. + if not macver: macver = macrelease