B
    =)H[<"  ã               @   s¶   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZmZ e e¡ZG dd	„ d	ejƒZG d
d„ deƒZG dd„ dejƒZG dd„ deƒZdS )zBase option parser setupé    )Úabsolute_importN)Ú	strtobool)Ústring_types)Úget_terminal_size)ÚConfigurationÚConfigurationErrorc               @   sR   e Zd ZdZdd„ Zdd„ Zddd	„Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚPrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.c             O   s:   d|d< d|d< t ƒ d d |d< tjj| f|ž|Ž d S )Né   Úmax_help_positioné   Úindent_incrementr   é   Úwidth)r   ÚoptparseÚIndentedHelpFormatterÚ__init__)ÚselfÚargsÚkwargs© r   úYC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_internal\baseparser.pyr      s    zPrettyHelpFormatter.__init__c             C   s   |   |dd¡S )Nz <%s>z, )Ú_format_option_strings)r   Úoptionr   r   r   Úformat_option_strings   s    z)PrettyHelpFormatter.format_option_stringsú <%s>ú, c             C   s|   g }|j r| |j d ¡ |jr0| |jd ¡ t|ƒdkrH| d|¡ | ¡ rr|jp^|j ¡ }| || ¡  ¡ d 	|¡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
        r   r   Ú )
Ú_short_optsÚappendÚ
_long_optsÚlenÚinsertÚtakes_valueÚmetavarÚdestÚlowerÚjoin)r   r   ÚmvarfmtÚoptsepÚoptsr#   r   r   r   r      s    z*PrettyHelpFormatter._format_option_stringsc             C   s   |dkrdS |d S )NÚOptionsr   z:
r   )r   Úheadingr   r   r   Úformat_heading6   s    z"PrettyHelpFormatter.format_headingc             C   s   d|   t |¡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_linesÚtextwrapÚdedent)r   ÚusageÚmsgr   r   r   Úformat_usage;   s    z PrettyHelpFormatter.format_usagec             C   sV   |rNt | jdƒrd}nd}| d¡}| ¡ }|  t |¡d¡}d||f }|S dS d S )NÚmainÚCommandsÚDescriptionÚ
z  z%s:
%s
r   )ÚhasattrÚparserÚlstripÚrstripr-   r.   r/   )r   ÚdescriptionÚlabelr   r   r   Úformat_descriptionC   s    
z&PrettyHelpFormatter.format_descriptionc             C   s   |r|S dS d S )Nr   r   )r   Úepilogr   r   r   Úformat_epilogU   s    z!PrettyHelpFormatter.format_epilogc                s"   ‡ fdd„|  d¡D ƒ}d |¡S )Nc                s   g | ]}ˆ | ‘qS r   r   )Ú.0Úline)Úindentr   r   ú
<listcomp>]   s    z4PrettyHelpFormatter.indent_lines.<locals>.<listcomp>r6   )Úsplitr&   )r   ÚtextrB   Ú	new_linesr   )rB   r   r-   \   s    z PrettyHelpFormatter.indent_linesN)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r,   r2   r=   r?   r-   r   r   r   r   r      s   
r   c               @   s   e Zd ZdZdd„ ZdS )ÚUpdatingDefaultsHelpFormatterz®Custom help formatter for use in ConfigOptionParser.

    This is updates the defaults before expanding them, allowing
    them to show up correctly in the help listing.
    c             C   s(   | j d k	r| j  | j j¡ tj | |¡S )N)r8   Ú_update_defaultsÚdefaultsr   r   Úexpand_default)r   r   r   r   r   rN   h   s    
z,UpdatingDefaultsHelpFormatter.expand_defaultN)rG   rH   rI   rJ   rN   r   r   r   r   rK   a   s   rK   c               @   s    e Zd Zdd„ Zedd„ ƒZdS )ÚCustomOptionParserc             O   s(   | j ||Ž}| j ¡  | j ||¡ |S )z*Insert an OptionGroup at a given position.)Úadd_option_groupÚoption_groupsÚpopr!   )r   Úidxr   r   Úgroupr   r   r   Úinsert_option_groupp   s    
z&CustomOptionParser.insert_option_groupc             C   s.   | j dd… }x| jD ]}| |j ¡ qW |S )z<Get a list of all options, including those in option groups.N)Úoption_listrQ   Úextend)r   ÚresÚir   r   r   Úoption_list_ally   s    z"CustomOptionParser.option_list_allN)rG   rH   rI   rU   ÚpropertyrZ   r   r   r   r   rO   n   s   	rO   c               @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚConfigOptionParserzsCustom option parser which updates its defaults by checking the
    configuration files and environmental variablesc             O   sD   |  d¡| _|  dd¡}t|ƒ| _| js,t‚tjj| f|ž|Ž d S )NÚnameÚisolatedF)rR   r]   r   ÚconfigÚAssertionErrorr   ÚOptionParserr   )r   r   r   r^   r   r   r   r   ‡   s
    

