(original) (raw)
changeset: 89599:c7bd0f953687 parent: 89594:996652f3c136 parent: 89598:504eb00998f2 user: Éric Araujo merwok@netwok.org date: Wed Mar 12 04:10:51 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: Merge 3.3 (#4931) diff -r 996652f3c136 -r c7bd0f953687 Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst Tue Mar 11 21:58:54 2014 -0400 +++ b/Doc/distutils/apiref.rst Wed Mar 12 04:10:51 2014 -0400 @@ -1160,15 +1160,6 @@ underscore. No { } or ( ) style quoting is available. -.. function:: grok_environment_error(exc[, prefix='error: ']) - - Generate a useful error message from an :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) Split a string up according to Unix shell-like rules for quotes and backslashes. diff -r 996652f3c136 -r c7bd0f953687 Lib/distutils/core.py --- a/Lib/distutils/core.py Tue Mar 11 21:58:54 2014 -0400 +++ b/Lib/distutils/core.py Wed Mar 12 04:10:51 2014 -0400 @@ -11,7 +11,6 @@ from distutils.debug import DEBUG from distutils.errors import * -from distutils.util import grok_environment_error # Mainly import these so setup scripts can "from distutils.core import" them. from distutils.dist import Distribution @@ -150,13 +149,11 @@ except KeyboardInterrupt: raise SystemExit("interrupted") except OSError as 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("error: %s" % (exc,)) except (DistutilsError, CCompilerError) as msg: diff -r 996652f3c136 -r c7bd0f953687 Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py Tue Mar 11 21:58:54 2014 -0400 +++ b/Lib/distutils/dir_util.py Wed Mar 12 04:10:51 2014 -0400 @@ -2,7 +2,7 @@ Utility functions for manipulating directories and directory trees.""" -import os, sys +import os import errno from distutils.errors import DistutilsFileError, DistutilsInternalError from distutils import log @@ -182,7 +182,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: @@ -199,8 +198,7 @@ if abspath in _path_created: del _path_created[abspath] except OSError as 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 996652f3c136 -r c7bd0f953687 Lib/distutils/tests/test_util.py --- a/Lib/distutils/tests/test_util.py Tue Mar 11 21:58:54 2014 -0400 +++ b/Lib/distutils/tests/test_util.py Wed Mar 12 04:10:51 2014 -0400 @@ -8,7 +8,8 @@ from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError from distutils.util import (get_platform, convert_path, change_root, check_environ, split_quoted, strtobool, - rfc822_escape, byte_compile) + rfc822_escape, byte_compile, + grok_environment_error) from distutils import util # used to patch _environ_checked from distutils.sysconfig import get_config_vars from distutils import sysconfig @@ -285,6 +286,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 996652f3c136 -r c7bd0f953687 Lib/distutils/util.py --- a/Lib/distutils/util.py Tue Mar 11 21:58:54 2014 -0400 +++ b/Lib/distutils/util.py Wed Mar 12 04:10:51 2014 -0400 @@ -207,25 +207,10 @@ def grok_environment_error (exc, prefix="error: "): - """Generate a useful error message from an 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.args[-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 996652f3c136 -r c7bd0f953687 Misc/NEWS --- a/Misc/NEWS Tue Mar 11 21:58:54 2014 -0400 +++ b/Misc/NEWS Wed Mar 12 04:10:51 2014 -0400 @@ -23,6 +23,9 @@ - Issue #19157: Include the broadcast address in the usuable hosts for IPv6 in ipaddress. +- Issue #4931: distutils should not produce unhelpful "error: None" messages + anymore. distutils.util.grok_environment_error is kept but doc-deprecated. + - Issue #20875: Prevent possible gzip "'read' is not defined" NameError. Patch by Claudiu Popa. /merwok@netwok.org