3

Q'ícá(ã@sÚdZddlmZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZddlmZmZejd	ejƒZGd
d„dejƒZGdd
„d
eƒZGdd„dejƒZGdd„deƒZdS)zBase option parser setupé)Úabsolute_importN)Ú	strtobool)Ústring_types)Úconfigparser)Úlegacy_config_fileÚconfig_basenameÚrunning_under_virtualenvÚsite_config_files)ÚappdirsÚget_terminal_sizez^PIP_c@sReZdZdZdd„Zdd„Zddd	„Zd
d„Zdd
„Zdd„Z	dd„Z
dd„ZdS)ÚPrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.cOs:d|d<d|d<tƒdd|d<tjj|f|ž|ŽdS)NéÚmax_help_positionéÚindent_incrementréÚwidth)rÚoptparseÚIndentedHelpFormatterÚ__init__)ÚselfÚargsÚkwargs©rú-/tmp/pip-build-l_bcah40/pip/pip/baseparser.pyrszPrettyHelpFormatter.__init__cCs|j|ddƒS)Nz <%s>z, )Ú_format_option_strings)rÚoptionrrrÚformat_option_strings!sz)PrettyHelpFormatter.format_option_stringsú <%s>ú, cCs|g}|jr|j|jdƒ|jr0|j|jdƒt|ƒdkrH|jd|ƒ|jƒrr|jp^|jjƒ}|j||jƒƒdj	|ƒS)a
        Return a comma-separated list of option strings and metavars.

        :param option:  tuple of (short opt, long opt), e.g: ('-f', '--format')
        :param mvarfmt: metavar format string - evaluated as mvarfmt % metavar
        :param optsep:  separator
        rrÚ)
Ú_short_optsÚappendÚ
_long_optsÚlenÚinsertÚtakes_valueÚmetavarÚdestÚlowerÚjoin)rrÚmvarfmtÚoptsepÚoptsr'rrrr$sz*PrettyHelpFormatter._format_option_stringscCs|dkrdS|dS)NÚOptionsr z:
r)rÚheadingrrrÚformat_heading;sz"PrettyHelpFormatter.format_headingcCsd|jtj|ƒdƒ}|S)zz
        Ensure there is only one newline between usage and the first heading
        if there is no description.
        z
Usage: %s
z  )Úindent_linesÚtextwrapÚdedent)rÚusageÚmsgrrrÚformat_usage@sz PrettyHelpFormatter.format_usagecCsV|rNt|jdƒrd}nd}|jdƒ}|jƒ}|jtj|ƒdƒ}d||f}|SdSdS)NÚmainÚCommandsÚDescriptionÚ
z  z%s:
%s
r )ÚhasattrÚparserÚlstripÚrstripr1r2r3)rÚdescriptionÚlabelrrrÚformat_descriptionHs
z&PrettyHelpFormatter.format_descriptioncCs|r|SdSdS)Nr r)rÚepilogrrrÚ
format_epilogZsz!PrettyHelpFormatter.format_epilogcs"‡fdd„|jdƒDƒ}dj|ƒS)Ncsg|]}ˆ|‘qSrr)Ú.0Úline)Úindentrrú
<listcomp>bsz4PrettyHelpFormatter.indent_lines.<locals>.<listcomp>r:)Úsplitr*)rÚtextrFÚ	new_linesr)rFrr1asz PrettyHelpFormatter.indent_linesN)rr)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrrr0r6rArCr1rrrrrs
rc@seZdZdZdd„ZdS)ÚUpdatingDefaultsHelpFormatterz®Custom help formatter for use in ConfigOptionParser.

    This is updates the defaults before expanding them, allowing
    them to show up correctly in the help listing.
    cCs(|jdk	r|jj|jjƒtjj||ƒS)N)r<Ú_update_defaultsÚdefaultsrrÚexpand_default)rrrrrrRms
z,UpdatingDefaultsHelpFormatter.expand_defaultN)rKrLrMrNrRrrrrrOfsrOc@s eZdZdd„Zedd„ƒZdS)ÚCustomOptionParsercOs(|j||Ž}|jjƒ|jj||ƒ|S)z*Insert an OptionGroup at a given position.)Úadd_option_groupÚ
option_groupsÚpopr%)rÚidxrrÚgrouprrrÚinsert_option_groupus
z&CustomOptionParser.insert_option_groupcCs.|jdd…}x|jD]}|j|jƒqW|S)z<Get a list of all options, including those in option groups.N)Úoption_listrUÚextend)rÚresÚirrrÚoption_list_all~sz"CustomOptionParser.option_list_allN)rKrLrMrYÚpropertyr^rrrrrSss	rSc@s\eZdZdZdZdd„Zdd„Zdd„Zd	d
„Zdd„Z	d
d„Z
dd„Zdd„Zdd„Z
dS)ÚConfigOptionParserzsCustom option parser which updates its defaults by checking the
    configuration files and environmental variablesFcOsdtjƒ|_|jdƒ|_|jddƒ|_|jƒ|_|jrB|jj|jƒ|jsLt	‚t
