Home | History | Annotate | Download | only in distutils

Lines Matching defs:Command

27 # Regex to define acceptable Distutils command names.  This is not *quite*
30 # to look for a Python module named after the command.
37 to the Distutils commands specified on the command line.
49 # 'global_options' describes the command-line options that may be
53 # since every global option is also valid as a command option -- and we
136 filled in with real command objects by 'parse_command_line()'.
139 # Default values for our command-line options
148 # information here (and enough command-line options) that it's
156 # 'cmdclass' maps command names to class objects, so we
158 # we need to create a new command object, and 2) have a way
159 # for the setup script to override command classes
163 # are searched for. The factory for command 'foo' is expected
166 # is raised if no named package provides the command being
172 # not necessarily a setup script run from the command-line.
176 # 'command_options' is where we store command options between
177 # parsing them (from config files, the command-line, etc.) and when
178 # they are actually needed -- ie. when the command in question is
183 # 'dist_files' is the list of (command, pyversion, file) that
212 # the caller at all. 'command_obj' maps command names to
213 # Command instances -- that's how we enforce that every command
217 # 'have_run' maps command names to boolean values; it keeps track
218 # of whether we have actually run a particular command, to make it
219 # cheap to "run" a command whenever we think we might need to -- if
222 # It's only safe to query 'have_run' for a command class that has
224 # command object is created, and replaced with a true value when
225 # the command is successfully run. Thus it's probably best to use
234 # Pull out the set of command options and work on them
236 # command options will override any supplied redundantly
241 for (command, cmd_options) in options.items():
242 opt_dict = self.get_option_dict(command)
271 # no-user-cfg is handled before other command line args
289 def get_option_dict(self, command):
290 """Get the option dictionary for a given command. If that
291 command's option dictionary hasn't been created yet, then create it
295 dict = self.command_options.get(command)
297 dict = self.command_options[command] = {}
303 if commands is None: # dump all command option dicts
319 "no option dict for '%s' command" % cmd_name)
322 "option dict for '%s' command:" % cmd_name)
421 # -- Command-line parsing methods ----------------------------------
424 """Parse the setup script's command line, taken from the
429 and options for that command. Each new command terminates the
430 options for the previous command. The allowed options for a
431 command are determined by the 'user_options' attribute of the
432 command class -- thus, we have to be able to load command classes
433 in order to parse the command line. Any error in that 'options'
435 command-line raises DistutilsArgError. If no Distutils commands
436 were found on the command line, raises DistutilsArgError. Return
437 true if command-line was successfully parsed and we should carry
444 # that allows the user to interactively specify the "command line".
448 # We have to parse the command line a bit at a time -- global
449 # options, then the first command, then its options, and so on --
450 # because each command will be handled by a different class, and
452 # until we have loaded the command class, which doesn't happen
453 # until we know what the command is.
472 # "setup.py --help" and "setup.py --help command ...". For the
476 # each command listed on the command line.
497 ("command-packages=", None,
502 """Parse the command-line options for a single command.
504 of arguments, starting with the current command (whose options
506 the next command at the front of the list; will be the empty
507 list if there are no more commands on the command line. Returns
508 None if the user asked for help on this command.
511 from distutils.cmd import Command
513 # Pull the current command from the head of the command line
514 command = args[0]
515 if not command_re.match(command):
516 raise SystemExit, "invalid command name '%s'" % command
517 self.commands.append(command)
519 # Dig up the command class that implements this command, so we
520 # 1) know that it's a valid command, and 2) know which options
523 cmd_class = self.get_command_class(command)
527 # Require that the command class be derived from Command -- want
528 # to be sure that the basic "command" interface is implemented.
529 if not issubclass(cmd_class, Command):
531 "command class %s must subclass Command" % cmd_class
533 # Also make sure that the command object provides a list of its
538 ("command class %s must provide " +
542 # If the command class has a list of negative alias options,
549 # Check for help_options in command class. They have a different
586 # Put the options from the command-line into their official
588 opt_dict = self.get_option_dict(command)
590 opt_dict[name] = ("command line", value)
596 instance, analogous to the .finalize_options() method of Command
609 """Show help for the setup script command-line in the form of
610 several lists of command-line options. 'parser' should be a
618 lists per-command help for every command name or command class
623 from distutils.cmd import Command
641 for command in self.commands:
642 if isinstance(command, type) and issubclass(command, Command):
643 klass = command
645 klass = self.get_command_class(command)
652 parser.print_help("Options for '%s' command:" % klass.__name__)
659 (--help-commands or the metadata display options) on the command
717 (listed in distutils.command.__all__) and "extra commands"
718 (mentioned in self.cmdclass, but not a standard command). The
719 descriptions come from the command class attribute
722 import distutils.command
723 std_commands = distutils.command.__all__
748 """Get a list of (command, description) tuples.
750 distutils.command.__all__) and "extra commands" (mentioned in
751 self.cmdclass, but not a standard command). The descriptions come
752 from the command class attribute 'description'.
757 import distutils.command
758 std_commands = distutils.command.__all__
780 # -- Command
789 if "distutils.command" not in pkgs:
790 pkgs.insert(0, "distutils.command")
794 def get_command_class(self, command):
795 """Return the class that implements the Distutils command named by
796 'command'. First we check the 'cmdclass' dictionary; if the
797 command is mentioned there, we fetch the class object from the
798 dictionary and return it. Otherwise we load the command module
799 ("distutils.command." + command) and fetch the command class from
806 klass = self.cmdclass.get(command)
811 module_name = "%s.%s" % (pkgname, command)
812 klass_name = command
824 "invalid command '%s' (no class '%s' in module '%s')" \
825 % (command, klass_name, module_name)
827 self.cmdclass[command] = klass
830 raise DistutilsModuleError("invalid command '%s'" % command)
833 def get_command_obj(self, command, create=1):
834 """Return the command object for 'command'. Normally this object
835 is cached on a previous call to 'get_command_obj()'; if no command
836 object for 'command' is in the cache, then we either create and
839 cmd_obj = self.command_obj.get(command)
843 "creating '%s' command object" % command)
845 klass = self.get_command_class(command)
846 cmd_obj = self.command_obj[command] = klass(self)
847 self.have_run[command] = 0
850 # or on the command line. (NB. support for error
854 options = self.command_options.get(command)
863 attributes of an instance ('command').
865 'command_obj' must be a Command instance. If 'option_dict' is not
866 supplied, uses the standard option dictionary for this command
874 self.announce(" setting options for '%s' command:" % command_name)
898 ("error in %s: command '%s' has no such option '%s'"
903 def reinitialize_command(self, command, reinit_subcommands=0):
904 """Reinitializes a command to the state it was in when first
908 user-supplied values from the config files and command line.
909 You'll have to re-finalize the command object (by calling
913 'command' should be a command name (string) or command object. If
914 'reinit_subcommands' is true, also reinitializes the command's
916 it has one). See the "install" command for an example. Only
920 Returns the reinitialized command object.
922 from distutils.cmd import Command
923 if not isinstance(command, Command):
924 command_name = command
925 command = self.get_command_obj(command_name)
927 command_name = command.get_command_name()
929 if not command.finalized:
930 return command
931 command.initialize_options()
932 command.finalized = 0
934 self._set_command_options(command)
937 for sub in command.get_sub_commands():
940 return command
948 """Run each command that was seen on the setup script command line.
949 Uses the list of commands found and cache of command objects
957 def run_command(self, command):
958 """Do whatever it takes to run a command (including nothing at all,
959 if the command has already been run). Specifically: if we have
960 already created and run the command named by 'command', return
961 silently without doing anything. If the command named by 'command'
962 doesn't even have a command object yet, create one. Then invoke
963 'run()' on that command object (or an existing one).
966 if self.have_run.get(command):
969 log.info("running %s", command)
970 cmd_obj = self.get_command_obj(command)
973 self.have_run[command] = 1
1243 """Convert a 4-tuple 'help_options' list as found in various command