From: Tarek Ziadé Date: Tue, 30 Dec 2008 23:09:20 +0000 (+0000) Subject: Merged revisions 68081 via svnmerge from X-Git-Tag: v3.1a1~630 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9df8ce3a8f2acb6c31a5f0b50015a9ba17d23823;p=python Merged revisions 68081 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r68081 | tarek.ziade | 2008-12-31 00:03:41 +0100 (Wed, 31 Dec 2008) | 1 line Fixed #4702: Throwing DistutilsPlatformError instead of IOError under win32 if MSVC is not found ........ --- diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py index eced0524b8..aae0637394 100644 --- a/Lib/distutils/msvc9compiler.py +++ b/Lib/distutils/msvc9compiler.py @@ -247,7 +247,7 @@ def query_vcvarsall(version, arch="x86"): result = {} if vcvarsall is None: - raise IOError("Unable to find vcvarsall.bat") + raise DistutilsPlatformError("Unable to find vcvarsall.bat") log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version) popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch), stdout=subprocess.PIPE, @@ -255,7 +255,7 @@ def query_vcvarsall(version, arch="x86"): stdout, stderr = popen.communicate() if popen.wait() != 0: - raise IOError(stderr.decode("mbcs")) + raise DistutilsPlatformError(stderr.decode("mbcs")) stdout = stdout.decode("mbcs") for line in stdout.split("\n"): diff --git a/Lib/distutils/tests/test_msvc9compiler.py b/Lib/distutils/tests/test_msvc9compiler.py new file mode 100644 index 0000000000..1659cea510 --- /dev/null +++ b/Lib/distutils/tests/test_msvc9compiler.py @@ -0,0 +1,33 @@ +"""Tests for distutils.msvc9compiler.""" +import sys +import unittest + +from distutils.errors import DistutilsPlatformError + +class msvc9compilerTestCase(unittest.TestCase): + + def test_no_compiler(self): + # makes sure query_vcvarsall throws + # a DistutilsPlatformError if the compiler + # is not found + if sys.platform != 'win32': + # this test is only for win32 + return + from distutils.msvc9compiler import query_vcvarsall + def _find_vcvarsall(version): + return None + + from distutils import msvc9compiler + old_find_vcvarsall = msvc9compiler.find_vcvarsall + msvc9compiler.find_vcvarsall = _find_vcvarsall + try: + self.assertRaises(DistutilsPlatformError, query_vcvarsall, + 'wont find this version') + finally: + msvc9compiler.find_vcvarsall = old_find_vcvarsall + +def test_suite(): + return unittest.makeSuite(msvc9compilerTestCase) + +if __name__ == "__main__": + unittest.main(defaultTest="test_suite") diff --git a/Misc/NEWS b/Misc/NEWS index bd43a002df..d7adf60139 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -67,6 +67,9 @@ Core and Builtins Library ------- +- Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case + no MSVC compiler is found under Windows. Original patch by Philip Jenvey. + - Issue #4646: distutils was choking on empty options arg in the setup function. Original patch by Thomas Heller.