Skip to content

Commit a0fe1f7

Browse files
committed
Merge 3.3 (#4931)
2 parents 03a4da5 + fc773a2 commit a0fe1f7

6 files changed

Lines changed: 20 additions & 38 deletions

File tree

Doc/distutils/apiref.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,15 +1160,6 @@ other utility module.
11601160
underscore. No { } or ( ) style quoting is available.
11611161

11621162

1163-
.. function:: grok_environment_error(exc[, prefix='error: '])
1164-
1165-
Generate a useful error message from an :exc:`OSError` exception object.
1166-
Handles Python 1.5.1 and later styles, and does what it can to deal with
1167-
exception objects that don't have a filename (which happens when the error
1168-
is due to a two-file operation, such as :func:`~os.rename` or :func:`~os.link`).
1169-
Returns the error message as a string prefixed with *prefix*.
1170-
1171-
11721163
.. function:: split_quoted(s)
11731164

11741165
Split a string up according to Unix shell-like rules for quotes and backslashes.

Lib/distutils/core.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from distutils.debug import DEBUG
1313
from distutils.errors import *
14-
from distutils.util import grok_environment_error
1514

1615
# Mainly import these so setup scripts can "from distutils.core import" them.
1716
from distutils.dist import Distribution
@@ -150,13 +149,11 @@ class found in 'cmdclass' is used in place of the default, which is
150149
except KeyboardInterrupt:
151150
raise SystemExit("interrupted")
152151
except OSError as exc:
153-
error = grok_environment_error(exc)
154-
155152
if DEBUG:
156-
sys.stderr.write(error + "\n")
153+
sys.stderr.write("error: %s\n" % (exc,))
157154
raise
158155
else:
159-
raise SystemExit(error)
156+
raise SystemExit("error: %s" % (exc,))
160157

161158
except (DistutilsError,
162159
CCompilerError) as msg:

Lib/distutils/dir_util.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Utility functions for manipulating directories and directory trees."""
44

5-
import os, sys
5+
import os
66
import errno
77
from distutils.errors import DistutilsFileError, DistutilsInternalError
88
from distutils import log
@@ -182,7 +182,6 @@ def remove_tree(directory, verbose=1, dry_run=0):
182182
Any errors are ignored (apart from being reported to stdout if 'verbose'
183183
is true).
184184
"""
185-
from distutils.util import grok_environment_error
186185
global _path_created
187186

188187
if verbose >= 1:
@@ -199,8 +198,7 @@ def remove_tree(directory, verbose=1, dry_run=0):
199198
if abspath in _path_created:
200199
del _path_created[abspath]
201200
except OSError as exc:
202-
log.warn(grok_environment_error(
203-
exc, "error removing %s: " % directory))
201+
log.warn("error removing %s: %s", directory, exc)
204202

205203
def ensure_relative(path):
206204
"""Take the full path 'path', and make it a relative path.

Lib/distutils/tests/test_util.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
99
from distutils.util import (get_platform, convert_path, change_root,
1010
check_environ, split_quoted, strtobool,
11-
rfc822_escape, byte_compile)
11+
rfc822_escape, byte_compile,
12+
grok_environment_error)
1213
from distutils import util # used to patch _environ_checked
1314
from distutils.sysconfig import get_config_vars
1415
from distutils import sysconfig
@@ -285,6 +286,13 @@ def test_dont_write_bytecode(self):
285286
finally:
286287
sys.dont_write_bytecode = old_dont_write_bytecode
287288

289+
def test_grok_environment_error(self):
290+
# test obsolete function to ensure backward compat (#4931)
291+
exc = IOError("Unable to find batch file")
292+
msg = grok_environment_error(exc)
293+
self.assertEqual(msg, "error: Unable to find batch file")
294+
295+
288296
def test_suite():
289297
return unittest.makeSuite(UtilTestCase)
290298

Lib/distutils/util.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,25 +207,10 @@ def _subst (match, local_vars=local_vars):
207207

208208

209209
def grok_environment_error (exc, prefix="error: "):
210-
"""Generate a useful error message from an OSError
211-
exception object. Handles Python 1.5.1 and 1.5.2 styles, and
212-
does what it can to deal with exception objects that don't have a
213-
filename (which happens when the error is due to a two-file operation,
214-
such as 'rename()' or 'link()'. Returns the error message as a string
215-
prefixed with 'prefix'.
216-
"""
217-
# check for Python 1.5.2-style {IO,OS}Error exception objects
218-
if hasattr(exc, 'filename') and hasattr(exc, 'strerror'):
219-
if exc.filename:
220-
error = prefix + "%s: %s" % (exc.filename, exc.strerror)
221-
else:
222-
# two-argument functions in posix module don't
223-
# include the filename in the exception object!
224-
error = prefix + "%s" % exc.strerror
225-
else:
226-
error = prefix + str(exc.args[-1])
227-
228-
return error
210+
# Function kept for backward compatibility.
211+
# Used to try clever things with EnvironmentErrors,
212+
# but nowadays str(exception) produces good messages.
213+
return prefix + str(exc)
229214

230215

231216
# Needed by 'split_quoted()'

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Library
2323
- Issue #19157: Include the broadcast address in the usuable hosts for IPv6
2424
in ipaddress.
2525

26+
- Issue #4931: distutils should not produce unhelpful "error: None" messages
27+
anymore. distutils.util.grok_environment_error is kept but doc-deprecated.
28+
2629
- Issue #20875: Prevent possible gzip "'read' is not defined" NameError.
2730
Patch by Claudiu Popa.
2831

0 commit comments

Comments
 (0)