jj|f|ž|ŽdS)NÚnameÚisolatedF)
rÚRawConfigParserÚconfigrVrarbÚget_config_filesÚfilesÚreadÚAssertionErrorrÚOptionParserr)rrrrrrrŽs


zConfigOptionParser.__init__cCsštjjddƒ}|tjkrgSttƒ}|jsj|rFtjj|ƒrF|j	|ƒn$|j	t
ƒ|j	tjjtj
dƒtƒƒtƒr–tjjtjtƒ}tjj|ƒr–|j	|ƒ|S)NÚPIP_CONFIG_FILEFÚpip)ÚosÚenvironÚgetÚdevnullÚlistr	rbÚpathÚexistsr"rr*r
Úuser_config_dirrrÚsysÚprefix)rÚconfig_filerfÚvenv_config_filerrrre˜s&


z#ConfigOptionParser.get_config_filescCsLy|j||ƒStjk
rF}ztd|ƒtjdƒWYdd}~XnXdS)Nz*An error occurred during configuration: %sé)Úcheck_valuerÚOptionValueErrorÚprintrtÚexit)rrÚkeyÚvalÚexcrrrÚ
check_defaultÀs
z ConfigOptionParser.check_defaultc	sji}x(dˆjfD]}|jˆjˆj|ƒƒƒqWˆjsH|jˆjˆjƒƒƒtjˆjƒˆ_	t
ƒ}xâ|jƒD]Ö\‰}|stqfˆjˆƒ‰ˆdkrˆqfˆj
d
krœt|ƒ}n–ˆj
dkrÆ|jƒ}‡‡‡fdd„|Dƒ}nlˆj
d	kr$|jˆjƒˆjƒ}ˆj||ƒ}ˆjpüf}ˆjpi}ˆjˆ||ˆf|ž|Žnˆjˆˆ|ƒ}||ˆj<qfWx|D]‰tˆj	ˆƒ|ˆ<qFWdˆ_	|S)z¢Updates the given defaults with values from the config files and
        the environ. Does a little special handling for certain types of
        options (lists).ÚglobalNÚ
store_trueÚstore_falseÚcountr"csg|]}ˆjˆˆ|ƒ‘qSr)r€)rDÚv)r}rrrrrGész7ConfigOptionParser._update_defaults.<locals>.<listcomp>Úcallback)r‚rƒr„)raÚupdateÚnormalize_keysÚget_config_sectionrbÚget_environ_varsrÚValuesrQÚvaluesÚsetÚitemsÚ
get_optionÚactionrrHÚaddr(Úget_opt_stringÚ
convert_valueÚ
callback_argsÚcallback_kwargsr†r€Úgetattr)	rrQrdÚsectionÚ	late_evalr~Úopt_strrrr)r}rrrrPÇs@




z#ConfigOptionParser._update_defaultscCs@i}x6|D].\}}|jddƒ}|jdƒs0d|}|||<q
W|S)z™Return a config dictionary with normalized keys regardless of
        whether the keys were specified in environment variables or in config
        filesÚ_ú-z--z--%s)ÚreplaceÚ
startswith)rrŽÚ
normalizedr}r~rrrrˆüs
z!ConfigOptionParser.normalize_keyscCs|jj|ƒr|jj|ƒSgS)z Get a section of a configuration)rdÚhas_sectionrŽ)rrarrrr‰sz%ConfigOptionParser.get_config_sectionccs<x6tjjƒD](\}}tj|ƒrtjd|ƒjƒ|fVqWdS)z@Returns a generator with all environmental vars with prefix PIP_r N)rlrmrŽÚ_environ_prefix_reÚsearchÚsubr))rr}r~rrrrŠs
z#ConfigOptionParser.get_environ_varscCsn|jstj|jƒS|j|jjƒƒ}x@|jƒD]4}|j|jƒ}t	|t
ƒr,|jƒ}|j||ƒ||j<q,Wtj|ƒS)z‹Overriding to make updating the defaults after instantiation of
        the option parser possible, _update_defaults() does the dirty work.)
Úprocess_default_valuesrr‹rQrPÚcopyÚ_get_all_optionsrnr(Ú
isinstancerr’ry)rrQrÚdefaultr™rrrÚget_default_valuess
z%ConfigOptionParser.get_default_valuescCs |jtjƒ|jdd|ƒdS)Nrz%s
)Úprint_usagertÚstderrr|)rr5rrrÚerror#szConfigOptionParser.errorN)rKrLrMrNrbrrer€rPrˆr‰rŠr¨r«rrrrr`ˆs
(5r`)rNÚ
__future__rrtrrlÚrer2Údistutils.utilrZpip._vendor.sixrZpip._vendor.six.movesrÚ
pip.locationsrrrr	Ú	pip.utilsr
rÚcompileÚIr rrrOrirSr`rrrrÚ<module>s O