Commit 7da8f827 authored by Éric Araujo's avatar Éric Araujo

Avoid “error: None” messages from distutils (#4931).

Thanks to Amaury Forgeot d’Arc and Philip J. Eby.
parent 9c925df0
...@@ -11,7 +11,6 @@ import sys ...@@ -11,7 +11,6 @@ import sys
from distutils.debug import DEBUG from distutils.debug import DEBUG
from distutils.errors import * from distutils.errors import *
from distutils.util import grok_environment_error
# Mainly import these so setup scripts can "from distutils.core import" them. # Mainly import these so setup scripts can "from distutils.core import" them.
from distutils.dist import Distribution from distutils.dist import Distribution
...@@ -149,13 +148,11 @@ def setup (**attrs): ...@@ -149,13 +148,11 @@ def setup (**attrs):
except KeyboardInterrupt: except KeyboardInterrupt:
raise SystemExit("interrupted") raise SystemExit("interrupted")
except (IOError, os.error) as exc: except (IOError, os.error) as exc:
error = grok_environment_error(exc)
if DEBUG: if DEBUG:
sys.stderr.write(error + "\n") sys.stderr.write("error: %s\n" % (exc,))
raise raise
else: else:
raise SystemExit(error) raise SystemExit("error: %s" % (exc,))
except (DistutilsError, except (DistutilsError,
CCompilerError) as msg: CCompilerError) as msg:
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Utility functions for manipulating directories and directory trees.""" Utility functions for manipulating directories and directory trees."""
import os, sys import os
import errno import errno
from distutils.errors import DistutilsFileError, DistutilsInternalError from distutils.errors import DistutilsFileError, DistutilsInternalError
from distutils import log from distutils import log
...@@ -182,7 +182,6 @@ def remove_tree(directory, verbose=1, dry_run=0): ...@@ -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' Any errors are ignored (apart from being reported to stdout if 'verbose'
is true). is true).
""" """
from distutils.util import grok_environment_error
global _path_created global _path_created
if verbose >= 1: if verbose >= 1:
...@@ -199,8 +198,7 @@ def remove_tree(directory, verbose=1, dry_run=0): ...@@ -199,8 +198,7 @@ def remove_tree(directory, verbose=1, dry_run=0):
if abspath in _path_created: if abspath in _path_created:
del _path_created[abspath] del _path_created[abspath]
except (IOError, OSError) as exc: except (IOError, OSError) as exc:
log.warn(grok_environment_error( log.warn("error removing %s: %s", directory, exc)
exc, "error removing %s: " % directory))
def ensure_relative(path): def ensure_relative(path):
"""Take the full path 'path', and make it a relative path. """Take the full path 'path', and make it a relative path.
......
...@@ -8,7 +8,8 @@ from test.support import run_unittest ...@@ -8,7 +8,8 @@ from test.support import run_unittest
from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
from distutils.util import (get_platform, convert_path, change_root, from distutils.util import (get_platform, convert_path, change_root,
check_environ, split_quoted, strtobool, 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 import util # used to patch _environ_checked
from distutils.sysconfig import get_config_vars from distutils.sysconfig import get_config_vars
from distutils import sysconfig from distutils import sysconfig
...@@ -285,6 +286,13 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): ...@@ -285,6 +286,13 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
finally: finally:
sys.dont_write_bytecode = old_dont_write_bytecode 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(): def test_suite():
return unittest.makeSuite(UtilTestCase) return unittest.makeSuite(UtilTestCase)
......
...@@ -213,25 +213,10 @@ def subst_vars (s, local_vars): ...@@ -213,25 +213,10 @@ def subst_vars (s, local_vars):
def grok_environment_error (exc, prefix="error: "): def grok_environment_error (exc, prefix="error: "):
"""Generate a useful error message from an EnvironmentError (IOError or # Function kept for backward compatibility.
OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and # Used to try clever things with EnvironmentErrors,
does what it can to deal with exception objects that don't have a # but nowadays str(exception) produces good messages.
filename (which happens when the error is due to a two-file operation, return prefix + str(exc)
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
# Needed by 'split_quoted()' # Needed by 'split_quoted()'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment