0{Y@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZGdd d ejZGd d d eZGd d d ejZGdddeZdS)zBase option parser setupN) strtobool) ConfigParser string_types)default_config_file)get_terminal_sizeget_prog) pkg_resourcesc@s|eZdZdZddZddZdddd Zd d Zd d ZddZ ddZ ddZ dS)PrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.cOsCd|dz, )_format_option_strings)roptionrrrformat_option_stringssz)PrettyHelpFormatter.format_option_stringsz <%s>z, cCsg}|jr&|j|jdn|jrF|j|jdnt|dkrk|jd|n|jr|jp|jj}|j||jndj |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"rrrrs   z*PrettyHelpFormatter._format_option_stringscCs|dkrdS|dS)NOptionsrz: r)rheadingrrrformat_heading3s z"PrettyHelpFormatter.format_headingcCs#d|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_usage8sz PrettyHelpFormatter.format_usagecCsy|rqt|jdr!d}nd}|jd}|j}|jtj|d}d||f}|SdSdS)NmainCommands Description z z%s: %s r)hasattrparserlstriprstripr,r-r.)r descriptionlabelrrrformat_description@s  z&PrettyHelpFormatter.format_descriptioncCs|r |SdSdS)Nrr)repilogrrr format_epilogRsz!PrettyHelpFormatter.format_epilogcs/fdd|jdD}dj|S)Ncsg|]}|qSrr).0line)indentrr Zs z4PrettyHelpFormatter.indent_lines..r5)splitr%)rtextrA new_linesr)rArr,Ys"z PrettyHelpFormatter.indent_linesN) __name__ __module__ __qualname____doc__rrrr+r1r<r>r,rrrrr s       r c@s"eZdZdZddZdS)UpdatingDefaultsHelpFormatterzCustom help formatter for use in ConfigOptionParser that updates the defaults before expanding them, allowing them to show up correctly in the help listingcCs;|jdk r(|jj|jjntjj||S)N)r7update_defaultsdefaultsrrexpand_default)rrrrrrMcsz,UpdatingDefaultsHelpFormatter.expand_defaultN)rFrGrHrIrMrrrrrJ^s rJc@s.eZdZddZeddZdS)CustomOptionParsercOs6|j||}|jj|jj|||S)z*Insert an OptionGroup at a given position.)add_option_group option_groupspopr )ridxrrgrouprrrinsert_option_groupjs z&CustomOptionParser.insert_option_groupcCs;|jdd}x!|jD]}|j|jqW|S)z.)z store_truez store_falsezcount) r\updatenormalize_keysget_config_sectionget_environ_varsitems get_optionactionrrCrvr#)rrLr^sectionrtr)rsrrrrKs"#  "z"ConfigOptionParser.update_defaultscCsYi}xL|D]D\}}|jdd}|jdsGd|}n||||j }|j ||||jq>Wtj|S)zOverridding to make updating the defaults after instantiation of the option parser possible, update_defaults() does the dirty work.) process_default_valuesrValuesrLrKcopy_get_all_optionsrgr# isinstancerget_opt_stringrm)rrLrdefaultopt_strrrrget_default_valuess   z%ConfigOptionParser.get_default_valuescCs(|jtj|jdd|dS)Nrz%s ) print_usagerostderrrr)rr0rrrerrorszConfigOptionParser.errorN) rFrGrHrIrr_rvrKr}r~rrrrrrrr[}s      r[)rIrorrer-distutils.utilrZpip.backwardcompatrr pip.locationsrpip.utilrr pip._vendorrrr rJrcrNr[rrrrs    O