Skip to content

Commit cd8a114

Browse files
committed
Make setup.py less chatty by default.
This is a conservative version of SF patch 504889. It uses the log module instead of calling print in various places, and it ignores the verbose argument passed to many functions and set as an attribute on some objects. Instead, it uses the verbosity set on the logger via the command line. The log module is now preferred over announce() and warn() methods that exist only for backwards compatibility. XXX This checkin changes a lot of modules that have no test suite and aren't exercised by the Python build process. It will need substantial testing.
1 parent 6fa82a3 commit cd8a114

32 files changed

Lines changed: 260 additions & 313 deletions

‎Lib/distutils/archive_util.py‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from distutils.errors import DistutilsExecError
1212
from distutils.spawn import spawn
1313
from distutils.dir_util import mkpath
14+
from distutils import log
1415

1516
def make_tarball (base_name, base_dir, compress="gzip",
1617
verbose=0, dry_run=0):
@@ -42,13 +43,13 @@ def make_tarball (base_name, base_dir, compress="gzip",
4243
"bad value for 'compress': must be None, 'gzip', or 'compress'"
4344

4445
archive_name = base_name + ".tar"
45-
mkpath(os.path.dirname(archive_name), verbose=verbose, dry_run=dry_run)
46+
mkpath(os.path.dirname(archive_name), dry_run=dry_run)
4647
cmd = ["tar", "-cf", archive_name, base_dir]
47-
spawn(cmd, verbose=verbose, dry_run=dry_run)
48+
spawn(cmd, dry_run=dry_run)
4849

4950
if compress:
5051
spawn([compress] + compress_flags[compress] + [archive_name],
51-
verbose=verbose, dry_run=dry_run)
52+
dry_run=dry_run)
5253
return archive_name + compress_ext[compress]
5354
else:
5455
return archive_name
@@ -69,10 +70,10 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0):
6970
# no changes needed!
7071

7172
zip_filename = base_name + ".zip"
72-
mkpath(os.path.dirname(zip_filename), verbose=verbose, dry_run=dry_run)
73+
mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
7374
try:
7475
spawn(["zip", "-rq", zip_filename, base_dir],
75-
verbose=verbose, dry_run=dry_run)
76+
dry_run=dry_run)
7677
except DistutilsExecError:
7778

7879
# XXX really should distinguish between "couldn't find
@@ -89,10 +90,10 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0):
8990
"could neither find a standalone zip utility nor " +
9091
"import the 'zipfile' module") % zip_filename
9192

