From f449ea51aa9b72bf8d8ea7a19e87c5a169fc9605 Mon Sep 17 00:00:00 2001 From: Greg Ward Date: Sat, 16 Sep 2000 15:23:28 +0000 Subject: Generalized 'reinitialize_command()' so it can optionally reinitialize 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 | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index 1552dc0..b126a99 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -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 -- cgit v0.12