[z @sdZddlZddlZddlZddlmZyddlZWnek rddZYnXddlTddl m Z m Z ddl m Z mZmZddlmZddlmZejd ZGd d d ZGd d d ZddZdS)z}distutils.dist Provides the Distribution class, which represents the module distribution being built/installed/distributed. N)message_from_file)*) FancyGetopttranslate_longopt) check_environ strtobool rfc822_escape)log)DEBUGz^[a-zA-Z]([a-zA-Z0-9_]*)$c@s%eZdZdZd~ddddgZdZdddddddddddddddddddddgZd>d?eDZidd6Zdd@dAZ dBdCZ dddDdEdFZ dGdHZ ddIdJZ dKdLZdMdNZdOdPZdQdRZddgdSdTZdUdVZdWdXZdYdZZd[d\Zd]d^Zd_d`ZddadbZddcddZdedfdgZejdhdiZdjdkZdldmZ dndoZ!dpdqZ"drdsZ#dtduZ$dvdwZ%dxdyZ&dzd{Z'd|d}Z(dS) DistributionaThe core of the Distutils. Most of the work hiding behind 'setup' is really done within a Distribution instance, which farms the work out to the Distutils commands specified on the command line. Setup scripts will almost never instantiate Distribution directly, unless the 'setup()' function is totally inadequate to their needs. However, it is conceivable that a setup script might wish to subclass Distribution for some specialized purpose, and then pass the subclass to 'setup()' as the 'distclass' keyword argument. If so, it is necessary to respect the expectations that 'setup' has of Distribution. See the code for 'setup()', in core.py, for details. verbosevrun verbosely (default)quietq!run quietly (turns verbosity off)dry-runndon't actually do anythinghelphshow detailed help message no-user-cfgN-ignore pydistutils.cfg in your home directoryzCommon commands: (see '--help-commands' for more) setup.py build will build the package underneath 'build/' setup.py install will install the package help-commandslist all available commandsnameprint package nameversionVprint package versionfullnameprint -authorprint the author's name author-email print the author's email address maintainerprint the maintainer's namemaintainer-email$print the maintainer's email addresscontact7print the maintainer's name if known, else the author's contact-email@print the maintainer's email address if known, else the author'surlprint the URL for this packagelicense print the license of the packagelicencealias for --license descriptionprint the package descriptionlong-description"print the long package description platformsprint the list of platforms classifiersprint the list of classifierskeywordsprint the list of keywordsprovides+print the list of packages/modules providedrequires+print the list of packages/modules required obsoletes0print the list of packages/modules made obsoletecCs g|]}t|dqS)r)r).0xrH$/usr/lib/python3.4/distutils/dist.py qs zDistribution.cCsid|_d|_d|_x!|jD]}t||dq%Wt|_x:|jjD],}d|}t||t|j|qXWi|_ d|_ d|_ d|_ i|_ g|_d|_i|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_i|_i|_|r|jd}|dk r|d=xY|jD]H\}}|j |}x*|jD]\} } d| f|| r:NcSsg|]}|jqSrH)strip)rFZelmrHrHrIrJ_s z1Distribution.finalize_options..,)zkeywordsz platforms)rVrTrstrrrR)rrrsrrHrHrIrqUs  zDistribution.finalize_optionsc Csvddlm}ddlm}|rr|r;|j}n |j}|j||j|jdt dn|r|j|j |jddt dnx|j D]}t |t rt||r|} n|j|} t| dr-t | jtr-|j| jt| jn|j| j|jd | jt dqWt ||jd S) abShow 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'. r) gen_usage)rz Global options:rLz*Information display options (just display z!information, ignore any commands)rzOptions for '%s' command:N)distutils.corerrrrrrZ print_help common_usageprintrrrtyperrrmrrrrrrY) rrrrrrrrrMruklassrHrHrIrbs6      zDistribution._show_helpc Csddlm}|jrD|jtdt||jdSd}i}x|jD]}d||dr:rr<r@rBrDrN)zkeywordsz platforms)z classifierszprovideszrequiresz obsoletes) rrZ help_commandsprint_commandsrrYrrerrVrTr) rrrrZany_display_optionsZis_display_optionoptionrwrxrrHrHrIrs,        z#Distribution.handle_display_optionscCst|dxw|D]o}|jj|}|sE|j|}ny |j}Wntk rld}YnXtd|||fqWdS)zZPrint a subset of the list of all commands -- used by 'print_commands()'. :z(no description available)z %-*s %sN)rrWrerr6AttributeError)rrrr max_lengthcmdrr6rHrHrIprint_command_lists    zDistribution.print_command_listcCsddl}|jj}i}x|D]}d||Get a list of (command, description) tuples. The list is divided into "standard commands" (listed in distutils.command.__all__) and "extra commands" (mentioned in self.cmdclass, but not a standard command). The descriptions come from the command class attribute 'description'. rNrz(no description available)) rrurrWrrerrr6r) rrrrrrrrvrr6rHrHrIget_command_lists(      zDistribution.get_command_listcCsx|j}t|tst|dkr-d}ndd|jdD}d|krh|jddn||_n|S)z9Return a list of packages from which commands are loaded.NrLcSs(g|]}|dkr|jqS)rL)r)rFZpkgrHrHrIrJs z5Distribution.get_command_packages..rzdistutils.commandr)rXrrrinsert)rrZpkgsrHrHrIget_command_packagess     z!Distribution.get_command_packagescCs|jj|}|r|Sx|jD]}d||f}|}yt|tj|}Wntk rww)YnXyt||}Wn+tk rt d|||fYnX||j|<|SWt d|dS)aoReturn 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 dictionary and return it. Otherwise we load the command module ("distutils.command." + command) and fetch the command class from the module. The loaded class is also stored in 'cmdclass' to speed future calls to 'get_command_class()'. Raises DistutilsModuleError if the expected module could not be found, or if that module does not define the expected class. z%s.%sz3invalid command '%s' (no class '%s' in module '%s')zinvalid command '%s'N) rWrer __import__rjr ImportErrorrVrr)rrrurZpkgnameZ module_nameZ klass_namemodulerHrHrIrs(     zDistribution.get_command_classcCs|jj|}| r|rtr9|jd|n|j|}||}|j|.z1error in %s: command '%s' has no such option '%s')get_command_namergr rrfZboolean_optionsrrrrrRrrmrr) rrrcZ option_dict command_namersourcerZ bool_optsZneg_optZ is_stringryrHrHrIr]s>        z!Distribution._set_command_optionsrcCsddlm}t||s7|}|j|}n |j}|jsP|S|jd|_d|j|<|j||rx'|j D]}|j ||qWn|S)aReinitializes 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 values in programmatically, overriding or supplementing user-supplied values from the config files and command line. You'll have to re-finalize the command object (by calling 'finalize_options()' or 'ensure_finalized()') before using it for real. '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. r)r) rrrrrZ finalizedZinitialize_optionsrdrZget_sub_commandsreinitialize_command)rrruZreinit_subcommandsrrsubrHrHrIrs      z!Distribution.reinitialize_commandcCstj||dS)N)r )rrrylevelrHrHrIrszDistribution.announcecCs%x|jD]}|j|q WdS)zRun 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()'. N)r run_command)rrrrHrHrI run_commandsszDistribution.run_commandscCsZ|jj|rdStjd||j|}|j|jd|j|Zd?d@ZdAdBZdCdDZdEdFZdGdHZdIdJZdKdLZ dMdNZ!dS)PrSz]Dummy class to hold the distribution meta-data: name, version, author, and so forth. rrr$ author_emailr(maintainer_emailr0r2r6long_descriptionr>r:r"r, contact_emailr< download_urlr@rBrDNcCs|dk r"|jt|nd|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_dS)N) read_pkg_fileopenrrr$rr(rr0r2r6rr>r:r<rr@rBrD)rrrrHrHrIr|s&                 zDistributionMetadata.__init__cst|fdd}fdd}d}|d|_|d|_|d|_|d |_d |_|d |_d |_|d |_|d |_ dkr|d|_ n d |_ |d|_ |d|_dkr!|dj d|_ n|d|_|d|_|dkr{|d|_|d|_|d|_nd |_d |_d |_d S)z-Reads the metadata values from a file object.cs|}|dkrdS|S)NUNKNOWNrH)rr)ryrHrI _read_fields  z7DistributionMetadata.read_pkg_file.._read_fieldcs&j|d}|gkr"dS|S)N)Zget_all)rvalues)ryrHrI _read_list%s z6DistributionMetadata.read_pkg_file.._read_listzmetadata-versionrrZsummaryr$Nz author-emailz home-pager2z download-urlr6r>rplatformZ classifierz1.1rBr@rD)rrrr6r$r(rrr0r2rrrr>r:r<rBr@rD)rrfiler rZmetadata_versionrH)ryrIr s:          z"DistributionMetadata.read_pkg_filec Cs>ttjj|dddd}|j|WdQXdS)z7Write the PKG-INFO file into the release tree. zPKG-INFOwencodingzUTF-8N)r rrrwrite_pkg_file)rrZbase_dirZpkg_inforHrHrIwrite_pkg_infoOs z#DistributionMetadata.write_pkg_infocCsd}|js3|js3|js3|js3|jr<d}n|jd||jd|j|jd|j|jd|j|jd|j |jd|j |jd |j |jd |j |jr|jd |jnt |j}|jd |d j|j}|r`|jd|n|j|d|j|j|d|j|j|d|j|j|d|j|j|d|jdS)z9Write the PKG-INFO format data to a file object. z1.0z1.1zMetadata-Version: %s z Name: %s z Version: %s z Summary: %s zHome-page: %s z Author: %s zAuthor-email: %s z License: %s zDownload-URL: %s zDescription: %s rz Keywords: %s ZPlatformZ ClassifierZRequiresZProvidesZ ObsoletesN)r@rBrDr<rrlget_name get_versionget_descriptionget_url get_contactget_contact_email get_licenserget_long_descriptionr get_keywords _write_list get_platformsget_classifiers get_requires get_provides get_obsoletes)rrrrZ long_descr>rHrHrIrVs0  z#DistributionMetadata.write_pkg_filecCs,x%|D]}|jd||fqWdS)Nz%s: %s )rl)rrrrr rrHrHrIrxs z DistributionMetadata._write_listcCs |jp dS)Nr )r)rrrHrHrIr~szDistributionMetadata.get_namecCs |jp dS)Nz0.0.0)r)rrrHrHrIrsz DistributionMetadata.get_versioncCsd|j|jfS)Nz%s-%s)rr)rrrHrHrI get_fullnamesz!DistributionMetadata.get_fullnamecCs |jp dS)Nr )r$)rrrHrHrI get_authorszDistributionMetadata.get_authorcCs |jp dS)Nr )r)rrrHrHrIget_author_emailsz%DistributionMetadata.get_author_emailcCs |jp dS)Nr )r()rrrHrHrIget_maintainersz#DistributionMetadata.get_maintainercCs |jp dS)Nr )r)rrrHrHrIget_maintainer_emailsz)DistributionMetadata.get_maintainer_emailcCs|jp|jpdS)Nr )r(r$)rrrHrHrIrsz DistributionMetadata.get_contactcCs|jp|jpdS)Nr )rr)rrrHrHrIrsz&DistributionMetadata.get_contact_emailcCs |jp dS)Nr )r0)rrrHrHrIrszDistributionMetadata.get_urlcCs |jp dS)Nr )r2)rrrHrHrIrsz DistributionMetadata.get_licensecCs |jp dS)Nr )r6)rrrHrHrIrsz$DistributionMetadata.get_descriptioncCs |jp dS)Nr )r)rrrHrHrIrsz)DistributionMetadata.get_long_descriptioncCs |jp gS)N)r>)rrrHrHrIrsz!DistributionMetadata.get_keywordscCs|jpdgS)Nr )r:)rrrHrHrIrsz"DistributionMetadata.get_platformscCs |jp gS)N)r<)rrrHrHrIr sz$DistributionMetadata.get_classifierscCs |jp dS)Nr )r)rrrHrHrIget_download_urlsz%DistributionMetadata.get_download_urlcCs |jp gS)N)rB)rrrHrHrIr!sz!DistributionMetadata.get_requirescCs:ddl}x|D]}|jj|qW||_dS)Nr)distutils.versionpredicateversionpredicateVersionPredicaterB)rrrrr rHrHrI set_requiress  z!DistributionMetadata.set_requirescCs |jp gS)N)r@)rrrHrHrIr"sz!DistributionMetadata.get_providescCsMdd|D}x*|D]"}ddl}|jj|qW||_dS)NcSsg|]}|jqSrH)r)rFr rHrHrIrJs z5DistributionMetadata.set_provides..r)r*r+Zsplit_provisionr@)rrrr rrHrHrI set_providess   z!DistributionMetadata.set_providescCs |jp gS)N)rD)rrrHrHrIr#sz"DistributionMetadata.get_obsoletescCs:ddl}x|D]}|jj|qW||_dS)Nr)r*r+r,rD)rrrrr rHrHrI set_obsoletess  z"DistributionMetadata.set_obsoletes)znamezversionzauthorz author_emailz maintainerzmaintainer_emailzurllicensez descriptionzlong_descriptionzkeywordsz platformszfullnamezcontactrr0z classifiersz download_urlzprovideszrequiresz obsoletes)"rrrrrUr|r rrrrrr$r%r&r'r(rrrrZ get_licencerrrrr r)r!r-r"r.r#r/rHrHrHrIrSsJ  4  "                       rScCs2g}x%|D]}|j|ddq W|S)zConvert a 4-tuple 'help_options' list as found in various command classes to the 3-tuple form required by FancyGetopt. r)r)rMZ new_optionsZ help_tuplerHrHrIrs r)rrjrreZemailrrhrZdistutils.errorsZdistutils.fancy_getoptrrZdistutils.utilrrrrr Zdistutils.debugr compilerr rSrrHrHrHrIs$$