(original) (raw)
changeset: 89596:a865f6fb82b4 branch: 2.7 user: Éric Araujo merwok@netwok.org date: Wed Mar 12 03:14:48 2014 -0400 files: Doc/distutils/apiref.rst Lib/distutils/core.py Lib/distutils/dir_util.py Lib/distutils/tests/test_util.py Lib/distutils/util.py Misc/NEWS description: Avoid “error: None” messages from distutils (#4931). Thanks to Amaury Forgeot d’Arc and Philip J. Eby. diff -r 1f823c1559bd -r a865f6fb82b4 Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst Wed Mar 12 02:16:37 2014 -0400 +++ b/Doc/distutils/apiref.rst Wed Mar 12 03:14:48 2014 -0400 @@ -1167,15 +1167,6 @@ underscore. No { } or ( ) style quoting is available. -.. function:: grok_environment_error(exc[, prefix='error: ']) - - Generate a useful error message from an :exc:`EnvironmentError` (:exc:`IOError` - or :exc:`OSError`) exception object. Handles Python 1.5.1 and later styles, - and does what it can to deal with exception objects that don't have a filename - (which happens when the error is due to a two-file operation, such as - :func:`~os.rename` or :func:`~os.link`). Returns the error message as a - string prefixed with *prefix*. - .. function:: split_quoted(s) diff -r 1f823c1559bd -r a865f6fb82b4 Lib/distutils/core.py --- a/Lib/distutils/core.py Wed Mar 12 02:16:37 2014 -0400 +++ b/Lib/distutils/core.py Wed Mar 12 03:14:48 2014 -0400 @@ -14,7 +14,6 @@ from distutils.debug import DEBUG from distutils.errors import (DistutilsSetupError, DistutilsArgError, DistutilsError, CCompilerError) -from distutils.util import grok_environment_error # Mainly import these so setup scripts can "from distutils.core import" them. from distutils.dist import Distribution @@ -153,13 +152,11 @@ except KeyboardInterrupt: raise SystemExit, "interrupted" except (IOError, os.error), exc: - error = grok_environment_error(exc) - if DEBUG: - sys.stderr.write(error + "\n") + sys.stderr.write("error: %s\n" % (exc,)) raise else: - raise SystemExit, error + raise SystemExit, exc except (DistutilsError, CCompilerError), msg: diff -r 1f823c1559bd -r a865f6fb82b4 Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py Wed Mar 12 02:16:37 2014 -0400 +++ b/Lib/distutils/dir_util.py Wed Mar 12 03:14:48 2014 -0400 @@ -185,7 +185,6 @@ Any errors are ignored (apart from being reported to stdout if 'verbose' is true). """ - from distutils.util import grok_environment_error global _path_created if verbose >= 1: @@ -202,8 +201,7 @@ if abspath in _path_created: del _path_created[abspath] except (IOError, OSError), exc: - log.warn(grok_environment_error( - exc, "error removing %s: " % directory)) + log.warn("error removing %s: %s", directory, exc) def ensure_relative(path): """Take the full path 'path', and make it a relative path. diff -r 1f823c1559bd -r a865f6fb82b4 Lib/distutils/tests/test_util.py --- a/Lib/distutils/tests/test_util.py Wed Mar 12 02:16:37 2014 -0400 +++ b/Lib/distutils/tests/test_util.py Wed Mar 12 03:14:48 2014 -0400 @@ -3,8 +3,9 @@ import unittest from test.test_support import run_unittest -from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError -from distutils.util import byte_compile +from distutils.errors import DistutilsByteCompileError +from distutils.util import byte_compile, grok_environment_error + class UtilTestCase(unittest.TestCase): @@ -18,6 +19,13 @@ finally: sys.dont_write_bytecode = old_dont_write_bytecode + def test_grok_environment_error(self): + # test obsolete function to ensure backward compat (#4931) + exc = IOError("Unable to find batch file") + msg = grok_environment_error(exc) + self.assertEqual(msg, "error: Unable to find batch file") + + def test_suite(): return unittest.makeSuite(UtilTestCase) diff -r 1f823c1559bd -r a865f6fb82b4 Lib/distutils/util.py --- a/Lib/distutils/util.py Wed Mar 12 02:16:37 2014 -0400 +++ b/Lib/distutils/util.py Wed Mar 12 03:14:48 2014 -0400 @@ -213,25 +213,10 @@ def grok_environment_error (exc, prefix="error: "): - """Generate a useful error message from an EnvironmentError (IOError or - OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and - does what it can to deal with exception objects that don't have a - filename (which happens when the error is due to a two-file operation, - such as 'rename()' or 'link()'. Returns the error message as a string - prefixed with 'prefix'. - """ - # check for Python 1.5.2-style {IO,OS}Error exception objects - if hasattr(exc, 'filename') and hasattr(exc, 'strerror'): - if exc.filename: - error = prefix + "%s: %s" % (exc.filename, exc.strerror) - else: - # two-argument functions in posix module don't - # include the filename in the exception object! - error = prefix + "%s" % exc.strerror - else: - error = prefix + str(exc[-1]) - - return error + # Function kept for backward compatibility. + # Used to try clever things with EnvironmentErrors, + # but nowadays str(exception) produces good messages. + return prefix + str(exc) # Needed by 'split_quoted()' diff -r 1f823c1559bd -r a865f6fb82b4 Misc/NEWS --- a/Misc/NEWS Wed Mar 12 02:16:37 2014 -0400 +++ b/Misc/NEWS Wed Mar 12 03:14:48 2014 -0400 @@ -44,6 +44,9 @@ as documented. The pattern and source keyword parameters are left as deprecated aliases. +- Issue #4931: distutils should not produce unhelpful "error: None" messages + anymore. distutils.util.grok_environment_error is kept but doc-deprecated. + - Improve the random module's default seeding to use 256 bits of entropy from os.urandom(). This was already done for Python 3, mildly improving security with a bigger seed space. /merwok@netwok.org