1010
1111class Command :
1212 """Abstract base class for defining command classes, the "worker bees"
13- of the Packaging. A useful analogy for command classes is to think of
13+ of Packaging. A useful analogy for command classes is to think of
1414 them as subroutines with local variables called "options". The options
1515 are "declared" in 'initialize_options()' and "defined" (given their
1616 final values, aka "finalized") in 'finalize_options()', both of which
@@ -351,7 +351,7 @@ def get_sub_commands(self):
351351 def execute (self , func , args , msg = None , level = 1 ):
352352 util .execute (func , args , msg , dry_run = self .dry_run )
353353
354- def mkpath (self , name , mode = 0o777 , dry_run = None , verbose = 0 ):
354+ def mkpath (self , name , mode = 0o777 , dry_run = None ):
355355 if dry_run is None :
356356 dry_run = self .dry_run
357357 name = os .path .normpath (name )
@@ -367,9 +367,11 @@ def mkpath(self, name, mode=0o777, dry_run=None, verbose=0):
367367
368368 def copy_file (self , infile , outfile ,
369369 preserve_mode = True , preserve_times = True , link = None , level = 1 ):
370- """Copy a file respecting verbose, dry-run and force flags. (The
371- former two default to whatever is in the Distribution object, and
372- the latter defaults to false for commands that don't define it.)"""
370+ """Copy a file respecting dry-run and force flags.
371+
372+ (dry-run defaults to whatever is in the Distribution object, and
373+ force to false for commands that don't define it.)
374+ """
373375 if self .dry_run :
374376 # XXX add a comment
375377 return
@@ -380,20 +382,21 @@ def copy_file(self, infile, outfile,
380382
381383 def copy_tree (self , infile , outfile , preserve_mode = True ,
382384 preserve_times = True , preserve_symlinks = False , level = 1 ):
383- """Copy an entire directory tree respecting verbose, dry-run,
385+ """Copy an entire directory tree respecting dry-run
384386 and force flags.
385387 """
386388 if self .dry_run :
387- return # see if we want to display something
388-
389+ # XXX should not return but let copy_tree log and decide to execute
390+ # or not based on its dry_run argument
391+ return
389392
390393 return util .copy_tree (infile , outfile , preserve_mode , preserve_times ,
391394 preserve_symlinks , not self .force , dry_run = self .dry_run )
392395
393396 def move_file (self , src , dst , level = 1 ):
394397 """Move a file respecting the dry-run flag."""
395398 if self .dry_run :
396- return # XXX log ?
399+ return # XXX same thing
397400 return move (src , dst )
398401
399402 def spawn (self , cmd , search_path = True , level = 1 ):
@@ -439,3 +442,20 @@ def make_file(self, infiles, outfile, func, args,
439442 # Otherwise, print the "skip" message
440443 else :
441444 logger .debug (skip_msg )
445+
446+ def byte_compile (self , files , prefix = None ):
447+ """Byte-compile files to pyc and/or pyo files.
448+
449+ This method requires that the calling class define compile and
450+ optimize options, like build_py and install_lib. It also
451+ automatically respects the force and dry-run options.
452+
453+ prefix, if given, is a string that will be stripped off the
454+ filenames encoded in bytecode files.
455+ """
456+ if self .compile :
457+ util .byte_compile (files , optimize = False , prefix = prefix ,
458+ force = self .force , dry_run = self .dry_run )
459+ if self .optimize :
460+ util .byte_compile (files , optimize = self .optimize , prefix = prefix ,
461+ force = self .force , dry_run = self .dry_run )
0 commit comments