zConfigOptionParser.__init__c          
   C   sL   y|  ||¡S  tjk
rF } ztd| ƒ t d¡ W d d }~X Y nX d S )Nz*An error occurred during configuration: %sé   )Úcheck_valuer   ÚOptionValueErrorÚprintÚsysÚexit)r   r   ÚkeyÚvalÚexcr   r   r   Úcheck_default�   s
    z ConfigOptionParser.check_defaultc             c   s    d| j dg}dd„ |D ƒ}xR| j ¡ D ]D\}}|s@t d|¡ q&| dd¡\}}||kr&||  ||f¡ q&W x,|D ]$}x|| D ]\}}||fV  q‚W qtW d S )NÚglobalz:env:c             S   s   i | ]
}g |“qS r   r   )r@   r]   r   r   r   ú
<dictcomp>œ   s    zGConfigOptionParser._get_ordered_configuration_items.<locals>.<dictcomp>z7Ignoring configuration key '%s' as it's value is empty.Ú.r   )r]   r_   ÚitemsÚloggerÚdebugrD   r   )r   Úoverride_orderÚsection_itemsÚsection_keyri   Úsectionrh   r   r   r   Ú _get_ordered_configuration_items—   s    
z3ConfigOptionParser._get_ordered_configuration_itemsc                s  t  ˆj¡ˆ_tƒ }xÚˆ ¡ D ]Î\‰ }ˆ dˆ  ¡‰ˆdkr>qˆjdkrRt|ƒ}n�ˆjdkr|| 	¡ }‡ ‡‡fdd„|D ƒ}nfˆjdkrÔ| 
ˆj¡ ˆ ¡ }ˆ ||¡}ˆjp®d}ˆjp¸i }ˆjˆ||ˆf|ž|Ž nˆ ˆˆ |¡}||ˆj< qW x|D ]‰ tˆjˆ ƒ|ˆ < qöW dˆ_|S )	z¢Updates 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_falseÚcountr   c                s   g | ]}ˆ  ˆˆ |¡‘qS r   )rk   )r@   Úv)rh   r   r   r   r   rC   Æ   s    z7ConfigOptionParser._update_defaults.<locals>.<listcomp>Úcallbackr   )r   ÚValuesrM   ÚvaluesÚsetrv   Ú
get_optionÚactionr   rD   Úaddr$   Úget_opt_stringÚconvert_valueÚcallback_argsÚcallback_kwargsr{   rk   Úgetattr)r   rM   Ú	late_evalri   Úopt_strr   r   r   )rh   r   r   r   rL   ¯   s0    






z#ConfigOptionParser._update_defaultsc          
   C   s²   | j st | j¡S y| j ¡  W n4 tk
rT } z|  d|jd ¡ W dd}~X Y nX |  	| j 
¡ ¡}x@|  ¡ D ]4}| |j¡}t|tƒrp| ¡ }| ||¡||j< qpW t |¡S )z‹Overriding to make updating the defaults after instantiation of
        the option parser possible, _update_defaults() does the dirty work.r   r   N)Úprocess_default_valuesr   r|   rM   r_   Úloadr   rg   r   rL   ÚcopyÚ_get_all_optionsÚgetr$   Ú
isinstancer   r‚   rc   )r   ÚerrrM   r   Údefaultrˆ   r   r   r   Úget_default_valuesÙ   s    $
z%ConfigOptionParser.get_default_valuesc             C   s    |   tj¡ |  dd| ¡ d S )Nr   z%s
)Úprint_usagerf   Ústderrrg   )r   r1   r   r   r   Úerrorî   s    zConfigOptionParser.errorN)
rG   rH   rI   rJ   r   rk   rv   rL   r‘   r”   r   r   r   r   r\   ƒ   s   	*r\   )rJ   Ú
__future__r   Úloggingr   rf   r.   Údistutils.utilr   Úpip._vendor.sixr   Úpip._internal.compatr   Úpip._internal.configurationr   r   Ú	getLoggerrG   rp   r   r   rK   ra   rO   r\   r   r   r   r   Ú<module>   s   
O