3 (\$@sdZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZddlmZejeZGd d d ejZGd d d eZGd ddejZGdddeZddZdS)zBase option parser setup)absolute_importN) strtobool) string_types) UNKNOWN_ERROR) ConfigurationConfigurationError)get_terminal_sizec@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)roptparseIndentedHelpFormatter__init__)selfargskwargsrk/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/cli/parser.pyrszPrettyHelpFormatter.__init__cCs|j|ddS)Nz <%s>z, )_format_option_strings)roptionrrrformat_option_stringssz)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)NOptionsrz: r)rheadingrrrformat_heading7sz"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)hasattrparserlstriprstripr.r/r0)r descriptionlabelrrrformat_descriptionDs   z&PrettyHelpFormatter.format_descriptioncCs|r|SdSdS)Nrr)repilogrrr format_epilogVsz!PrettyHelpFormatter.format_epilogcs"fdd|jdD}dj|S)Ncsg|] }|qSrr).0line)indentrr ^sz4PrettyHelpFormatter.indent_lines..r7)splitr')rtextrC new_linesr)rCrr.]sz PrettyHelpFormatter.indent_linesN)rr) __name__ __module__ __qualname____doc__rrrr-r3r>r@r.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)r9_update_defaultsdefaultsrrexpand_default)rrrrrrOis z,UpdatingDefaultsHelpFormatter.expand_defaultN)rHrIrJrKrOrrrrrLbsrLc@s eZdZddZeddZdS)CustomOptionParsercOs(|j||}|jj|jj|||S)z*Insert an OptionGroup at a given position.)add_option_group option_groupspopr")ridxrrgrouprrrinsert_option_groupqs  z&CustomOptionParser.insert_option_groupcCs.|jdd}x|jD]}|j|jqW|S)zszGConfigOptionParser._get_ordered_configuration_items..z7Ignoring configuration key '%s' as it's value is empty..r )r^r`itemsloggerdebugrEr)rZoverride_order section_itemsZ section_keyrjsectionrirrr _get_ordered_configuration_itemss  z3ConfigOptionParser._get_ordered_configuration_itemsc sRtjj_t}xjD]\}jddkrBq jd kry t|}Wn,t k rt j|}j |YnXnjdkr|j }fdd|D}nhjd kr |j jj}j||}jpf}jpi}j||f||nj|}||j<q Wx|D]tj|<q.Wd_|S) zUpdates the given defaults with values from the config files and the environ. Does a little special handling for certain types of options (lists).z--N store_true store_falsecountrcsg|]}j|qSr)rl)rAv)rirrrrrDsz7ConfigOptionParser._update_defaults..callback)rvrwrx)rValuesrNvaluessetru get_optionactionr ValueErrorinvalid_config_error_messageerrorrEaddr%get_opt_string convert_value callback_argscallback_kwargsrzrlgetattr)rrN late_evalrjZ error_msgopt_strrrr)rirrrrMs:          z#ConfigOptionParser._update_defaultscCs|jstj|jSy|jjWn2tk rR}z|jtt |WYdd}~XnX|j |jj }x@|j D]4}|j |j}t|trn|j}|j||||j<qnWtj|S)zOverriding to make updating the defaults after instantiation of the option parser possible, _update_defaults() does the dirty work.N)process_default_valuesrr{rNr`loadrrhrstrrMcopy_get_all_optionsgetr% isinstancerrrd)rerrrNrdefaultrrrrget_default_valuess "  z%ConfigOptionParser.get_default_valuescCs |jtj|jtd|dS)Nz%s ) print_usagergstderrrhr)rr2rrrrs zConfigOptionParser.errorN) rHrIrJrKrrlrurMrrrrrrr]s 1r]cCs |dkrdj||Sdj||S)zQReturns a better error message when invalid configuration option is provided.rvrwzo{0} is not a valid value for {1} option, please specify a boolean value like yes/no, true/false or 1/0 instead.z[{0} is not a valid value for {1} option, please specify a numerical value like 1/0 instead.)rvrw)format)rrirjrrrrs r)rK __future__rloggingrrgr/distutils.utilrpip._vendor.sixrZpip._internal.cli.status_codesrZpip._internal.configurationrrZpip._internal.utils.compatr getLoggerrHrqrr rLrbrPr]rrrrrs       O w