Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 905a257

Browse files
author
Tarek Ziadé
committed
Merged revisions 73762 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r73762 | tarek.ziade | 2009-07-02 16:20:47 +0200 (Thu, 02 Jul 2009) | 1 line pep8-fied and cleaned up distutils.util ........
1 parent 5f8aa47 commit 905a257

1 file changed

Lines changed: 43 additions & 46 deletions

File tree

Lib/distutils/util.py

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from distutils.spawn import spawn
1313
from distutils import log
1414

15-
def get_platform ():
16-
"""Return a string that identifies the current platform. This is used
17-
mainly to distinguish platform-specific build directories and
15+
def get_platform():
16+
"""Return a string that identifies the current platform.
17+
18+
This is used mainly to distinguish platform-specific build directories and
1819
platform-specific built distributions. Typically includes the OS name
1920
and version and the architecture (as supplied by 'os.uname()'),
2021
although the exact information included depends on the OS; eg. for IRIX
@@ -153,11 +154,10 @@ def get_platform ():
153154

154155
return "%s-%s-%s" % (osname, release, machine)
155156

156-
# get_platform ()
157157

158+
def convert_path(pathname):
159+
"""Return 'pathname' as a name that will work on the native filesystem.
158160
159-
def convert_path (pathname):
160-
"""Return 'pathname' as a name that will work on the native filesystem,
161161
i.e. split it on '/' and put it back together again using the current
162162
directory separator. Needed because filenames in the setup script are
163163
always supplied in Unix style, and have to be converted to the local
@@ -181,12 +181,12 @@ def convert_path (pathname):
181181
return os.curdir
182182
return os.path.join(*paths)
183183

184-
# convert_path ()
185184

185+
def change_root(new_root, pathname):
186+
"""Return 'pathname' with 'new_root' prepended.
186187
187-
def change_root (new_root, pathname):
188-
"""Return 'pathname' with 'new_root' prepended. If 'pathname' is
189-
relative, this is equivalent to "os.path.join(new_root,pathname)".
188+
If 'pathname' is relative, this is equivalent to
189+
"os.path.join(new_root,pathname)".
190190
Otherwise, it requires making 'pathname' relative and then joining the
191191
two, which is tricky on DOS/Windows and Mac OS.
192192
"""
@@ -218,13 +218,15 @@ def change_root (new_root, pathname):
218218
return os.path.join(new_root, pathname)
219219

220220
else:
221-
raise DistutilsPlatformError("nothing known about platform '%s'" % os.name)
222-
221+
raise DistutilsPlatformError("nothing known about "
222+
"platform '%s'" % os.name)
223223

224224
_environ_checked = 0
225-
def check_environ ():
226-
"""Ensure that 'os.environ' has all the environment variables we
227-
guarantee that users can use in config files, command-line options,
225+
226+
def check_environ():
227+
"""Ensure that 'os.environ' has all the environment variables needed.
228+
229+
We guarantee that users can use in config files, command-line options,
228230
etc. Currently this includes:
229231
HOME - user's home directory (Unix only)
230232
PLAT - description of the current platform, including hardware
@@ -243,10 +245,10 @@ def check_environ ():
243245

244246
_environ_checked = 1
245247

248+
def subst_vars(s, local_vars):
249+
"""Perform shell/Perl-style variable substitution on 'string'.
246250
247-
def subst_vars (s, local_vars):
248-
"""Perform shell/Perl-style variable substitution on 'string'. Every
249-
occurrence of '$' followed by a name is considered a variable, and
251+
Every occurrence of '$' followed by a name is considered a variable, and
250252
variable is substituted by the value found in the 'local_vars'
251253
dictionary, or in 'os.environ' if it's not in 'local_vars'.
252254
'os.environ' is first checked/augmented to guarantee that it contains
@@ -266,12 +268,11 @@ def _subst (match, local_vars=local_vars):
266268
except KeyError as var:
267269
raise ValueError("invalid variable '$%s'" % var)
268270

269-
# subst_vars ()
270-
271+
def grok_environment_error(exc, prefix="error: "):
272+
"""Generate a useful error message from an EnvironmentError.
271273
272-
def grok_environment_error (exc, prefix="error: "):
273-
"""Generate a useful error message from an EnvironmentError (IOError or
274-
OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and
274+
This will generate an IOError or an OSError exception object.
275+
Handles Python 1.5.1 and 1.5.2 styles, and
275276
does what it can to deal with exception objects that don't have a
276277
filename (which happens when the error is due to a two-file operation,
277278
such as 'rename()' or 'link()'. Returns the error message as a string
@@ -290,26 +291,27 @@ def grok_environment_error (exc, prefix="error: "):
290291

291292
return error
292293

293-
294294
# Needed by 'split_quoted()'
295295
_wordchars_re = _squote_re = _dquote_re = None
296+
296297
def _init_regex():
297298
global _wordchars_re, _squote_re, _dquote_re
298299
_wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace)
299300
_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
300301
_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
301302

302-
def split_quoted (s):
303+
def split_quoted(s):
303304
"""Split a string up according to Unix shell-like rules for quotes and
304-
backslashes. In short: words are delimited by spaces, as long as those
305+
backslashes.
306+
307+
In short: words are delimited by spaces, as long as those
305308
spaces are not escaped by a backslash, or inside a quoted string.
306309
Single and double quotes are equivalent, and the quote characters can
307310
be backslash-escaped. The backslash is stripped from any two-character
308311
escape sequence, leaving only the escaped character. The quote
309312
characters are stripped from any quoted string. Returns a list of
310313
words.
311314
"""
312-
313315
# This is a nice algorithm for splitting up a single string, since it
314316
# doesn't require character-by-character examination. It was a little
315317
# bit of a brain-bender to get it working right, though...
@@ -357,13 +359,12 @@ def split_quoted (s):
357359

358360
return words
359361

360-
# split_quoted ()
361362

363+
def execute(func, args, msg=None, verbose=0, dry_run=0):
364+
"""Perform some action that affects the outside world.
362365
363-
def execute (func, args, msg=None, verbose=0, dry_run=0):
364-
"""Perform some action that affects the outside world (eg. by
365-
writing to the filesystem). Such actions are special because they
366-
are disabled by the 'dry_run' flag. This method takes care of all
366+
eg. by writing to the filesystem). Such actions are special because
367+
they are disabled by the 'dry_run' flag. This method takes care of all
367368
that bureaucracy for you; all you have to do is supply the
368369
function to call and an argument tuple for it (to embody the
369370
"external action" being performed), and an optional message to
@@ -379,7 +380,7 @@ def execute (func, args, msg=None, verbose=0, dry_run=0):
379380
func(*args)
380381

381382

382-
def strtobool (val):
383+
def strtobool(val):
383384
"""Convert a string representation of truth to true (1) or false (0).
384385
385386
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
@@ -395,15 +396,13 @@ def strtobool (val):
395396
raise ValueError("invalid truth value %r" % (val,))
396397

