3 Pf(@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)NZmax_help_positionZindent_incrementrwidth)r optparseIndentedHelpFormatter__init__)selfargskwargsr /usr/lib/python3.6/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) Z _short_optsappendZ _long_optsleninsertZ takes_valuemetavardestlowerjoin)rrZmvarfmtZoptsepZoptsr"rrrr$s  z*PrettyHelpFormatter._format_option_stringscCs|dkr dS|dS)NZOptionsrz: r)rZheadingrrrformat_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)rZusagemsgrrr format_usage@sz PrettyHelpFormatter.format_usagecCsV|rNt|jdrd}nd}|jd}|j}|jtj|d}d||f}|SdSdS)NmainZCommandsZ Description z z%s: %s r)hasattrparserlstriprstripr'r(r))r descriptionZlabelrrrformat_descriptionHs   z&PrettyHelpFormatter.format_descriptioncCs|r|SdSdS)Nrr)rZepilogrrr format_epilogZsz!PrettyHelpFormatter.format_epilogcs"fdd|jdD}dj|S)Ncsg|] }|qSrr).0line)indentrr bsz4PrettyHelpFormatter.indent_lines..r-)splitr%)rtextr7Z new_linesr)r7rr'asz PrettyHelpFormatter.indent_linesN)rr) __name__ __module__ __qualname____doc__rrrr&r+r3r4r'rrrrr 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)rrrrrrBms z,UpdatingDefaultsHelpFormatter.expand_defaultN)r;r<r=r>rBrrrrr?fsr?c@s eZdZddZeddZdS)CustomOptionParsercOs(|j||}|jj|jj|||S)z*Insert an OptionGroup at a given position.)Zadd_option_group option_groupspopr!)ridxrrgrouprrrinsert_option_groupus  z&CustomOptionParser.insert_option_groupcCs.|jdd}x|jD]}|j|jqW|S)z.callback)rirjrk)rOupdatenormalize_keysget_config_sectionrPget_environ_varsrValuesrAvaluessetitemsZ get_optionactionrr9addr#get_opt_stringZ convert_valueZ callback_argsZcallback_kwargsrmrggetattr) rrArQZsectionZ late_evalreopt_strrrr)rdrrrr@s@          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)rruZ normalizedrdrerrrros   z!ConfigOptionParser.normalize_keyscCs|jj|r|jj|SgS)z Get a section of a configuration)rQZ has_sectionru)rrOrrrrps  z%ConfigOptionParser.get_config_sectionccs<x6tjjD](\}}tj|r tjd|j|fVq WdS)z@Returns a generator with all environmental vars with prefix PIP_rN)rWrXru_environ_prefix_researchsubr$)rrdrerrrrqs 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.) Zprocess_default_valuesrrrrAr@copyZ_get_all_optionsrYr# isinstancerrxra)rrArdefaultrzrrrget_default_valuess   z%ConfigOptionParser.get_default_valuescCs |jtj|jdd|dS)Nrz%s )Z print_usager^stderrrc)rr*rrrerror#s zConfigOptionParser.errorN)r;r<r=r>rPrrRrgr@rorprqrrrrrrrNs (5 rN)r>Z __future__rr^rrWrer(Zdistutils.utilrZpip._vendor.sixrZpip._vendor.six.movesrZ pip.locationsrrrr Z pip.utilsr r compileIrrr r?rVrCrNrrrrs     O