U :e@sddlZddlZddlZddlmZz ddlZWnek rHdZYnXddlTddlm 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 nZd?d@ZdAdBZdcdCdDZdddEdFZdedHdIZejfdJdKZdLdMZdNdOZdPdQZ dRdSZ!dTdUZ"dVdWZ#dXdYZ$dZd[Z%d\d]Z&d^d_Z'd S)f 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 szDistribution.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}|dk r8|d=|D]4\}}| |}|D]\} } d| f|| <qqd|kr~|d|d<|d=d } t!dk rnt!"| nt#j$%| d |D]\} } t&|jd | rt|jd | | nNt&|j| rt|j| | n0t&|| rt|| | nd t'| } t!"| qd |_(|j dk rP|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_filesZpassword command_objhave_rungetitemsget_option_dictwarningswarnsysstderrwritehasattrrepr want_user_cfg startswithfinalize_options)selfZattrsattrbasenameZ method_namer;commandZ cmd_optionsopt_dictoptvalrkeyargrrr__init__s~                   zDistribution.__init__cCs&|j|}|dkr"i}|j|<|SN)rIrS)r`rcdictrrrrU&s zDistribution.get_option_dictr:c Csddlm}|dkr"t|j}|dk r@||||d}|sV||ddS|D]h}|j|}|dkr||d|qZ||d|||}|dD]}||d|qqZdS)Nr)pformatz zno commands known yetzno option dict for '%s' commandzoption dict for '%s' command:r<)ZpprintrlsortedrIkeysannouncerSsplit) r`headercommandsindentrlZcmd_namerdoutlinerrrdump_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, )rospathdirnamerXmodules__file__joinisfileappendr#r] expanduserr ro)r`filesZsys_dirZsys_fileZ user_filenameZ user_fileZ local_filerrrfind_config_filesMs&       zDistribution.find_config_filesc Csddlm}tjtjkr8ddddddd d d d d ddg }ng}t|}|dkrT|}trb|d|}|D]}tr|d|| || D]V}| |}| |}|D]8} | dkr| |kr| || } | dd} || f|| <qq|qld|jkr|jdD]\} \} } |j | } zF| rDt|| t|  n(| dkr`t|| t| n t|| | Wn,tk r} z t| W5d} ~ XYnXqdS)Nr) ConfigParserz install-basezinstall-platbasez install-libzinstall-platlibzinstall-purelibzinstall-headerszinstall-scriptsz install-dataprefixz exec-prefixhomeuserrootz"Distribution.parse_config_files():z reading %srr=_global)rr>) configparserrrXr base_prefix frozensetrr roreadZsectionsr;rUrSreplacerirIrT negative_optr@r ValueErrorDistutilsOptionError)r` filenamesrZignore_optionsparserfilenamesectionr;rdrerfsrcaliasrrrrparse_config_files}s^             zDistribution.parse_config_filescCs|}g|_t||j}||j|ddi|j|j|d}| }t |j | |rhdS|r|||}|dkrhdSqh|jr|j|t|jdk|jddS|jstddS)Nr-r,)argsobjectrdisplay_optionsrrzno commands suppliedT)_get_toplevel_optionsrrrrset_negative_aliasesrZ set_aliasesgetoptrHZget_option_orderr Z set_verbosityrhandle_display_options_parse_command_optsr! _show_helplenDistutilsArgError)r`Ztoplevel_optionsrr option_orderrrrparse_command_lines.      zDistribution.parse_command_linecCs |jdgS)N)zcommand-packages=Nz0list of packages that provide distutils commands)global_optionsr`rrrrsz"Distribution._get_toplevel_optionsc Csddlm}|d}t|s*td||j|z||}Wn*tk rn}z t |W5d}~XYnXt ||st d|t |drt |jtsd}t |||j}t |dr|}||jt |drt |jtrt|j}ng}||j|j|||||d d\}} t | d rV| jrV|j|d|gd dSt |drt |jtrd} |jD]F\} } } }t | || rzd } t|r|nt d || fqz| 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 SystemExitrrrget_command_classDistutilsModuleErrorr issubclassZDistutilsClassErrorr[r rrrcopyupdaterfix_help_optionsset_option_tablerrrr!rZ get_attr_namecallablerUvarsrT)r`rrrrcZ cmd_classrrrZoptsZhelp_option_foundZ help_optionZshortZdescfuncrdr#rrrrrsr                  z Distribution._parse_command_optscCsPdD]F}t|j|}|dkrqt|trdd|dD}t|j||qdS)Nr1r/cSsg|] }|qSrstrip)r6Zelmrrrr8jsz1Distribution.finalize_options..,)rDrBr rrpr@)r`rarrrrr_`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_usageprintrrrr rrrr[rrrrrrG) r`rrrrrrrr;rcklassrrrrms:           zDistribution._show_helpc Csddlm}|jr4|tdt||jdSd}i}|jD]}d||d<qB|D]l\}}|rX||rXt|}t |j d|}|dkrtd |n |dkrtd |nt|d}qX|S) Nrrr:rr9rr)r0r2r3r4r<) rrZ help_commandsprint_commandsrrGrrSrrDrBr) r`rrZany_display_optionsZis_display_optionoptionrerfrrrrrs*   z#Distribution.handle_display_optionsc Csjt|d|D]T}|j|}|s.||}z |j}Wntk rPd}YnXtd|||fqdS)N:(no description available)z %-*s %s)rrErSrr.AttributeError)r`rrrq 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.commandrc__all__rErnrSrrrr)r`rw std_commandsis_stdrextra_commandsrrrrrs.      zDistribution.print_commandsc Csddl}|jj}i}|D] }d||<qg}|jD]}||s4||q4g}||D]P}|j|}|sx||}z |j}Wnt k rd}YnX|||fqZ|S)Nrrr) rrcrrErnrSrrr.r) r`rwrrrrrvrr.rrrget_command_lists(         zDistribution.get_command_listcCsN|j}t|tsJ|dkrd}dd|dD}d|krD|dd||_|S)Nr:cSsg|]}|dkr|qS)r:r)r6Zpkgrrrr8!sz5Distribution.get_command_packages..rzdistutils.commandr)rFr rrpinsert)r`Zpkgsrrrget_command_packagess  z!Distribution.get_command_packagesc Cs|j|}|r|S|D]}d||f}|}zt|tj|}Wntk r^YqYnXzt||}Wn&tk rt d|||fYnX||j|<|St d|dS)Nz%s.%sz3invalid command '%s' (no class '%s' in module '%s')zinvalid command '%s') rErSr __import__rXr} ImportErrorrDrr)r`rcrZpkgname 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_namerUr rorTZboolean_optionsrrr rr@rr[rr) r`rQZ 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_optionsrRrZget_sub_commandsreinitialize_command)r`rcZreinit_subcommandsrrsubrrrrs      z!Distribution.reinitialize_commandcCst||dSrjr )r`rlevelrrrroszDistribution.announcecCs|jD]}||qdSrj)rr run_command)r`rrrr run_commandss zDistribution.run_commandscCsD|j|rdStd|||}||d|j|<dS)Nz running %sr)rRrSr inforZensure_finalizedrun)r`rcrrrrrs   zDistribution.run_commandcCst|jp|jpgdkSNr)rrJrKrrrrhas_pure_modulesszDistribution.has_pure_modulescCs|jot|jdkSr)rNrrrrrhas_ext_modulesszDistribution.has_ext_modulescCs|jot|jdkSr)rLrrrrrhas_c_librariesszDistribution.has_c_librariescCs|p|Srj)rrrrrr has_modulesszDistribution.has_modulescCs|jot|jdkSr)rMrrrrr has_headersszDistribution.has_headerscCs|jot|jdkSr)rOrrrrr has_scriptsszDistribution.has_scriptscCs|jot|jdkSr)rPrrrrrhas_data_filesszDistribution.has_data_filescCs|o| o| Srj)rrrrrrris_pures zDistribution.is_pure)N)NNr:)N)r)N)r)(r __module__ __qualname__rrrr?rrirUrvrrrrrr_rrrrrrrrrrr INFOrorrrrrrrrrrrrrrr,s  ,  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)BrA)r#r$r' author_emailr)maintainer_emailr+r,r.long_descriptionr1r/r&r*Z contact_emailr0 download_urlr2r3r4NcCs|dk r|t|nfd|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_dSrj) read_pkg_fileopenr#r$r'rr)rr+r,r.rr1r/r0rr2r3r4)r`r{rrrri s&zDistributionMetadata.__init__cst|fdd}fdd}d}|d|_|d|_|d|_|d |_d|_|d |_d|_|d |_|d |_ d kr|d |_ nd|_ |d|_ |d|_dkr|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|Srj)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,rrrpr1r/r0r3r2r4)r`filerrZmetadata_versionrrrr$s:                 z"DistributionMetadata.read_pkg_filec Cs2ttj|dddd}||W5QRXdS)NzPKG-INFOwzUTF-8)encoding)rrzr{rwrite_pkg_file)r`base_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)r2r3r4r0rrZget_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)r`rr$Z long_descr1rrrr_s6 z#DistributionMetadata.write_pkg_filecCs |D]}|d||fqdS)Nz%s: %s )rZ)r`rr#rrrrrrsz DistributionMetadata._write_listcCs |jpdSr)r#rrrrr szDistributionMetadata.get_namecCs |jpdS)Nz0.0.0)r$rrrrr sz DistributionMetadata.get_versioncCsd||fS)Nz%s-%s)r r rrrr 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+rrrrr szDistributionMetadata.get_urlcCs |jpdSr)r,rrrrrsz DistributionMetadata.get_licensecCs |jpdSr)r.rrrrr sz$DistributionMetadata.get_descriptioncCs |jpdSr)rrrrrrsz)DistributionMetadata.get_long_descriptioncCs |jpgSrj)r1rrrrrsz!DistributionMetadata.get_keywordscCst|d|_dS)Nr1)rr1r`rrrr set_keywordssz!DistributionMetadata.set_keywordscCs |jp dgSr)r/rrrrrsz"DistributionMetadata.get_platformscCst|d|_dS)Nr/)rr/rrrr set_platformssz"DistributionMetadata.set_platformscCs |jpgSrj)r0rrrrrsz$DistributionMetadata.get_classifierscCst|d|_dS)Nr0)rr0rrrrset_classifierssz$DistributionMetadata.set_classifierscCs |jpdSr)rrrrrget_download_urlsz%DistributionMetadata.get_download_urlcCs |jpgSrj)r3rrrrrsz!DistributionMetadata.get_requirescCs,ddl}|D]}|j|q t||_dSr)distutils.versionpredicateversionpredicateVersionPredicaterr3r`rrwrrrr set_requiressz!DistributionMetadata.set_requirescCs |jpgSrj)r2rrrrrsz!DistributionMetadata.get_providescCs6dd|D}|D]}ddl}|j|q||_dS)NcSsg|] }|qSrr)r6rrrrr8sz5DistributionMetadata.set_provides..r)r#r$Zsplit_provisionr2)r`rrrwrrr set_providess z!DistributionMetadata.set_providescCs |jpgSrj)r4rrrrrsz"DistributionMetadata.get_obsoletescCs,ddl}|D]}|j|q t||_dSr)r#r$r%rr4r&rrr set_obsoletessz"DistributionMetadata.set_obsoletes)N)$rrrrCrirr rrr r rrrrrrrr rZ get_licencer rrrrr rr!r"rr'rr(rr)rrrrrAsB 4"rAcCs$g}|D]}||ddq|S)Nr)r)r;Z new_optionsZ help_tuplerrrrsr)rXrzreZemailrrVrZdistutils.errorsZdistutils.fancy_getoptrrZdistutils.utilrrrrwr Zdistutils.debugr compilerrrrArrrrrs2      Zc