U n a%@sdZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZddlmZeeZGd 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__)selfargskwargsrYC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_internal\cli\parser.pyrszPrettyHelpFormatter.__init__cCs ||SN)_format_option_stringsroptionrrrformat_option_strings!sz)PrettyHelpFormatter.format_option_strings <{}>, cCs~g}|jr||jd|jr0||jdt|dkrH|d||rt|jp^|j}|| |d |S)z 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 :param optsep: separator rr ) _short_optsappend _long_optsleninsert takes_valuemetavardestlowerformatjoin)rrmvarfmtoptsepoptsr&rrrr$s  z*PrettyHelpFormatter._format_option_stringscCs|dkr dS|dS)NOptionsrz: r)rheadingrrrformat_heading;sz"PrettyHelpFormatter.format_headingcCsd|t|d}|S)zz Ensure there is only one newline between usage and the first heading if there is no description. z Usage: {}  )r) indent_linestextwrapdedent)rusagemsgrrr format_usage@sz PrettyHelpFormatter.format_usagecCsV|rNt|jdrd}nd}|d}|}|t|d}d||}|SdSdS)NmainCommands Description r1z{}: {} r)hasattrparserlstriprstripr2r3r4r))r descriptionlabelrrrformat_descriptionIs   z&PrettyHelpFormatter.format_descriptioncCs|r|SdSdS)Nrr)repilogrrr format_epilog[sz!PrettyHelpFormatter.format_epilogcs"fdd|dD}d|S)Ncsg|] }|qSrr).0lineindentrr csz4PrettyHelpFormatter.indent_lines..r;)splitr*)rtextrH new_linesrrGrr2bsz PrettyHelpFormatter.indent_linesN)rr) __name__ __module__ __qualname____doc__rrrr0r7rBrDr2rrrrr 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|j|jjtj||Sr)r=_update_defaultsdefaultsrrexpand_defaultrrrrrTns z,UpdatingDefaultsHelpFormatter.expand_defaultN)rMrNrOrPrTrrrrrQgsrQc@s eZdZddZeddZdS)CustomOptionParsercOs(|j||}|j|j|||S)z*Insert an OptionGroup at a given position.)add_option_group option_groupspopr$)ridxrrgrouprrrinsert_option_groupvs  z&CustomOptionParser.insert_option_groupcCs*|jdd}|jD]}||jq|S)ztd|q$|dd\}}||kr$||||fq$|D] }||D]\}}||fVqzqndS)Nglobalz:env:cSsi|] }|gqSrr)rErcrrr szGConfigOptionParser._get_ordered_configuration_items..z7Ignoring configuration key '%s' as it's value is empty..r )rcreitemsloggerdebugrJr!)roverride_order section_items section_keyrosectionrnrrr _get_ordered_configuration_itemss z3ConfigOptionParser._get_ordered_configuration_itemsc sHtj_t}D]\}ddkr>qjdkrz t|}Wn,t k rt j|} |YnXnjdkr| }fdd|D}nhjdkr| j}||}jpd}jpi}j||f||n|}||j<q|D]tj|<q&d_|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_falsecountr!csg|]}|qSr)rq)rEvrnrrrrrIsz7ConfigOptionParser._update_defaults..callbackr)rValuesrSvaluessetr| get_optionactionr ValueErrorinvalid_config_error_messageerrorrJaddr'get_opt_string convert_value callback_argscallback_kwargsrrqgetattr)rrS late_evalro error_msgopt_strrrrrrrRs@         z#ConfigOptionParser._update_defaultsc Cs|jst|jSz|jWn2tk rR}z|tt |W5d}~XYnX| |j }| D]4}| |j}t|trl|}|||||j<qlt|S)zOverriding to make updating the defaults after instantiation of the option parser possible, _update_defaults() does the dirty work.N)process_default_valuesrrrSreloadrrmrstrrRcopy_get_all_optionsgetr' isinstancerrri)rerrrSrdefaultrrrrget_default_valuess "   z%ConfigOptionParser.get_default_valuescCs"|tj|td|dS)Nz{} ) print_usagerlstderrrmrr))rr6rrrrs zConfigOptionParser.errorN) rMrNrOrPrrqr|rRrrrrrrrbs 1rbcCs |dkrd||Sd||S)zQReturns a better error message when invalid configuration option is provided.)r}r~zo{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.)r))rrnrorrrrsr)rP __future__rloggingrrlr3distutils.utilrZpip._vendor.sixrpip._internal.cli.status_codesrpip._internal.configurationrrpip._internal.utils.compatr getLoggerrMrvrr rQrgrUrbrrrrrs       P w