cpython: bdbfbb57e37e (original) (raw)
Mercurial > cpython
changeset 91561:bdbfbb57e37e 2.7
Issue #21923: Prevent AttributeError in distutils.sysconfig.customize_compiler due to possible uninitialized _config_vars. Original patch by Alex Gaynor. [#21923]
Ned Deily nad@acm.org | |
---|---|
date | Sun, 06 Jul 2014 16:11:44 -0700 |
parents | 3881c12fa3ae |
children | 4514804d0e50 |
files | Lib/distutils/sysconfig.py Lib/distutils/tests/test_sysconfig.py Misc/NEWS |
diffstat | 3 files changed, 26 insertions(+), 1 deletions(-)[+] [-] Lib/distutils/sysconfig.py 3 Lib/distutils/tests/test_sysconfig.py 21 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -165,7 +165,8 @@ def customize_compiler(compiler): # version and build tools may not support the same set # of CPU architectures for universal builds. global _config_vars
if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''):[](#l1.7)
# Use get_config_var() to ensure _config_vars is initialized.[](#l1.8)
if not get_config_var('CUSTOMIZED_OSX_COMPILER'):[](#l1.9) import _osx_support[](#l1.10) _osx_support.customize_compiler(_config_vars)[](#l1.11) _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'[](#l1.12)
--- a/Lib/distutils/tests/test_sysconfig.py +++ b/Lib/distutils/tests/test_sysconfig.py @@ -3,6 +3,9 @@ import os import test import unittest import shutil +import subprocess +import sys +import textwrap from distutils import sysconfig from distutils.tests import support @@ -99,6 +102,24 @@ class SysconfigTestCase(support.EnvironG self.assertEqual(global_sysconfig.get_config_var('LDSHARED'), sysconfig.get_config_var('LDSHARED')) self.assertEqual(global_sysconfig.get_config_var('CC'), sysconfig.get_config_var('CC'))
- def test_customize_compiler_before_get_config_vars(self):
# Issue #21923: test that a Distribution compiler[](#l2.18)
# instance can be called without an explicit call to[](#l2.19)
# get_config_vars().[](#l2.20)
with open(TESTFN, 'w') as f:[](#l2.21)
f.writelines(textwrap.dedent('''\[](#l2.22)
from distutils.core import Distribution[](#l2.23)
config = Distribution().get_command_obj('config')[](#l2.24)
# try_compile may pass or it may fail if no compiler[](#l2.25)
# is found but it should not raise an exception.[](#l2.26)
rc = config.try_compile('int x;')[](#l2.27)
'''))[](#l2.28)
p = subprocess.Popen([str(sys.executable), TESTFN],[](#l2.29)
stdout=subprocess.PIPE,[](#l2.30)
stderr=subprocess.STDOUT,[](#l2.31)
universal_newlines=True)[](#l2.32)
outs, errs = p.communicate()[](#l2.33)
self.assertEqual(0, p.returncode, "Subprocess failed: " + outs)[](#l2.34)