a DOg@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_runrdisplay_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)selfattrsattrbasenameZ method_namer:commandZ cmd_optionsopt_dictoptvalrkeyargrrr__init__s~                   zDistribution.__init__cCs&|j|}|dur"i}|j|<|SN)rHrR)r_rcdictrrrrT&s zDistribution.get_option_dictr9c 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;)ZpprintrlsortedrHkeysannouncerRsplit) 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, )rospathdirnamerWmodules__file__joinisfileappendr!r\ expanduserr ro)r_filesZsys_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=)Z configparserrrWr base_prefix frozensetrr roreadZsectionsr:rTrRreplacerirHrS negative_optr?r ValueErrorDistutilsOptionError)r_ filenamesrZignore_optionsparserfilenameZsectionr:rdrerfsrcaliasrrrrparse_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_optionsrrzno commands suppliedT)_get_toplevel_optionsrrrrset_negative_aliasesrZ set_aliasesgetoptrGZget_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,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_optionsrrrzYinvalid help function %r for help option '%s': must be a callable object (function, etc.)z command line) distutils.cmdr command_rematch SystemExitrrrget_command_classDistutilsModuleErrorr issubclassZDistutilsClassErrorrZr rrrcopyupdaterfix_help_optionsset_option_tablerrrrrZ get_attr_namecallablerTvarsrS)r_rrrrcZ cmd_classrrrZoptsZhelp_option_foundZ help_optionZshortZdescfuncrdr!rrrrrsr                  z Distribution._parse_command_optscCsPdD]F}t|j|}|durqt|trdd|dD}t|j||qdS)Nr/r-cSsg|] }|qSrstrip)r4Zelmrrrr6jr7z1Distribution.finalize_options..,)rCrAr 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:r9zKInformation display options (just display information, ignore any commands)rzOptions for '%s' command:)distutils.corerrrrrrZ print_help common_usageprintrrrr rrrrZrrrrrrF) r_rrrrrrrr:rcklassrrrrms:           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) Nrrr9rr8rr)r.r0r1r2r;) rrZ help_commandsprint_commandsrrFrrRrrCrAr) r_rrZany_display_optionsZis_display_optionoptionrerfrrrrrs*   z#Distribution.handle_display_optionsc Csht|d|D]R}|j|}|s.||}z |j}WntyNd}Yn0td|||fqdS)N:(no description available)z %-*s %s)rrDrRrr,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__rDrnrRrrrr)r_rw 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) rrcrrDrnrRrrr,r) r_rwrrrrrvrr,rrrget_command_lists(          zDistribution.get_command_listcCsN|j}t|tsJ|durd}dd|dD}d|vrD|dd||_|S)Nr9cSsg|]}|dkr|qS)r9r)r4Zpkgrrrr6!r7z5Distribution.get_command_packages..rzdistutils.commandr)rEr rrpinsert)r_Zpkgsrrrget_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') rDrRr __import__rWr} ImportErrorrCrr)r_rcrZpkgnameZ 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_namerTr rorSZboolean_optionsrrr rr?rrZrr) r_rPZ 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_optionsrQrZget_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)rQrRr inforZensure_finalizedrun)r_rcrrrrrs   zDistribution.run_commandcCst|jp|jpgdkSNr)rrIrJrrrrhas_pure_modulesszDistribution.has_pure_modulescCs|jot|jdkSr)rMrrrrrhas_ext_modulesszDistribution.has_ext_modulescCs|jot|jdkSr)rKrrrrrhas_c_librariesszDistribution.has_c_librariescCs|p|Srj)rrrrrr has_modulesszDistribution.has_modulescCs|jot|jdkSr)rLrrrrr has_headersszDistribution.has_headerscCs|jot|jdkSr)rNrrrrr has_scriptsszDistribution.has_scriptscCs|jot|jdkSr)rOrrrrrhas_data_filesszDistribution.has_data_filescCs|o| o| Srj)rrrrrrris_pures zDistribution.is_pure)N)NNr9)N)r)N)r)(r __module__ __qualname__rrrr>rrirTrvrrrrrr^rrrrrrrrrrr INFOrorrrrrrrrrrrrrrr,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)Br@)r!r"r% author_emailr'maintainer_emailr)r*r,long_descriptionr/r-r$r(Z contact_emailr. download_urlr0r1r2NcCs|dur|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,rr/r-r.rr0r1r2)r_r{rrrri 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|Srj)Zget_all)r!valuesrrr _read_list.s z6DistributionMetadata.read_pkg_file.._read_listzmetadata-versionr!r"Zsummaryr%r&z home-pager*z download-urlr,r/rplatformZ classifier1.1r1r0r2)rr!r"r,r%r'rrr)r*rrrpr/r-r.r1r0r2)r_filerrZmetadata_versionrrrr$s:                 z"DistributionMetadata.read_pkg_filecCsFttj|dddd}||Wdn1s80YdS)NzPKG-INFOwzUTF-8)encoding)rrzr{rwrite_pkg_file)r_Zbase_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)r0r1r2r.rrYget_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_descr/rrrr_s6 z#DistributionMetadata.write_pkg_filecCs |D]}|d||fqdS)Nz%s: %s )rY)r_rr!rrrrrrsz DistributionMetadata._write_listcCs |jpdSr)r!rrrrrszDistributionMetadata.get_namecCs |jpdS)Nz0.0.0)r"rrrrrsz DistributionMetadata.get_versioncCsd||fS)Nz%s-%s)rrrrrr 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%rrrrr sz DistributionMetadata.get_contactcCs|jp|jpdSr)rrrrrrr sz&DistributionMetadata.get_contact_emailcCs |jpdSr)r)rrrrrszDistributionMetadata.get_urlcCs |jpdSr)r*rrrrr sz DistributionMetadata.get_licensecCs |jpdSr)r,rrrrrsz$DistributionMetadata.get_descriptioncCs |jpdSr)rrrrrr sz)DistributionMetadata.get_long_descriptioncCs |jpgSrj)r/rrrrr sz!DistributionMetadata.get_keywordscCst|d|_dS)Nr/)rr/r_rrrr set_keywordssz!DistributionMetadata.set_keywordscCs |jp dgSr)r-rrrrrsz"DistributionMetadata.get_platformscCst|d|_dS)Nr-)rr-rrrr set_platformssz"DistributionMetadata.set_platformscCs |jpgSrj)r.rrrrrsz$DistributionMetadata.get_classifierscCst|d|_dS)Nr.)rr.rrrrset_classifierssz$DistributionMetadata.set_classifierscCs |jpdSr)rrrrrget_download_urlsz%DistributionMetadata.get_download_urlcCs |jpgSrj)r1rrrrrsz!DistributionMetadata.get_requirescCs,ddl}|D]}|j|q t||_dSr)distutils.versionpredicateversionpredicateVersionPredicaterr1r_rrwrrrr set_requiressz!DistributionMetadata.set_requirescCs |jpgSrj)r0rrrrrsz!DistributionMetadata.get_providescCs6dd|D}|D]}ddl}|j|q||_dS)NcSsg|] }|qSrr)r4rrrrr6r7z5DistributionMetadata.set_provides..r)rrZsplit_provisionr0)r_rrrwrrr set_providess z!DistributionMetadata.set_providescCs |jpgSrj)r2rrrrrsz"DistributionMetadata.get_obsoletescCs,ddl}|D]}|j|q t||_dSr)rrr rr2r!rrr set_obsoletessz"DistributionMetadata.set_obsoletes)N)$rrrrBrirrrrrrrrrrrr r rr Z get_licencerr r rrrrrrrr"rr#rr$rrrrr@sB 4"r@cCs$g}|D]}||ddq|S)Nr)r)r:Z new_optionsZ help_tuplerrrrsr)rWrzreZemailrrUrZdistutils.errorsZdistutils.fancy_getoptrrZdistutils.utilrrrrwr Zdistutils.debugr compilerrrr@rrrrrs2       Zc