def handle_display_options (self, option_order): """If there were any non-global "display-only" options (--help-commands or the metadata display options) on the command line, display the requested info and return true; else return false. """ from distutils.core import gen_usage # User just wants a list of commands -- we'll print it out and stop # processing now (ie. if they ran "setup --help-commands foo bar", # we ignore "foo bar"). if self.help_commands: self.print_commands() print print gen_usage(self.script_name) return 1 # If user supplied any of the "display metadata" options, then # display that metadata in the order in which the user supplied the # metadata options. any_display_options = 0 is_display_option = {} for option in self.display_options: is_display_option[option[0]] = 1 for (opt, val) in option_order: if val and is_display_option.get(opt): opt = translate_longopt(opt) print getattr(self.metadata, "get_"+opt)() any_display_options = 1 return any_display_options
def handle_display_options(self, option_order): """If there were any non-global "display-only" options (--help-commands or the metadata display options) on the command line, display the requested info and return true; else return false. """ from distutils.core import gen_usage if self.help_commands: self.print_commands() print "" print gen_usage(self.script_name) return 1 any_display_options = 0 is_display_option = {} for option in self.display_options: is_display_option[option[0]] = 1 for opt, val in option_order: if val and is_display_option.get(opt): opt = translate_longopt(opt) value = getattr(self.metadata, "get_" + opt)() if opt in ("keywords", "platforms"): print ",".join(value) elif opt in ("classifiers", "provides", "requires", "obsoletes"): print "\n".join(value) else: print value any_display_options = 1 return any_display_options
def _show_help (self, parser, global_options=1, display_options=1, commands=[]): # Gather the options for the distribution options = [] if global_options: if display_options: global_options = self._get_toplevel_options() else: global_options = self.global_options options.extend(global_options) if display_options: display_options = self.display_options options.extend(display_options) # Gather the options for the requested commands commands = [] for command in self.commands: klass = self.get_command_class(command) command_name = getattr(klass, 'command_name', klass.__name__) command_options = klass.user_options if hasattr(klass, 'help_options'): command_options = command_options + klass.help_options commands.append((command_name, command_options)) options.extend(command_options) # Determine maximum length of option names max_length = 0 for option in options: long = option[0] short = option[1] l = len(long) if long[-1] == '=': l = l - 1 if short is not None: l = l + 5 # " (-x)" where short == 'x' if l > max_length: max_length = l # Now print the option tables if global_options: self.print_option_list(global_options, "Global options:", max_length) if display_options: self.print_option_list(display_options, "Information display options (just display" " information, ignore any commands):", max_length) for name, options in commands: self.print_option_list(options, "Options for '%s' command:" % name, max_length) print gen_usage(self.script_name) return
def handle_display_options(self, option_order): """ Overrides handle_display_options() to update 'package_defaults' and handle the '--help-packages' option. """ # Update the default distribution options with any toplevel options # from the command-line. toplevel_options = {} help_options = {} display_options = {} any_display_options = False any_help_options = False for option in Dist.Dist._get_toplevel_options(self): toplevel_options[option[0]] = True for option in self.display_options: option = option[0] if option.startswith('help'): help_options[option] = True else: display_options[option] = True for option, value in option_order: if option in toplevel_options: name = translate_longopt(option) self.package_defaults[name] = value elif option in display_options: any_display_options = True elif option in help_options: any_help_options = True # User just wants a list of packages -- we'll print it out and stop # processing now (ie. if they ran "setup --help-packages foo bar", # we ignore "foo bar"). if self.help_packages: self.print_packages() print print core.gen_usage(self.script_name) return 1 if any_help_options: return Dist.Dist.handle_display_options(self, option_order) elif any_display_options: for dist in self.get_distributions(): print "Information for '%s' package:" % dist.get_name() for option, value in option_order: if value and option in display_options: name = translate_longopt(option) value = getattr(dist.metadata, "get_" + name)() if name in ('keywords', 'platforms'): value = ",".join(value) elif isinstance(value, list): value = "\n ".join(value) print " " + value print return any_display_options
def _show_help (self, parser, global_options=1, display_options=1, commands=[]): """Show help for the setup script command-line in the form of several lists of command-line options. 'parser' should be a FancyGetopt instance; do not expect it to be returned in the same state, as its option table will be reset to make it generate the correct help text. If 'global_options' is true, lists the global options: --verbose, --dry-run, etc. If 'display_options' is true, lists the "display-only" options: --name, --version, etc. Finally, lists per-command help for every command name or command class in 'commands'. """ # late import because of mutual dependence between these modules from distutils.core import gen_usage from distutils.cmd import Command if global_options: if display_options: options = self._get_toplevel_options() else: options = self.global_options parser.set_option_table(options) parser.print_help(self.common_usage + "\nGlobal options:") print if display_options: parser.set_option_table(self.display_options) parser.print_help( "Information display options (just display " + "information, ignore any commands)") print for command in self.commands: if type(command) is ClassType and issubclass(command, Command): klass = command else: klass = self.get_command_class(command) if (hasattr(klass, 'help_options') and type(klass.help_options) is ListType): parser.set_option_table(klass.user_options + fix_help_options(klass.help_options)) else: parser.set_option_table(klass.user_options) parser.print_help("Options for '%s' command:" % klass.__name__) print print gen_usage(self.script_name) return
def handle_display_options(self, option_order): """If there were any non-global "display-only" options (--help-commands) on the command line, display the requested info and return true; else return false. """ from distutils.core import gen_usage # User just wants a list of commands -- we'll print it out and stop # processing now (ie. if they ran # "some_utility.py --help-commands foo bar", # we ignore "foo bar"). if self.help_commands: self.print_commands() print print gen_usage(self.script_name) return 1 return 0
size = max(len(l) + 1 for l in lines) print('-' * (size + 2)) for l in lines: print('|{}{}|'.format(l, ' ' * (size - len(l)))) print('-' * (size + 2)) if __name__ == '__main__': # Parse the command line and check the arguments # before we proceed with building deps and setup dist = Distribution() dist.script_name = sys.argv[0] dist.script_args = sys.argv[1:] try: ok = dist.parse_command_line() except DistutilsArgError as msg: raise SystemExit(core.gen_usage(dist.script_name) + "\nerror: %s" % msg) if not ok: sys.exit() if RUN_BUILD_DEPS: build_deps() extensions, cmdclass, packages, entry_points, extra_install_requires = configure_extension_build() install_requires += extra_install_requires # Read in README.md for our long_description with open(os.path.join(cwd, "README.md"), encoding="utf-8") as f: long_description = f.read() setup(
for l in lines: print('|{}{}|'.format(l, ' ' * (size - len(l)))) print('-' * (size + 2)) if __name__ == '__main__': # Parse the command line and check the arguments # before we proceed with building deps and setup dist = Distribution() dist.script_name = sys.argv[0] dist.script_args = sys.argv[1:] try: ok = dist.parse_command_line() except DistutilsArgError as msg: raise SystemExit( core.gen_usage(dist.script_name) + "\nerror: %s" % msg) if not ok: sys.exit() if RUN_BUILD_DEPS: build_deps() extensions, cmdclass, packages, entry_points, extra_install_requires = configure_extension_build( ) install_requires += extra_install_requires # Read in README.md for our long_description with open(os.path.join(cwd, "README.md"), encoding="utf-8") as f: long_description = f.read()
"""distutils.dist
key_bdist = "bdist_rpm" if bdist_deb: key_bdist = "bdist_deb" if key_bdist: if dist.command_options.has_key(key_bdist): bdist_val = dist.command_options[key_bdist] if bdist_val.has_key('install_extra_opts'): install_extra_opts = bdist_val['install_extra_opts'][1] # Parse the command line; any command-line errors are the end user's # fault, so turn them into SystemExit to suppress tracebacks. try: ok = dist.parse_command_line() except DistutilsArgError, msg: raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg if DEBUG: print "options (after parsing command line):" dist.dump_option_dicts() if _setup_stop_after == "commandline": return dist #go on only if I create rpm or deb and I want join options (see no_join_opts option) if key_bdist: #go on only if in setup.cfg is now bdist_rpm or bdist_deb part if dist.command_options.has_key(key_bdist): bdist_val = dist.command_options[key_bdist] #go on only if in setup.cfg is install_extra_opts line (under #bdist_rpm or bdist_deb paragraph)