diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index ac5a0ca0120..1c1ea477db4 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -354,7 +354,7 @@ def parse_config_files(self, filenames=None): parser = ConfigParser() for filename in filenames: if DEBUG: - self.announce(" reading", filename) + self.announce(" reading %s" % filename) parser.read(filename) for section in parser.sections(): options = parser.options(section) diff --git a/Lib/distutils/log.py b/Lib/distutils/log.py index 6f949d51793..758857081c8 100644 --- a/Lib/distutils/log.py +++ b/Lib/distutils/log.py @@ -17,6 +17,9 @@ def __init__(self, threshold=WARN): self.threshold = threshold def _log(self, level, msg, args): + if level not in (DEBUG, INFO, WARN, ERROR, FATAL): + raise ValueError('%s wrong log level' % str(level)) + if level >= self.threshold: if args: msg = msg % args diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py index 1255413989e..ea122111caa 100644 --- a/Lib/distutils/tests/support.py +++ b/Lib/distutils/tests/support.py @@ -4,6 +4,7 @@ import tempfile from distutils import log +from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL from distutils.core import Distribution from test.support import EnvironmentVarGuard @@ -25,6 +26,8 @@ def tearDown(self): super().tearDown() def _log(self, level, msg, args): + if level not in (DEBUG, INFO, WARN, ERROR, FATAL): + raise ValueError('%s wrong log level' % str(level)) self.logs.append((level, msg, args)) def get_logs(self, *levels): diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index 91297f0e158..799b0c06037 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -171,6 +171,13 @@ def test_get_command_packages(self): self.assertEquals(cmds, ['distutils.command', 'one', 'two']) + def test_announce(self): + # make sure the level is known + dist = Distribution() + args = ('ok',) + kwargs = {'level': 'ok2'} + self.assertRaises(ValueError, dist.announce, args, kwargs) + class MetadataTestCase(support.TempdirManager, support.EnvironGuard, unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS index 528b3fdc3b0..6948fc6fc26 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -1064,6 +1064,8 @@ Core and Builtins Library ------- +- Issue #6954: Fixed crash when using DISTUTILS_DEBUG flag in Distutils. + - Issue #6163: Fixed HP-UX runtime library dir options in distutils.unixcompiler. Initial patch by Sridhar Ratnakumar and Michael Haubenwallner.