U jaH+@sdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z ddlmZddlmZmZddlmZmZeeZGdd d ejZGd d d eZGd d d ejZGdddeZdS)zBase option parser setupN)suppress)AnyDictIteratorListTuple) UNKNOWN_ERROR) ConfigurationConfigurationError)redact_auth_from_url strtoboolcseZdZdZeeddfdd ZejedddZ dejeeed d d Z eedddZ eedddZ eedddZ eedddZeeedddZZS)PrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.N)argskwargsreturncs6d|d<d|d<tdd|d<tj||dS)Nmax_help_positionindent_incrementrwidth)shutilget_terminal_sizesuper__init__)selfrr __class__p/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-bug3gbve/pip/_internal/cli/parser.pyrszPrettyHelpFormatter.__init__optionrcCs ||SN)_format_option_strings)rr!rrrformat_option_stringssz)PrettyHelpFormatter.format_option_strings <{}>, )r!mvarfmtoptseprcCsg}|jr||jd|jr0||jdt|dkrH|d||r|jdk s^t|jpl|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 rrN) _short_optsappend _long_optsleninsert takes_valuedestAssertionErrormetavarlowerformatjoin)rr!r'r(optsr2rrrr#s   z*PrettyHelpFormatter._format_option_strings)headingrcCs|dkr dS|dS)NOptionsr): r)rr7rrrformat_heading9sz"PrettyHelpFormatter.format_heading)usagercCsd|t|d}|S)zz Ensure there is only one newline between usage and the first heading if there is no description. z Usage: {}  )r4 indent_linestextwrapdedent)rr;msgrrr format_usage>sz PrettyHelpFormatter.format_usage) descriptionrcCsZ|rRt|jdrd}nd}|d}|}|t|d}|d|d}|SdSdS)NmainCommands Description r<r9r))hasattrparserlstriprstripr=r>r?)rrBlabelrrrformat_descriptionFs  z&PrettyHelpFormatter.format_description)epilogrcCs|r|SdSdS)Nr)r)rrMrrr format_epilogXsz!PrettyHelpFormatter.format_epilog)textindentrcs"fdd|dD}d|S)Ncsg|] }|qSrr).0linerPrr `sz4PrettyHelpFormatter.indent_lines..rF)splitr5)rrOrP new_linesrrSrr=_sz PrettyHelpFormatter.indent_lines)r%r&)__name__ __module__ __qualname____doc__rroptparseOptionstrr$r#r:rArLrNr= __classcell__rrrrr s  r cs*eZdZdZejedfdd ZZS)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. Also redact auth from url type options r csd}|jdk rLt|jtst|j|jj|jdk std|q$|dd\}}||kr$||||fq$|D] }||D]\}}||fVqzqndS)Nglobalz:env:cSsi|] }|gqSrr)rQr|rrr szGConfigOptionParser._get_ordered_configuration_items..z7Ignoring configuration key '%s' as it's value is empty..r)r|r}itemsloggerdebugrUr+)roverride_order section_items section_keyrjsectionr~rrr _get_ordered_configuration_itemss" z3ConfigOptionParser._get_ordered_configuration_items)rdrc stj_t}D]\}ddkr>qjdk sLtj dkrz t |}Wn&t k r d |YnXnj dkrtt t |}W5QRXtt t|}W5QRXt|tr|dkr d |nj dkr"|}fd d |D}n|j d krjdk s>t|j}||}jphd }jpti}j||f||n|}||j<q|D]tj|<qd_|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_falsezm{} is not a valid value for {} option, please specify a boolean value like yes/no, true/false or 1/0 instead.countrz{} is not a valid value for {} option, please instead specify either a non-negative integer or a boolean value like yes/no or false/true which is equivalent to 1/0.r+csg|]}|qSr)r)rQvr~r!rrrrTsz7ConfigOptionParser._update_defaults..callbackr)r[Valuesrdvaluessetr get_optionr0r1actionr ValueErrorerrorr4rrxrarUraddget_opt_string convert_value callback_argscallback_kwargsrgetattr)rrd late_evalrjopt_strrrrrrrcs\            z#ConfigOptionParser._update_defaultsc Cs|jst|jSz|jWn2tk rR}z|tt |W5d}~XYnX| |j }| D]B}|j dk s~t||j }t|t rl|}|||||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_valuesr[rrdr}loadr rrr]rccopy_get_all_optionsr0r1rerarr)rerrrdr!defaultrrrrget_default_values s "   z%ConfigOptionParser.get_default_values)r@rcCs"|tj|t|ddS)NrF) print_usagerstderrrr)rr@rrrr"s zConfigOptionParser.error)rWrXrYrZrr]boolrr[r\rrrrrrcrrrr^rrrrrbs  @rb)rZloggingr[rrr> contextlibrtypingrrrrrpip._internal.cli.status_codesrpip._internal.configurationr r pip._internal.utils.miscr r getLoggerrWrIndentedHelpFormatterr r_ OptionParserrkrbrrrrs   R