3 ](@sdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZmZddlmZmZejd ejZGd d d ejZGd d d eZGdddejZGdddeZdS)zBase option parser setup)absolute_importN) strtobool) string_types) configparser)legacy_config_fileconfig_basenamerunning_under_virtualenvsite_config_files)appdirsget_terminal_sizez^PIP_c@sReZdZdZddZddZddd Zd d Zd d ZddZ ddZ ddZ dS)PrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.cOs:d|d<d|d<tdd|d<tjj|f||dS)Nmax_help_positionindent_incrementrwidth)r optparseIndentedHelpFormatter__init__)selfargskwargsr-/tmp/pip-build-8jg9gmni/pip/pip/baseparser.pyrszPrettyHelpFormatter.__init__cCs|j|ddS)Nz <%s>z, )_format_option_strings)roptionrrrformat_option_strings!sz)PrettyHelpFormatter.format_option_strings <%s>, cCs|g}|jr|j|jd|jr0|j|jdt|dkrH|jd||jrr|jp^|jj}|j||jdj |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_optsappend _long_optsleninsert takes_valuemetavardestlowerjoin)rrmvarfmtoptsepoptsr'rrrr$s  z*PrettyHelpFormatter._format_option_stringscCs|dkr dS|dS)NOptionsr z: r)rheadingrrrformat_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_linestextwrapdedent)rusagemsgrrr format_usage@sz PrettyHelpFormatter.format_usagecCsV|rNt|jdrd}nd}|jd}|j}|jtj|d}d||f}|SdSdS)NmainCommands Description z z%s: %s r )hasattrparserlstriprstripr1r2r3)r descriptionlabelrrrformat_descriptionHs   z&PrettyHelpFormatter.format_descriptioncCs|r|SdSdS)Nr r)repilogrrr format_epilogZsz!PrettyHelpFormatter.format_epilogcs"fdd|jdD}dj|S)Ncsg|] }|qSrr).0line)indentrr bsz4PrettyHelpFormatter.indent_lines..r:)splitr*)rtextrF new_linesr)rFrr1asz PrettyHelpFormatter.indent_linesN)rr) __name__ __module__ __qualname____doc__rrrr0r6rArCr1rrrrr s r c@seZdZdZddZdS)UpdatingDefaultsHelpFormatterzCustom 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|jjtjj||S)N)r<_update_defaultsdefaultsrrexpand_default)rrrrrrRms z,UpdatingDefaultsHelpFormatter.expand_defaultN)rKrLrMrNrRrrrrrOfsrOc@s eZdZddZeddZdS)CustomOptionParsercOs(|j||}|jj|jj|||S)z*Insert an OptionGroup at a given position.)add_option_group option_groupspopr%)ridxrrgrouprrrinsert_option_groupus  z&CustomOptionParser.insert_option_groupcCs.|jdd}x|jD]}|j|jqW|S)z.callback)rrr)raupdatenormalize_keysget_config_sectionrbget_environ_varsrValuesrQvaluessetitems get_optionactionrrHaddr(get_opt_string convert_value callback_argscallback_kwargsrrgetattr) rrQrdsection late_evalr~opt_strrrr)r}rrrrPs@          z#ConfigOptionParser._update_defaultscCs@i}x6|D].\}}|jdd}|jds0d|}|||<q W|S)zReturn 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~rrrrs   z!ConfigOptionParser.normalize_keyscCs|jj|r|jj|SgS)z Get a section of a configuration)rd has_sectionr)rrarrrrs  z%ConfigOptionParser.get_config_sectionccs<x6tjjD](\}}tj|r tjd|j|fVq WdS)z@Returns a generator with all environmental vars with prefix PIP_r N)rlrmr_environ_prefix_researchsubr))rr}r~rrrrs z#ConfigOptionParser.get_environ_varscCsn|jstj|jS|j|jj}x@|jD]4}|j|j}t |t r,|j }|j ||||j<q,Wtj|S)zOverriding to make updating the defaults after instantiation of the option parser possible, _update_defaults() does the dirty work.) process_default_valuesrrrQrPcopy_get_all_optionsrnr( isinstancerrry)rrQrdefaultrrrrget_default_valuess   z%ConfigOptionParser.get_default_valuescCs |jtj|jdd|dS)Nrz%s ) print_usagertstderrr|)rr5rrrerror#s zConfigOptionParser.errorN)rKrLrMrNrbrrerrPrrrrrrrrrr`s (5 r`)rN __future__rrtrrlrer2distutils.utilrZpip._vendor.sixrZpip._vendor.six.movesr pip.locationsrrrr pip.utilsr r compileIrrr rOrirSr`rrrrs     O