U e5d@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_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_namer9commandZ cmd_optionsopt_dictoptvalrkeyargrrr__init__s~                   zDistribution.__init__cCs&|j|}|dkr"i}|j|<|SN)rGrQ)r^rbdictrrrrS&s zDistribution.get_option_dictr8c 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:)ZpprintrksortedrGkeysannouncerQsplit) r^headercommandsindentrkZcmd_namercoutlinerrrdump_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, )rospathdirnamerVmodules__file__joinisfileappendr!r[ expanduserr rn)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<)Z configparserrrVr base_prefix frozensetrr rnreadZsectionsr9rSrQreplacerhrGrR negative_optr>r ValueErrorDistutilsOptionError)r^ filenamesrZignore_optionsparserfilenameZsectionr9rcrdresrcaliasrrrrparse_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_optionsrqzno commands suppliedT)_get_toplevel_optionsrqrrset_negative_aliasesrZ set_aliasesgetoptrFZget_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_optionsrrrzYinvalid help function %r for help option '%s': must be a callable object (function, etc.)z command line) distutils.cmdr command_rematch SystemExitrqrget_command_classDistutilsModuleErrorr issubclassZDistutilsClassErrorrYr rrrcopyupdaterfix_help_optionsset_option_tablerrrrrZ get_attr_namecallablerSvarsrR)r^rrrrbZ cmd_classrrrZoptsZhelp_option_foundZ help_optionZshortZdescfuncrcr!rrrrrsr                  z Distribution._parse_command_optscCsPdD]F}t|j|}|dkrqt|trdd|dD}t|j||qdS)Nr/r-cSsg|] }|qSrstrip)r4Zelmrrrr6jsz1Distribution.finalize_options..,)rBr@r rror>)r^r`rrrrr]`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:r8zKInformation display options (just display information, ignore any commands)rzOptions for '%s' command:)distutils.corerrrrrrZ print_help common_usageprintrrqr rrrrYrrrrrrE) r^rrrrqrrr9rbklassrrrrms:           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) Nrrr8rr7rr)r.r0r1r2r:) rrZ help_commandsprint_commandsrrErrQrrBr@r~) r^rrZany_display_optionsZis_display_optionoptionrdrerrrrrs*   z#Distribution.handle_display_optionsc Csjt|d|D]T}|j|}|s.||}z |j}Wntk rPd}YnXtd|||fqdS)N:(no description available)z %-*s %s)rrCrQrr,AttributeError)r^rqrp 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.commandrb__all__rCrmrQrrrr)r^rv 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) rrbrrCrmrQrrr,r) r^rvrrrrrvrr,rrrget_command_lists(         zDistribution.get_command_listcCsN|j}t|tsJ|dkrd}dd|dD}d|krD|dd||_|S)Nr8cSsg|]}|dkr|qS)r8r)r4Zpkgrrrr6!sz5Distribution.get_command_packages..rzdistutils.commandr)rDr rroinsert)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') rCrQr __import__rVr| ImportErrorrBrr)r^rbrZpkgnameZ 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_namerSr rnrRZboolean_optionsrrr rr>rrYrr) r^rOZ 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_optionsrPrZget_sub_commandsreinitialize_command)r^rbZreinit_subcommandsrrsubrrrrs      z!Distribution.reinitialize_commandcCst||dSrir )r^rlevelrrrrnszDistribution.announcecCs|jD]}||qdSri)rq run_command)r^rrrr run_commandss zDistribution.run_commandscCsD|j|rdStd|||}||d|j|<dS)Nz running %sr)rPrQr inforZensure_finalizedrun)r^rbrrrrrs   zDistribution.run_commandcCst|jp|jpgdkSNr)rrHrIrrrrhas_pure_modulesszDistribution.has_pure_modulescCs|jot|jdkSr)rLrrrrrhas_ext_modulesszDistribution.has_ext_modulescCs|jot|jdkSr)rJrrrrrhas_c_librariesszDistribution.has_c_librariescCs|p|Sri)rrrrrr has_modulesszDistribution.has_modulescCs|jot|jdkSr)rKrrrrr has_headersszDistribution.has_headerscCs|jot|jdkSr)rMrrrrr has_scriptsszDistribution.has_scriptscCs|jot|jdkSr)rNrrrrrhas_data_filesszDistribution.has_data_filescCs|o| o| Sri)rrrrrrris_pures zDistribution.is_pure)N)NNr8)N)r)N)r)(r __module__ __qualname__rrrr=rrhrSrurrrrrr]rrrrrrrrrrr INFOrnrrrrrrrrrrrrrrr,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)Br?)r!r"r% author_emailr'maintainer_emailr)r*r,long_descriptionr/r-r$r(Z contact_emailr. download_urlr0r1r2NcCs|dk r|t|nfd|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_dSri) read_pkg_fileopenr!r"r%rr'rr)r*r,rr/r-r.rr0r1r2)r^rzrrrrh 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|Sri)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*rrror/r-r.r1r0r2)r^filerrZmetadata_versionrrrr$s:                 z"DistributionMetadata.read_pkg_filec Cs2ttj|dddd}||W5QRXdS)NzPKG-INFOwzUTF-8)encoding)rryrzr~write_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.rrXget_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 )rX)r^rr!rrrrrr sz 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%rrrrrsz 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 |jpgSri)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 |jpgSri)r.rrrrrsz$DistributionMetadata.get_classifierscCst|d|_dS)Nr.)rr.rrrrset_classifierssz$DistributionMetadata.set_classifierscCs |jpdSr)rrrrrget_download_urlsz%DistributionMetadata.get_download_urlcCs |jpgSri)r1rrrrrsz!DistributionMetadata.get_requirescCs,ddl}|D]}|j|q t||_dSr)distutils.versionpredicateversionpredicateVersionPredicaterr1r^rrvrrrr set_requiressz!DistributionMetadata.set_requirescCs |jpgSri)r0rrrrrsz!DistributionMetadata.get_providescCs6dd|D}|D]}ddl}|j|q||_dS)NcSsg|] }|qSrr)r4rrrrr6sz5DistributionMetadata.set_provides..r)rrZsplit_provisionr0)r^rrrvrrr set_providess z!DistributionMetadata.set_providescCs |jpgSri)r2rrrrrsz"DistributionMetadata.get_obsoletescCs,ddl}|D]}|j|q t||_dSr)rrrrr2r rrr set_obsoletessz"DistributionMetadata.set_obsoletes)N)$rrrrArhrrrr rrrrrrrrr rr Z get_licencerr r rrrrrrrr!rr"rr#rrrrr?sB 4"r?cCs$g}|D]}||ddq|S)Nr)r)r9Z new_optionsZ help_tuplerrrrsr)rVryreZemailrrTrZdistutils.errorsZdistutils.fancy_getoptrrZdistutils.utilrrrrvr Zdistutils.debugr compilerrrr?rrrrrs2      Zc