92-
if verbose:
93-
print "creating '%s' and adding '%s' to it" % \
94-
(zip_filename, base_dir)
95-
93+
94+
log.info("creating '%s' and adding '%s' to it",
95+
zip_filename, base_dir)
96+
9697
def visit (z, dirname, names):
9798
for name in names:
9899
path = os.path.normpath(os.path.join(dirname, name))
@@ -141,17 +142,15 @@ def make_archive (base_name, format,
141142
"""
142143
save_cwd = os.getcwd()
143144
if root_dir is not None:
144-
if verbose:
145-
print "changing into '%s'" % root_dir
145+
log.debug("changing into '%s'", root_dir)
146146
base_name = os.path.abspath(base_name)
147147
if not dry_run:
148148
os.chdir(root_dir)
149149

150150
if base_dir is None:
151151
base_dir = os.curdir
152152

153-
kwargs = { 'verbose': verbose,
154-
'dry_run': dry_run }
153+
kwargs = { 'dry_run': dry_run }
155154

156155
try:
157156
format_info = ARCHIVE_FORMATS[format]
@@ -164,8 +163,7 @@ def make_archive (base_name, format,
164163
filename = apply(func, (base_name, base_dir), kwargs)
165164

166165
if root_dir is not None:
167-
if verbose:
168-
print "changing back to '%s'" % save_cwd
166+
log.debug("changing back to '%s'", save_cwd)
169167
os.chdir(save_cwd)
170168

171169
return filename

‎Lib/distutils/bcppcompiler.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
CCompiler, gen_preprocess_options, gen_lib_options
2323
from distutils.file_util import write_file
2424
from distutils.dep_util import newer
25+
from distutils import log
2526

2627
class BCPPCompiler(CCompiler) :
2728
"""Concrete class that implements an interface to the Borland C/C++
@@ -108,7 +109,7 @@ def compile (self,
108109
ext = (os.path.splitext (src))[1]
109110

110111
if skip_sources[src]:
111-
self.announce ("skipping %s (%s up-to-date)" % (src, obj))
112+
log.debug("skipping %s (%s up-to-date)", src, obj)
112113
else:
113114
src = os.path.normpath(src)
114115
obj = os.path.normpath(obj)
@@ -178,7 +179,7 @@ def create_static_lib (self,
178179
except DistutilsExecError, msg:
179180
raise LibError, msg
180181
else:
181-
self.announce ("skipping %s (up-to-date)" % output_filename)
182+
log.debug("skipping %s (up-to-date)", output_filename)
182183

183184
# create_static_lib ()
184185

@@ -205,8 +206,8 @@ def link (self,
205206
self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
206207

207208
if runtime_library_dirs:
208-
self.warn ("I don't know what to do with 'runtime_library_dirs': "
209-
+ str (runtime_library_dirs))
209+
log.warn("I don't know what to do with 'runtime_library_dirs': %s",
210+
str(runtime_library_dirs))
210211

211212
if output_dir is not None:
212213
output_filename = os.path.join (output_dir, output_filename)
@@ -285,7 +286,6 @@ def link (self,
285286
if libfile is None:
286287
ld_args.append(lib)
287288
# probably a BCPP internal library -- don't warn
288-
# self.warn('library %s not found.' % lib)
289289
else:
290290
# full name which prefers bcpp_xxx.lib over xxx.lib
291291
ld_args.append(libfile)
@@ -313,7 +313,7 @@ def link (self,
313313
raise LinkError, msg
314314

315315
else:
316-
self.announce ("skipping %s (up-to-date)" % output_filename)
316+
log.debug("skipping %s (up-to-date)", output_filename)
317317

318318
# link ()
319319

‎Lib/distutils/ccompiler.py‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from distutils.dir_util import mkpath
1717
from distutils.dep_util import newer_pairwise, newer_group
1818
from distutils.util import split_quoted, execute
19-
19+
from distutils import log
2020

2121
class CCompiler:
2222
"""Abstract base class to define the interface that must be implemented
@@ -80,7 +80,6 @@ def __init__ (self,
8080
dry_run=0,
8181
force=0):
8282

83-
self.verbose = verbose
8483
self.dry_run = dry_run
8584
self.force = force
8685

@@ -808,8 +807,7 @@ def library_filename (self,
808807
# -- Utility methods -----------------------------------------------
809808

810809
def announce (self, msg, level=1):
811-
if self.verbose >= level:
812-
print msg
810+
log.debug(msg)
813811

814812
def debug_print (self, msg):
815813
from distutils.core import DEBUG
@@ -820,16 +818,16 @@ def warn (self, msg):
820818
sys.stderr.write ("warning: %s\n" % msg)
821819

822820
def execute (self, func, args, msg=None, level=1):
823-
execute(func, args, msg, self.verbose >= level, self.dry_run)
821+
execute(func, args, msg, self.dry_run)
824822

825823
def spawn (self, cmd):
826-
spawn (cmd, verbose=self.verbose, dry_run=self.dry_run)
824+
spawn (cmd, dry_run=self.dry_run)
827825

828826
def move_file (self, src, dst):
829-
return move_file (src, dst, verbose=self.verbose, dry_run=self.dry_run)
827+
return move_file (src, dst, dry_run=self.dry_run)
830828

831829
def mkpath (self, name, mode=0777):
832-
mkpath (name, mode, self.verbose, self.dry_run)
830+
mkpath (name, mode, self.dry_run)
833831

834832

835833
# class CCompiler
@@ -957,7 +955,10 @@ def new_compiler (plat=None,
957955
("can't compile C/C++ code: unable to find class '%s' " +
958956
"in module '%s'") % (class_name, module_name)
959957

960-
return klass (verbose, dry_run, force)
958+
# XXX The None is necessary to preserve backwards compatibility
959+
# with classes that expect verbose to be the first positional
960+
# argument.
961+
return klass (None, dry_run, force)
961962

962963

963964
def gen_preprocess_options (macros, include_dirs):

‎Lib/distutils/cmd.py‎

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from types import *
1414
from distutils.errors import *
1515
from distutils import util, dir_util, file_util, archive_util, dep_util
16-
16+
from distutils import log
1717

1818
class Command:
1919
"""Abstract base class for defining command classes, the "worker bees"
@@ -72,11 +72,15 @@ def __init__ (self, dist):
7272
# commands fallback on the Distribution's behaviour. None means
7373
# "not defined, check self.distribution's copy", while 0 or 1 mean
7474
# false and true (duh). Note that this means figuring out the real
75-
# value of each flag is a touch complicated -- hence "self.verbose"
76-
# (etc.) will be handled by __getattr__, below.
77-
self._verbose = None
75+
# value of each flag is a touch complicated -- hence "self._dry_run"
76+
# will be handled by __getattr__, below.
77+
# XXX This needs to be fixed.
7878
self._dry_run = None
7979

80+
# verbose is largely ignored, but needs to be set for
81+
# backwards compatibility (I think)?
82+
self.verbose = dist.verbose
83+
8084
# Some commands define a 'self.force' option to ignore file
8185
# timestamps, but methods defined *here* assume that
8286
# 'self.force' exists for all commands. So define it here
@@ -96,8 +100,10 @@ def __init__ (self, dist):
96100
# __init__ ()
97101

98102

103+
# XXX A more explicit way to customize dry_run would be better.
104+
99105
def __getattr__ (self, attr):
100-
if attr in ('verbose', 'dry_run'):
106+
if attr == 'dry_run':
101107
myval = getattr(self, "_" + attr)
102108
if myval is None:
103109
return getattr(self.distribution, attr)
@@ -186,9 +192,7 @@ def announce (self, msg, level=1):
186192
"""If the current verbosity level is of greater than or equal to
187193
'level' print 'msg' to stdout.
188194
"""
189-
if self.verbose >= level:
190-
print msg
191-
sys.stdout.flush()
195+
log.debug(msg)
192196

193197
def debug_print (self, msg):
194198
"""Print 'msg' to stdout if the global DEBUG (taken from the
@@ -352,12 +356,11 @@ def warn (self, msg):
352356

353357

354358
def execute (self, func, args, msg=None, level=1):
355-
util.execute(func, args, msg, self.verbose >= level, self.dry_run)
359+
util.execute(func, args, msg, dry_run=self.dry_run)
356360

357361

358362
def mkpath (self, name, mode=0777):
359-
dir_util.mkpath(name, mode,
360-
self.verbose, self.dry_run)
363+
dir_util.mkpath(name, mode, dry_run=self.dry_run)
361364

362365

363366
def copy_file (self, infile, outfile,
@@ -371,8 +374,7 @@ def copy_file (self, infile, outfile,
371374
preserve_mode, preserve_times,
372375
not self.force,
373376
link,
374-
self.verbose >= level,
375-
self.dry_run)
377+
dry_run=self.dry_run)
376378

377379

378380
def copy_tree (self, infile, outfile,
@@ -385,30 +387,21 @@ def copy_tree (self, infile, outfile,
385387
infile, outfile,
386388
preserve_mode,preserve_times,preserve_symlinks,
387389
not self.force,
388-
self.verbose >= level,
389-
self.dry_run)
390-
390+
dry_run=self.dry_run)
391391

392392
def move_file (self, src, dst, level=1):
393-
"""Move a file respecting verbose and dry-run flags."""
394-
return file_util.move_file(src, dst,
395-
self.verbose >= level,
396-
self.dry_run)
397-
393+
"""Move a file respectin dry-run flag."""
394+
return file_util.move_file(src, dst, dry_run = self.dry_run)
398395

399396
def spawn (self, cmd, search_path=1, level=1):
400-
"""Spawn an external command respecting verbose and dry-run flags."""
397+
"""Spawn an external command respecting dry-run flag."""
401398
from distutils.spawn import spawn
402-
spawn(cmd, search_path,
403-
self.verbose >= level,
404-
self.dry_run)
405-
399+
spawn(cmd, search_path, dry_run= self.dry_run)
406400

407401
def make_archive (self, base_name, format,
408402
root_dir=None, base_dir=None):
409403
return archive_util.make_archive(
410-
base_name, format, root_dir, base_dir,
411-
self.verbose, self.dry_run)
404+
base_name, format, root_dir, base_dir, dry_run=self.dry_run)
412405

413406

414407
def make_file (self, infiles, outfile, func, args,
@@ -443,7 +436,7 @@ def make_file (self, infiles, outfile, func, args,
443436

444437
# Otherwise, print the "skip" message
445438
else:
446-
self.announce(skip_msg, level)
439+
log.debug(skip_msg)
447440

448441
# make_file ()
449442

‎Lib/distutils/command/bdist_dumb.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from distutils.util import get_platform
1414
from distutils.dir_util import create_tree, remove_tree
1515
from distutils.errors import *
16+
from distutils import log
1617

1718
class bdist_dumb (Command):
1819

@@ -83,7 +84,7 @@ def run (self):
8384
install.skip_build = self.skip_build
8485
install.warn_dir = 0
8586

86-
self.announce("installing to %s" % self.bdist_dir)
87+
log.info("installing to %s" % self.bdist_dir)
8788
self.run_command('install')
8889

8990
# And make an archive relative to the root of the
@@ -101,7 +102,7 @@ def run (self):
101102
root_dir=self.bdist_dir)
102103

103104
if not self.keep_temp:
104-
remove_tree(self.bdist_dir, self.verbose, self.dry_run)
105+
remove_tree(self.bdist_dir, dry_run=self.dry_run)
105106

106107
# run()
107108

‎Lib/distutils/command/bdist_packager.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from distutils.dir_util import create_tree, remove_tree
1515
from distutils.file_util import write_file
1616
from distutils.errors import *
17+
from distutils import log
1718
import string, sys
1819

1920
class bdist_packager (Command):
@@ -102,8 +103,8 @@ def write_script (self,path,attr,default=None):
102103
else:
103104
setattr(self,attr,default)
104105
val = default
105-
if val!="":
106-
self.announce('Creating %s script', attr)
106+
if val != "":
107+
log.info('Creating %s script', attr)
107108
self.execute(write_file,
108109
(path, self.get_script(attr)),
109110
"writing '%s'" % path)
@@ -234,7 +235,7 @@ def run (self):
234235
install = self.reinitialize_command('install', reinit_subcommands=1)
235236
install.root = self.pkg_dir
236237

237-
self.announce("installing to %s" % self.pkg_dir)
238+
log.info("installing to %s", self.pkg_dir)
238239
self.run_command('install')
239240

240241
# And make an archive relative to the root of the
@@ -243,7 +244,7 @@ def run (self):
243244
self.plat_name)
244245

245246
if not self.keep_temp:
246-
remove_tree(self.pkg_dir, self.verbose, self.dry_run)
247+
remove_tree(self.pkg_dir, dry_run=self.dry_run)
247248

248249
# run()
249250

0 commit comments

Comments
 (0)