diff options
author | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-05-16 18:37:32 +0000 |
---|---|---|
committer | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-05-16 18:37:32 +0000 |
commit | 188789d8f445f9d7a4885025a7885b0f50c593a6 (patch) | |
tree | 693bfe5e4ef0f26465856e3f748895844bf46bfb /Lib/distutils/dist.py | |
parent | 5af55c63607fb6bebfc95c57e6eda5db0c669b46 (diff) | |
download | cpython-git-188789d8f445f9d7a4885025a7885b0f50c593a6.tar.gz |
Merged revisions 72686 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72686 | tarek.ziade | 2009-05-16 20:29:40 +0200 (Sat, 16 May 2009) | 1 line
pep8-fied distutils.dist module
........
Diffstat (limited to 'Lib/distutils/dist.py')
-rw-r--r-- | Lib/distutils/dist.py | 103 |
1 files changed, 38 insertions, 65 deletions
diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index 91adc4d37f..7969503507 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -262,21 +262,18 @@ Common commands: (see '--help-commands' for more) self.finalize_options() - - def get_option_dict (self, command): + def get_option_dict(self, command): """Get the option dictionary for a given command. If that command's option dictionary hasn't been created yet, then create it and return the new dictionary; otherwise, return the existing option dictionary. """ - dict = self.command_options.get(command) if dict is None: dict = self.command_options[command] = {} return dict - - def dump_option_dicts (self, header=None, commands=None, indent=""): + def dump_option_dicts(self, header=None, commands=None, indent=""): from pprint import pformat if commands is None: # dump all command option dicts @@ -300,11 +297,9 @@ Common commands: (see '--help-commands' for more) for line in out.split("\n"): print(indent + " " + line) - - # -- Config file finding/parsing methods --------------------------- - def find_config_files (self): + def find_config_files(self): """Find as many configuration files as should be processed for this platform, and return a list of filenames in the order in which they should be parsed. The filenames returned are guaranteed to exist @@ -345,9 +340,7 @@ Common commands: (see '--help-commands' for more) return files - - def parse_config_files (self, filenames=None): - + def parse_config_files(self, filenames=None): from configparser import ConfigParser if filenames is None: @@ -389,10 +382,9 @@ Common commands: (see '--help-commands' for more) except ValueError as msg: raise DistutilsOptionError(msg) - # -- Command-line parsing methods ---------------------------------- - def parse_command_line (self): + def parse_command_line(self): """Parse the setup script's command line, taken from the 'script_args' instance attribute (which defaults to 'sys.argv[1:]' -- see 'setup()' in core.py). This list is first processed for @@ -465,7 +457,7 @@ Common commands: (see '--help-commands' for more) # All is well: return true return True - def _get_toplevel_options (self): + def _get_toplevel_options(self): """Return the non-display options recognized at the top level. This includes options that are recognized *only* at the top @@ -476,7 +468,7 @@ Common commands: (see '--help-commands' for more) "list of packages that provide distutils commands"), ] - def _parse_command_opts (self, parser, args): + def _parse_command_opts(self, parser, args): """Parse the command-line options for a single command. 'parser' must be a FancyGetopt instance; 'args' must be the list of arguments, starting with the current command (whose options @@ -571,12 +563,11 @@ Common commands: (see '--help-commands' for more) return args - def finalize_options (self): + def finalize_options(self): """Set final values for all the options on the Distribution instance, analogous to the .finalize_options() method of Command objects. """ - keywords = self.metadata.keywords if keywords is not None: if isinstance(keywords, str): @@ -589,11 +580,8 @@ Common commands: (see '--help-commands' for more) platformlist = platforms.split(',') self.metadata.platforms = [x.strip() for x in platformlist] - def _show_help (self, - parser, - global_options=1, - display_options=1, - commands=[]): + 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 @@ -643,8 +631,7 @@ Common commands: (see '--help-commands' for more) print(gen_usage(self.script_name)) return - - def handle_display_options (self, option_order): + 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 @@ -684,7 +671,7 @@ Common commands: (see '--help-commands' for more) return any_display_options - def print_command_list (self, commands, header, max_length): + def print_command_list(self, commands, header, max_length): """Print a subset of the list of all commands -- used by 'print_commands()'. """ @@ -701,8 +688,7 @@ Common commands: (see '--help-commands' for more) print(" %-*s %s" % (max_length, cmd, description)) - - def print_commands (self): + def print_commands(self): """Print out a help message listing all available commands with a description of each. The list is divided into "standard commands" (listed in distutils.command.__all__) and "extra commands" @@ -735,7 +721,7 @@ Common commands: (see '--help-commands' for more) "Extra commands", max_length) - def get_command_list (self): + def get_command_list(self): """Get a list of (command, description) tuples. The list is divided into "standard commands" (listed in distutils.command.__all__) and "extra commands" (mentioned in @@ -769,7 +755,7 @@ Common commands: (see '--help-commands' for more) # -- Command class/object methods ---------------------------------- - def get_command_packages (self): + def get_command_packages(self): """Return a list of packages from which commands are loaded.""" pkgs = self.command_packages if not isinstance(pkgs, type([])): @@ -782,7 +768,7 @@ Common commands: (see '--help-commands' for more) self.command_packages = pkgs return pkgs - def get_command_class (self, command): + def get_command_class(self, command): """Return the class that implements the Distutils command named by 'command'. First we check the 'cmdclass' dictionary; if the command is mentioned there, we fetch the class object from the @@ -820,7 +806,7 @@ Common commands: (see '--help-commands' for more) raise DistutilsModuleError("invalid command '%s'" % command) - def get_command_obj (self, command, create=1): + def get_command_obj(self, command, create=1): """Return the command object for 'command'. Normally this object is cached on a previous call to 'get_command_obj()'; if no command object for 'command' is in the cache, then we either create and @@ -847,7 +833,7 @@ Common commands: (see '--help-commands' for more) return cmd_obj - def _set_command_options (self, command_obj, option_dict=None): + def _set_command_options(self, command_obj, option_dict=None): """Set the options for 'command_obj' from 'option_dict'. Basically this means copying elements of a dictionary ('option_dict') to attributes of an instance ('command'). @@ -888,7 +874,7 @@ Common commands: (see '--help-commands' for more) except ValueError as msg: raise DistutilsOptionError(msg) - def reinitialize_command (self, command, reinit_subcommands=0): + 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 @@ -927,13 +913,12 @@ Common commands: (see '--help-commands' for more) return command - # -- Methods that operate on the Distribution ---------------------- - def announce (self, msg, level=1): + def announce(self, msg, level=1): log.debug(msg) - def run_commands (self): + def run_commands(self): """Run each command that was seen on the setup script command line. Uses the list of commands found and cache of command objects created by 'get_command_obj()'. @@ -941,10 +926,9 @@ Common commands: (see '--help-commands' for more) for cmd in self.commands: self.run_command(cmd) - # -- Methods that operate on its Commands -------------------------- - def run_command (self, command): + def run_command(self, command): """Do whatever it takes to run a command (including nothing at all, if the command has already been run). Specifically: if we have already created and run the command named by 'command', return @@ -965,28 +949,28 @@ Common commands: (see '--help-commands' for more) # -- Distribution query methods ------------------------------------ - def has_pure_modules (self): + def has_pure_modules(self): return len(self.packages or self.py_modules or []) > 0 - def has_ext_modules (self): + def has_ext_modules(self): return self.ext_modules and len(self.ext_modules) > 0 - def has_c_libraries (self): + def has_c_libraries(self): return self.libraries and len(self.libraries) > 0 - def has_modules (self): + def has_modules(self): return self.has_pure_modules() or self.has_ext_modules() - def has_headers (self): + def has_headers(self): return self.headers and len(self.headers) > 0 - def has_scripts (self): + def has_scripts(self): return self.scripts and len(self.scripts) > 0 - def has_data_files (self): + def has_data_files(self): return self.data_files and len(self.data_files) > 0 - def is_pure (self): + def is_pure(self): return (self.has_pure_modules() and not self.has_ext_modules() and not self.has_c_libraries()) @@ -998,9 +982,6 @@ Common commands: (see '--help-commands' for more) # to self.metadata.get_XXX. The actual code is in the # DistributionMetadata class, below. -# class Distribution - - class DistributionMetadata: """Dummy class to hold the distribution meta-data: name, version, author, and so forth. @@ -1036,16 +1017,14 @@ class DistributionMetadata: self.requires = None self.obsoletes = None - def write_pkg_info (self, base_dir): + def write_pkg_info(self, base_dir): """Write the PKG-INFO file into the release tree. """ pkg_info = open( os.path.join(base_dir, 'PKG-INFO'), 'w') - self.write_pkg_file(pkg_info) - pkg_info.close() - def write_pkg_file (self, file): + def write_pkg_file(self, file): """Write the PKG-INFO format data to a file object. """ version = '1.0' @@ -1078,19 +1057,19 @@ class DistributionMetadata: self._write_list(file, 'Provides', self.get_provides()) self._write_list(file, 'Obsoletes', self.get_obsoletes()) - def _write_list (self, file, name, values): + def _write_list(self, file, name, values): for value in values: file.write('%s: %s\n' % (name, value)) # -- Metadata query methods ---------------------------------------- - def get_name (self): + def get_name(self): return self.name or "UNKNOWN" def get_version(self): return self.version or "0.0.0" - def get_fullname (self): + def get_fullname(self): return "%s-%s" % (self.get_name(), self.get_version()) def get_author(self): @@ -1106,14 +1085,10 @@ class DistributionMetadata: return self.maintainer_email or "UNKNOWN" def get_contact(self): - return (self.maintainer or - self.author or - "UNKNOWN") + return self.maintainer or self.author or "UNKNOWN" def get_contact_email(self): - return (self.maintainer_email or - self.author_email or - "UNKNOWN") + return self.maintainer_email or self.author_email or "UNKNOWN" def get_url(self): return self.url or "UNKNOWN" @@ -1141,7 +1116,6 @@ class DistributionMetadata: return self.download_url or "UNKNOWN" # PEP 314 - def get_requires(self): return self.requires or [] @@ -1170,8 +1144,7 @@ class DistributionMetadata: distutils.versionpredicate.VersionPredicate(v) self.obsoletes = value - -def fix_help_options (options): +def fix_help_options(options): """Convert a 4-tuple 'help_options' list as found in various command classes to the 3-tuple form required by FancyGetopt. """ |