a  ze@sddlZddlZddlZddlmZz ddlZWneyFdZYn0ddlTddlm Z m Z ddl m Z m Z mZddlmZddlmZedZd d ZGd d d ZGd ddZddZdS)N)message_from_file)*) FancyGetopttranslate_longopt) check_environ strtobool rfc822_escapelog)DEBUGz^[a-zA-Z]([a-zA-Z0-9_]*)$cCsLt|tr nd?Z#d@dAZ$dBdCZ%dDdEZ&dFdGZ'dS)N Distribution))verbosevzrun verbosely (default))quietqz!run quietly (turns verbosity off))zdry-runnzdon't actually do anything)helphzshow detailed help message)z no-user-cfgNz-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 ))z help-commandsNzlist all available commands)nameNzprint package name)versionVzprint package version)fullnameNzprint -)authorNzprint the author's name) author-emailNz print the author's email address) maintainerNzprint the maintainer's name)zmaintainer-emailNz$print the maintainer's email address)contactNz7print the maintainer's name if known, else the author's)z contact-emailNz@print the maintainer's email address if known, else the author's)urlNzprint the URL for this package)licenseNz print the license of the package)licenceNzalias for --license) descriptionNzprint the package description)zlong-descriptionNz"print the long package description) platformsNzprint the list of platforms) classifiersNzprint the list of classifiers)keywordsNzprint the list of keywords)providesNz+print the list of packages/modules provided)requiresNz+print the list of packages/modules required) obsoletesNz0print the list of packages/modules made obsoletecCsg|]}t|dqS)rr).0xrrr zDistribution.rrNcCs\d|_d|_d|_|jD]}t||dqt|_|jjD] }d|}t||t|j|q:i|_ d|_ d|_ d|_ i|_ g|_d|_i|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_i|_i|_|r|d}|dur8|d=|D]4\}}| |}|D]\} } d| f|| <qqd|vr~|d|d<|d=d } t!durnt!"| nt#j$%| d |D]\} } t&|jd | rt|jd | | nNt&|j| rt|j| | n0t&|| rt|| | nd t'| } t!"| qd |_(|j durP|j D].} | )ds6qP| dkr d|_(qPq |*dS)Nrrget_optionsz setup scriptr-r,z:'licence' distribution option is deprecated; use 'license' Zset_zUnknown distribution option: %sT-z --no-user-cfgF)+rdry_runr!display_option_namessetattrDistributionMetadatametadata_METHOD_BASENAMESgetattrcmdclasscommand_packages script_name script_argscommand_optionsZ dist_filespackagesZ package_dataZ package_dir py_modules librariesheaders ext_modulesZ ext_packageZ include_dirsZ extra_pathscripts data_filespassword command_objhave_rungetitemsget_option_dictwarningswarnsysstderrwritehasattrrepr want_user_cfg startswithfinalize_options)selfattrsattrbasenameZ method_namer<commandZ cmd_optionsopt_dictoptvalrkeyargrrr__init__s~                   zDistribution.__init__cCs&|j|}|dur"i}|j|<|SN)rJrU)rbrfdictrrrrW&s zDistribution.get_option_dictr;c Csddlm}|dur"t|j}|dur@||||d}|sV||ddS|D]h}|j|}|dur||d|qZ||d|||}|dD]}||d|qqZdS)Nr)pformatz zno commands known yetzno option dict for '%s' commandzoption dict for '%s' command:r=)ZpprintrosortedrJkeysannouncerUsplit) rbheadercommandsindentroZcmd_namergoutlinerrrdump_option_dicts1s*  zDistribution.dump_option_dictscCsg}ttjtjdj}tj|d}tj|rB| |tj dkrRd}nd}|j rtjtj d|}tj|r| |d}tj|r| |t r|dd ||S) N distutilsz distutils.cfgposixz.pydistutils.cfgzpydistutils.cfg~z setup.cfgzusing config files: %sz, )rospathdirnamerZmodules__file__joinisfileappendr#r_ expanduserr rr)rbfilesZsys_dirZsys_fileZ user_filenameZ user_fileZ local_filerrrfind_config_filesMs&       zDistribution.find_config_filesc Csddlm}tjtjkr"gd}ng}t|}|dur>|}trL|d|}|D]}trl|d|| || D]V}| |}| |}|D]8} | dkr| |vr| || } | dd} || f|| <qq~|qVd |jvr|jd D]\} \} } |j | } zF| r.t|| t|  n(| d vrJt|| t| n t|| | Wqty} zt| WYd} ~ qd} ~ 00qdS) Nr) ConfigParser) z install-basezinstall-platbasez install-libzinstall-platlibzinstall-purelibzinstall-headerszinstall-scriptsz install-dataprefixz exec-prefixhomeuserrootz"Distribution.parse_config_files():z reading %srr>_global)rr?) configparserrrZr base_prefix frozensetrr rrreadZsectionsr<rWrUreplacerlrJrV negative_optrAr ValueErrorDistutilsOptionError)rb filenamesrZignore_optionsparserfilenamesectionr<rgrhrisrcaliasrrrrparse_config_files}sD              zDistribution.parse_config_filescCs|}g|_t||j}||j|ddi|j|j|d}| }t |j | |rhdS|r|||}|durhdSqh|jr|j|t|jdk|jddS|jstddS)Nr-r,)argsobjectrdisplay_optionsruzno commands suppliedT)_get_toplevel_optionsrurrset_negative_aliasesrZ set_aliasesgetoptrIZget_option_orderr Z set_verbosityrhandle_display_options_parse_command_optsr! _show_helplenDistutilsArgError)rbZtoplevel_optionsrr option_orderrrrparse_command_lines.      zDistribution.parse_command_linecCs |jdgS)N)zcommand-packages=Nz0list of packages that provide distutils commands)global_optionsrbrrrrsz"Distribution._get_toplevel_optionsc Csddlm}|d}t|s*td||j|z||}Wn,typ}zt |WYd}~n d}~00t ||st d|t |drt |jtsd}t |||j}t |dr|}||jt |drt |jtrt|j}ng}||j|j|||||d d\}} t | d rX| jrX|j|d|gd dSt |drt |jtrd} |jD]F\} } } }t | || r|d } t|r|nt d || fq|| rdS||}t| D]\}}d |f||<q|S)NrCommandzinvalid command name '%s'z&command class %s must subclass Command user_optionszIcommand class %s must provide 'user_options' attribute (a list of tuples)r help_optionsrr!rzYinvalid help function %r for help option '%s': must be a callable object (function, etc.)z command line) distutils.cmdr command_rematch SystemExitrurget_command_classDistutilsModuleErrorr issubclassZDistutilsClassErrorr]r rrrcopyupdaterfix_help_optionsset_option_tablerrrr!rZ get_attr_namecallablerWvarsrV)rbrrrrfZ cmd_classrrrZoptsZhelp_option_foundZ help_optionZshortZdescfuncrgr#rrrrrsr                  z Distribution._parse_command_optscCsPdD]F}t|j|}|durqt|trdd|dD}t|j||qdS)Nr1r/cSsg|] }|qSrstrip)r6Zelmrrrr8jr9z1Distribution.finalize_options..,)rErCr rrsrA)rbrdrrrrra`s  zDistribution.finalize_optionsrc Csddlm}ddlm}|rR|r*|}n|j}||||jdt d|rt||j |dt d|j D]z}t |t rt||r|} n ||} t| drt | jtr|| jt| jn || j|d| jt dqzt ||jdS) Nr gen_usagerz Global options:r;zKInformation display options (just display information, ignore any commands)rzOptions for '%s' command:)distutils.corerrrrrr print_help common_usageprintrrur rrrr]rrrrrrH) rbrrrrurrr<rfklassrrrrms:           zDistribution._show_helpc Csddlm}|jr4|tdt||jdSd}i}|jD]}d||d<qB|D]l\}}|rX||rXt|}t |j d|}|dvrtd |n |dvrtd |nt|d}qX|S) Nrrr;rr:rr)r0r2r3r4r=) rrZ help_commandsprint_commandsrrHrrUrrErCr) rbrrZany_display_optionsZis_display_optionoptionrhrirrrrrs*   z#Distribution.handle_display_optionsc Csht|d|D]R}|j|}|s.||}z |j}WntyNd}Yn0td|||fqdS)N:(no description available)z %-*s %s)rrFrUrr.AttributeError)rbrurt max_lengthcmdrr.rrrprint_command_lists      zDistribution.print_command_listcCsddl}|jj}i}|D] }d||<qg}|jD]}||s4||q4d}||D]}t||krZt|}qZ||d||rt ||d|dS)NrrzStandard commandszExtra commands) distutils.commandrf__all__rFrqrUrrrr)rbrz std_commandsis_stdrextra_commandsrrrrrs.      zDistribution.print_commandsc Csddl}|jj}i}|D] }d||<qg}|jD]}||s4||q4g}||D]N}|j|}|sx||}z |j}Wnt yd}Yn0|||fqZ|S)Nrrr) rrfrrFrqrUrrr.r) rbrzrrrrrvrr.rrrget_command_lists(          zDistribution.get_command_listcCsN|j}t|tsJ|durd}dd|dD}d|vrD|dd||_|S)Nr;cSsg|]}|dkr|qS)r;r)r6Zpkgrrrr8!r9z5Distribution.get_command_packages..rzdistutils.commandr)rGr rrsinsert)rbZpkgsrrrget_command_packagess  z!Distribution.get_command_packagesc Cs|j|}|r|S|D]}d||f}|}zt|tj|}Wnty\YqYn0zt||}Wn$tyt d|||fYn0||j|<|St d|dS)Nz%s.%sz3invalid command '%s' (no class '%s' in module '%s')zinvalid command '%s') rFrUr __import__rZr ImportErrorrErr)rbrfrZpkgname module_nameZ klass_namemodulerrrr's,        zDistribution.get_command_classcCsl|j|}|sh|rhtr&|d|||}||}|j|<d|j|<|j|}|rh||||S)Nz.z1error in %s: command '%s' has no such option '%s')get_command_namerWr rrrVZboolean_optionsrrr rrArr]rr) rbrSZ option_dict command_namersourcerZ bool_optsZneg_optZ is_stringrrrrrhsF             z!Distribution._set_command_optionsrcCs|ddlm}t||s&|}||}n|}|js8|S|d|_d|j|<|||rx| D]}| ||qf|S)Nrr) rrr rrZ finalizedZinitialize_optionsrTrZget_sub_commandsreinitialize_command)rbrfZreinit_subcommandsrrsubrrrrs      z!Distribution.reinitialize_commandcCst||dSrmr )rbrlevelrrrrrszDistribution.announcecCs|jD]}||qdSrm)ru run_command)rbrrrr run_commandss zDistribution.run_commandscCsD|j|rdStd|||}||d|j|<dS)Nz running %sr)rTrUr inforZensure_finalizedrun)rbrfrrrrrs   zDistribution.run_commandcCst|jp|jpgdkSNr)rrKrLrrrrhas_pure_modulesszDistribution.has_pure_modulescCs|jot|jdkSr)rOrrrrrhas_ext_modulesszDistribution.has_ext_modulescCs|jot|jdkSr)rMrrrrrhas_c_librariesszDistribution.has_c_librariescCs|p|Srm)rrrrrr has_modulesszDistribution.has_modulescCs|jot|jdkSr)rNrrrrr has_headersszDistribution.has_headerscCs|jot|jdkSr)rPrrrrr has_scriptsszDistribution.has_scriptscCs|jot|jdkSr)rQrrrrrhas_data_filesszDistribution.has_data_filescCs|o| o| Srm)rrrrrrris_pures zDistribution.is_pure)N)NNr;)N)r)N)r)(r __module__ __qualname__rrrr@rrlrWryrrrrrrarrrrrrrrrrr INFOrrrrrrrrrrrrrrrrr,sL ,  0 :C [  2(!" &  , ) rc@seZdZdZdAddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"ZeZd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Z d;d<Z!d=d>Z"d?d@Z#dS)BrB)r#r$r' author_emailr)maintainer_emailr+r,r.long_descriptionr1r/r&r*Z contact_emailr0 download_urlr2r3r4NcCs|dur|t|nfd|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_dSrm) read_pkg_fileopenr#r$r'rr)rr+r,r.rr1r/r0rr2r3r4)rbr~rrrrl s&zDistributionMetadata.__init__cst|fdd}fdd}d}|d|_|d|_|d|_|d |_d|_|d |_d|_|d |_|d |_ d vr|d |_ nd|_ |d|_ |d|_dvr|d d|_ |d|_|d|_|dkr|d|_|d|_|d|_nd|_d|_d|_dS)Ncs|}|dkrdS|SNZUNKNOWNr)r#rrrr _read_field(sz7DistributionMetadata.read_pkg_file.._read_fieldcs|d}|gkrdS|Srm)Zget_all)r#valuesrrr _read_list.s z6DistributionMetadata.read_pkg_file.._read_listzmetadata-versionr#r$Zsummaryr'r(z home-pager,z download-urlr.r1rplatformZ classifier1.1r3r2r4)rr#r$r.r'r)rrr+r,rrrsr1r/r0r3r2r4)rbfilerrZmetadata_versionrrrr$s:                 z"DistributionMetadata.read_pkg_filecCsFttj|dddd}||Wdn1s80YdS)NzPKG-INFOwzUTF-8)encoding)rr}r~rwrite_pkg_file)rbbase_dirZpkg_inforrrwrite_pkg_infoXs z#DistributionMetadata.write_pkg_infocCsbd}|js"|js"|js"|js"|jr&d}|d||d||d||d||d| |d| |d | |d | |jr|d |jt |}|d |d |}|r|d|||d|||d|||d|||d|||d|dS)Nz1.0rzMetadata-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 Obsoletes)r2r3r4r0rr\get_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)rbrr$Z long_descr1rrrr _s6 z#DistributionMetadata.write_pkg_filecCs |D]}|d||fqdS)Nz%s: %s )r\)rbrr#rrrrrrsz DistributionMetadata._write_listcCs |jpdSr)r#rrrrr szDistributionMetadata.get_namecCs |jpdS)Nz0.0.0)r$rrrrrsz DistributionMetadata.get_versioncCsd||fS)Nz%s-%s)r rrrrr get_fullnamesz!DistributionMetadata.get_fullnamecCs |jpdSr)r'rrrr get_authorszDistributionMetadata.get_authorcCs |jpdSr)rrrrrget_author_emailsz%DistributionMetadata.get_author_emailcCs |jpdSr)r)rrrrget_maintainersz#DistributionMetadata.get_maintainercCs |jpdSr)rrrrrget_maintainer_emailsz)DistributionMetadata.get_maintainer_emailcCs|jp|jpdSr)r)r'rrrrrsz DistributionMetadata.get_contactcCs|jp|jpdSr)rrrrrrrsz&DistributionMetadata.get_contact_emailcCs |jpdSr)r+rrrrrszDistributionMetadata.get_urlcCs |jpdSr)r,rrrrrsz DistributionMetadata.get_licensecCs |jpdSr)r.rrrrrsz$DistributionMetadata.get_descriptioncCs |jpdSr)rrrrrrsz)DistributionMetadata.get_long_descriptioncCs |jpgSrm)r1rrrrrsz!DistributionMetadata.get_keywordscCst|d|_dS)Nr1)rr1rbrrrr set_keywordssz!DistributionMetadata.set_keywordscCs |jp dgSr)r/rrrrrsz"DistributionMetadata.get_platformscCst|d|_dS)Nr/)rr/r!rrr set_platformssz"DistributionMetadata.set_platformscCs |jpgSrm)r0rrrrrsz$DistributionMetadata.get_classifierscCst|d|_dS)Nr0)rr0r!rrrset_classifierssz$DistributionMetadata.set_classifierscCs |jpdSr)rrrrrget_download_urlsz%DistributionMetadata.get_download_urlcCs |jpgSrm)r3rrrrrsz!DistributionMetadata.get_requirescCs,ddl}|D]}|j|q t||_dSr)distutils.versionpredicateversionpredicateVersionPredicaterr3rbrrzrrrr set_requiressz!DistributionMetadata.set_requirescCs |jpgSrm)r2rrrrrsz!DistributionMetadata.get_providescCs6dd|D}|D]}ddl}|j|q||_dS)NcSsg|] }|qSrr)r6rrrrr8r9z5DistributionMetadata.set_provides..r)r&r'Zsplit_provisionr2)rbrrrzrrr set_providess z!DistributionMetadata.set_providescCs |jpgSrm)r4rrrrrsz"DistributionMetadata.get_obsoletescCs,ddl}|D]}|j|q t||_dSr)r&r'r(rr4r)rrr set_obsoletessz"DistributionMetadata.set_obsoletes)N)$rrrrDrlrr r rr rrrrrr rrrrZ get_licencerrrr"rr#rr$r%rr*rr+rr,rrrrrBsB 4"rBcCs$g}|D]}||ddq|S)Nr)r)r<Z new_optionsZ help_tuplerrrrsr)rZr}reZemailrrXrZdistutils.errorsZdistutils.fancy_getoptrrZdistutils.utilrrrrzr Zdistutils.debugr compilerrrrBrrrrrs2       Zc