397398

398-
def byte_compile (py_files,
399-
optimize=0, force=0,
400-
prefix=None, base_dir=None,
401-
verbose=1, dry_run=0,
402-
direct=None):
399+
def byte_compile(py_files, optimize=0, force=0, prefix=None, base_dir=None,
400+
verbose=1, dry_run=0, direct=None):
403401
"""Byte-compile a collection of Python source files to either .pyc
404-
or .pyo files in the same directory. 'py_files' is a list of files
405-
to compile; any files that don't end in ".py" are silently skipped.
406-
'optimize' must be one of the following:
402+
or .pyo files in the same directory.
403+
404+
'py_files' is a list of files to compile; any files that don't end in
405+
".py" are silently skipped. 'optimize' must be one of the following:
407406
0 - don't optimize (generate .pyc)
408407
1 - normal optimization (like "python -O")
409408
2 - extra optimization (like "python -OO")
@@ -428,7 +427,6 @@ def byte_compile (py_files,
428427
generated in indirect mode; unless you know what you're doing, leave
429428
it set to None.
430429
"""
431-
432430
# First, if the caller didn't force us into direct or indirect mode,
433431
# figure out which mode we should be in. We take a conservative
434432
# approach: choose direct mode *only* if the current interpreter is
@@ -516,8 +514,8 @@ def byte_compile (py_files,
516514
dfile = file
517515
if prefix:
518516
if file[:len(prefix)] != prefix:
519-
raise ValueError("invalid prefix: filename %r doesn't start with %r"
520-
% (file, prefix))
517+
raise ValueError("invalid prefix: filename %r doesn't "
518+
"start with %r" % (file, prefix))
521519
dfile = dfile[len(prefix):]
522520
if base_dir:
523521
dfile = os.path.join(base_dir, dfile)
@@ -532,9 +530,8 @@ def byte_compile (py_files,
532530
log.debug("skipping byte-compilation of %s to %s",
533531
file, cfile_base)
534532

535-
# byte_compile ()
536533

537-
def rfc822_escape (header):
534+
def rfc822_escape(header):
538535
"""Return a version of the string escaped for inclusion in an
539536
RFC-822 header, by ensuring there are 8 spaces space after each newline.
540537
"""

0 commit comments

Comments
 (0)