diff -r c5508c706293 Doc/distutils/setupscript.rst --- a/Doc/distutils/setupscript.rst Fri Jan 18 13:42:56 2013 +0100 +++ b/Doc/distutils/setupscript.rst Fri Jan 18 13:10:57 2013 -0500 @@ -696,7 +696,10 @@ and see that it's a permission problem. On the other hand, this doesn't help the developer to find the cause of the -failure. For this purpose, the DISTUTILS_DEBUG environment variable can be set -to anything except an empty string, and distutils will now print detailed -information what it is doing, and prints the full traceback in case an exception -occurs. +failure. For this purpose, the :attr:`DEBUG` attribute of the +:mod:`distutils.debug` module can be used to control distutils specific deugging +information. If not set directly, :attr:`DEBUG` is set to ``True`` +if the DISTUTILS_DEBUG environment variable is set to anything except an empty +string. With :attr:`DEBUG` set to ``True``, distutils prints detailed +information about what it is doing, and prints the full traceback in case an +exception occurs. diff -r c5508c706293 Lib/distutils/ccompiler.py --- a/Lib/distutils/ccompiler.py Fri Jan 18 13:42:56 2013 +0100 +++ b/Lib/distutils/ccompiler.py Fri Jan 18 13:10:57 2013 -0500 @@ -895,8 +895,8 @@ log.debug(msg) def debug_print(self, msg): - from distutils.debug import DEBUG - if DEBUG: + import distutils.debug + if distutils.debug.DEBUG: print(msg) def warn(self, msg): diff -r c5508c706293 Lib/distutils/core.py --- a/Lib/distutils/core.py Fri Jan 18 13:42:56 2013 +0100 +++ b/Lib/distutils/core.py Fri Jan 18 13:10:57 2013 -0500 @@ -9,7 +9,7 @@ import os import sys -from distutils.debug import DEBUG +import distutils.debug from distutils.errors import * from distutils.util import grok_environment_error @@ -121,7 +121,7 @@ # the setup script, but be overridden by the command line. dist.parse_config_files() - if DEBUG: + if distutils.debug.DEBUG: print("options (after parsing config files):") dist.dump_option_dicts() @@ -135,7 +135,7 @@ except DistutilsArgError as msg: raise SystemExit(gen_usage(dist.script_name) + "\nerror: %s" % msg) - if DEBUG: + if distutils.debug.DEBUG: print("options (after parsing command line):") dist.dump_option_dicts() @@ -151,7 +151,7 @@ except OSError as exc: error = grok_environment_error(exc) - if DEBUG: + if distutils.debug.DEBUG: sys.stderr.write(error + "\n") raise else: @@ -159,7 +159,7 @@ except (DistutilsError, CCompilerError) as msg: - if DEBUG: + if distutils.debug.DEBUG: raise else: raise SystemExit("error: " + str(msg)) diff -r c5508c706293 Lib/distutils/dist.py --- a/Lib/distutils/dist.py Fri Jan 18 13:42:56 2013 +0100 +++ b/Lib/distutils/dist.py Fri Jan 18 13:10:57 2013 -0500 @@ -15,7 +15,7 @@ from distutils.fancy_getopt import FancyGetopt, translate_longopt from distutils.util import check_environ, strtobool, rfc822_escape from distutils import log -from distutils.debug import DEBUG +import distutils.debug # Regex to define acceptable Distutils command names. This is not *quite* # the same as a Python NAME -- I don't allow leading underscores. The fact @@ -346,12 +346,12 @@ if filenames is None: filenames = self.find_config_files() - if DEBUG: + if distutils.debug.DEBUG: self.announce("Distribution.parse_config_files():") parser = ConfigParser() for filename in filenames: - if DEBUG: + if distutils.debug.DEBUG: self.announce(" reading %s" % filename) parser.read(filename) for section in parser.sections(): @@ -801,7 +801,7 @@ """ cmd_obj = self.command_obj.get(command) if not cmd_obj and create: - if DEBUG: + if distutils.debug.DEBUG: self.announce("Distribution.get_command_obj(): " \ "creating '%s' command object" % command) @@ -833,10 +833,10 @@ if option_dict is None: option_dict = self.get_option_dict(command_name) - if DEBUG: + if distutils.debug.DEBUG: self.announce(" setting options for '%s' command:" % command_name) for (option, (source, value)) in option_dict.items(): - if DEBUG: + if distutils.debug.DEBUG: self.announce(" %s = %s (from %s)" % (option, value, source)) try: diff -r c5508c706293 Lib/distutils/filelist.py --- a/Lib/distutils/filelist.py Fri Jan 18 13:42:56 2013 +0100 +++ b/Lib/distutils/filelist.py Fri Jan 18 13:10:57 2013 -0500 @@ -41,8 +41,8 @@ """Print 'msg' to stdout if the global DEBUG (taken from the DISTUTILS_DEBUG environment variable) flag is true. """ - from distutils.debug import DEBUG - if DEBUG: + import distutils.debug + if distutils.debug.DEBUG: print(msg) # -- List-like methods --------------------------------------------- diff -r c5508c706293 Lib/distutils/tests/test_core.py --- a/Lib/distutils/tests/test_core.py Fri Jan 18 13:42:56 2013 +0100 +++ b/Lib/distutils/tests/test_core.py Fri Jan 18 13:10:57 2013 -0500 @@ -91,15 +91,15 @@ stdout.seek(0) self.assertEqual(stdout.read(), 'bar\n') - distutils.core.DEBUG = True + distutils.debug.DEBUG = True try: with captured_stdout() as stdout: distutils.core.setup(name='bar') finally: - distutils.core.DEBUG = False + distutils.debug.DEBUG = False stdout.seek(0) wanted = "options (after parsing config files):\n" - self.assertEqual(stdout.readlines()[0], wanted) + self.assertIn(wanted, stdout.readlines()) def test_suite(): return unittest.makeSuite(CoreTestCase)