summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2014-03-12 07:34:02 (GMT)
committerÉric Araujo <merwok@netwok.org>2014-03-12 07:34:02 (GMT)
commitfc773a2d4ba3810b982e703bf8a240206369e5d1 (patch)
tree7d1428117d5ec01e94cdba671e35755cf9462a3e
parented5d95b76bd9a3584038bf578bac8f473a47e4c4 (diff)
downloadcpython-fc773a2d4ba3810b982e703bf8a240206369e5d1.zip
cpython-fc773a2d4ba3810b982e703bf8a240206369e5d1.tar.gz
cpython-fc773a2d4ba3810b982e703bf8a240206369e5d1.tar.bz2
Avoid “error: None” messages from distutils (#4931).
Thanks to Amaury Forgeot d’Arc and Philip J. Eby.
-rw-r--r--Doc/distutils/apiref.rst9
-rw-r--r--Lib/distutils/core.py7
-rw-r--r--Lib/distutils/dir_util.py6
-rw-r--r--Lib/distutils/tests/test_util.py10
-rw-r--r--Lib/distutils/util.py23
-rw-r--r--Misc/NEWS3
6 files changed, 20 insertions, 38 deletions
diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst
index 54f0a4e..d70d13f 100644
--- a/Doc/distutils/apiref.rst
+++ b/Doc/distutils/apiref.rst
@@ -1171,15 +1171,6 @@ other utility module.
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 --git a/Lib/distutils/core.py b/Lib/distutils/core.py
index 260332a..25d91ba 100644
--- a/Lib/distutils/core.py
+++ b/Lib/distutils/core.py
@@ -11,7 +11,6 @@ import sys
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
@@ -149,13 +148,11 @@ def setup (**attrs):
except KeyboardInterrupt:
raise SystemExit("interrupted")
except (IOError, os.error) 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 --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py
index 2826ff8..6a72bdd 100644
--- a/Lib/distutils/dir_util.py
+++ b/Lib/distutils/dir_util.py
@@ -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 @@ def remove_tree(directory, verbose=1, dry_run=0):
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 @@ def remove_tree(directory, verbose=1, dry_run=0):
if abspath in _path_created:
del _path_created[abspath]
except (IOError, 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 --git a/Lib/distutils/tests/test_util.py b/Lib/distutils/tests/test_util.py
index 00219cf..a1abf8f 100644
--- a/Lib/distutils/tests/test_util.py
+++ b/Lib/distutils/tests/test_util.py
@@ -8,7 +8,8 @@ from test.support import run_unittest
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 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
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 --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 67d8166..b558957 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -213,25 +213,10 @@ def subst_vars (s, local_vars):
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.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 --git a/Misc/NEWS b/Misc/NEWS
index 7baa0f7..1dce0ea 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,9 @@ Library
- Issue #20875: Prevent possible gzip "'read' is not defined" NameError.
Patch by Claudiu Popa.
+- Issue #4931: distutils should not produce unhelpful "error: None" messages
+ anymore. distutils.util.grok_environment_error is kept but doc-deprecated.
+
- Issue #20283: RE pattern methods now accept the string keyword parameters
as documented. The pattern and source keyword parameters are left as
deprecated aliases.