]> granicus.if.org Git - python/commitdiff
Generalized 'reinitialize_command()' so it can optionally reinitialize
authorGreg Ward <gward@python.net>
Sat, 16 Sep 2000 15:23:28 +0000 (15:23 +0000)
committerGreg Ward <gward@python.net>
Sat, 16 Sep 2000 15:23:28 +0000 (15:23 +0000)
the command's sub-commands as well (off by default).  This is essential if
we want to be be able to run (eg.) "install" twice in one run, as happens
when generating multiple built distributions in one run.

Lib/distutils/dist.py

index 1552dc0c41ddaadf7be8097c36fad238b939e4d1..b126a997575c2b2e6ad0b0e840c38cde112c241a 100644 (file)
@@ -733,7 +733,7 @@ class Distribution:
                       (source, command_name, option)
             setattr(command_obj, option, value)
 
-    def reinitialize_command (self, command):
+    def reinitialize_command (self, command, reinit_subcommands=0):
         """Reinitializes a command to the state it was in when first
         returned by 'get_command_obj()': ie., initialized but not yet
         finalized.  This provides the opportunity to sneak option
@@ -743,9 +743,18 @@ class Distribution:
         'finalize_options()' or 'ensure_finalized()') before using it for
         real.  
 
-        'command' should be a command name (string) or command object.
+        'command' should be a command name (string) or command object.  If
+        'reinit_subcommands' is true, also reinitializes the command's
+        sub-commands, as declared by the 'sub_commands' class attribute (if
+        it has one).  See the "install" command for an example.  Only
+        reinitializes the sub-commands that actually matter, ie. those
+        whose test predicates return true.
+
         Returns the reinitialized command object.
         """
+        print "reinitialize_command: command=%s" % command
+        print "  before: have_run =", self.have_run
+
         from distutils.cmd import Command
         if not isinstance(command, Command):
             command_name = command
@@ -759,6 +768,15 @@ class Distribution:
         command.finalized = 0
         self.have_run[command_name] = 0
         self._set_command_options(command)
+
+        print "  after:  have_run =", self.have_run
+
+        if reinit_subcommands:
+            print ("  reinitializing sub-commands: %s" %
+                   command.get_sub_commands())
+            for sub in command.get_sub_commands():
+                self.reinitialize_command(sub, reinit_subcommands)            
+
         return command