Current File : //lib/python3.9/site-packages/pip/_internal/commands/__pycache__/configuration.cpython-39.pyc
a

[��f�"�@s�ddlZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
ddlmZmZmZmZddlmZddlmZdd	lmZmZe�e�ZGd
d�de
�ZdS)�N)�Values)�Any�List�Optional)�Command)�ERROR�SUCCESS)�
Configuration�Kind�get_configuration_files�kinds)�PipError)�
indent_log)�get_prog�write_outputc@s*eZdZdZdZdZdd�dd�Zeee	e
d�d	d
�Zeee
ed�dd
�Zeee	dd�dd�Zeee	dd�dd�Zeee	dd�dd�Zeee	dd�dd�Zeee	dd�dd�Zedd�dd�Zdd�dd�Zeee	dd�dd�Zee	e	e
ed�d d!�Zdd�d"d#�Zee	d$�d%d&�ZdS)'�ConfigurationCommandaa
    Manage local and global configuration.

    Subcommands:

    - list: List the active configuration (or from the file specified)
    - edit: Edit the configuration file in an editor
    - get: Get the value associated with name
    - set: Set the name=value
    - unset: Unset the value associated with name
    - debug: List the configuration files and values defined under them

    If none of --user, --global and --site are passed, a virtual
    environment configuration file is used if one is active and the file
    exists. Otherwise, all modifications happen to the user file by
    default.
    Ta
        %prog [<file-option>] list
        %prog [<file-option>] [--editor <editor-path>] edit

        %prog [<file-option>] get name
        %prog [<file-option>] set name value
        %prog [<file-option>] unset name
        %prog [<file-option>] debug
    N)�returncCsl|jjdddddd�|jjdddd	d
d�|jjdddd	d
d�|jjdddd	dd�|j�d|j�dS)Nz--editor�editor�storez\Editor to use to edit the file. Uses VISUAL or EDITOR environment variables if not provided.)�dest�action�default�helpz--global�global_file�
store_trueFz+Use the system-wide configuration file onlyz--user�	user_filez$Use the user configuration file onlyz--site�	site_filez3Use the current environment configuration file onlyr)Zcmd_optsZ
add_option�parserZinsert_option_group��self�r �H/usr/lib/python3.9/site-packages/pip/_internal/commands/configuration.py�add_options4s:����z ConfigurationCommand.add_options)�options�argsrc
Cs|j|j|j|j|j|jd�}|r.|d|vrHt�dd�t	|���t
S|d}z|j||dvd�}Wn8ty�}z t�|j
d�t
WYd}~Sd}~00t|j|d�|_|j��z||||dd��Wn:t�y}z t�|j
d�t
WYd}~Sd}~00tS)	N)�list�edit�get�set�unset�debugrzNeed an action (%s) to perform.z, )r'r(r)r&)�
need_value)�isolated�	load_only�)�list_values�open_in_editor�get_name�set_name_value�
unset_name�list_config_values�logger�error�join�sortedr�_determine_filer
r$r	Z
isolated_mode�
configuration�loadr)rr#r$�handlersrr-�er r r!�runZs>�
��
�
zConfigurationCommand.run)r#r+rcCs�dd�tj|jftj|jftj|jffD�}|s`|s8dStdd�t�tjD��rXtjStjSnt	|�dkrt|dSt
d��dS)NcSsg|]\}}|r|�qSr r )�.0�key�valuer r r!�
<listcomp>�s�z8ConfigurationCommand._determine_file.<locals>.<listcomp>css|]}tj�|�VqdS)N)�os�path�exists)r?Zsite_config_filer r r!�	<genexpr>�s�z7ConfigurationCommand._determine_file.<locals>.<genexpr>r.rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.)rZUSERrZGLOBALrZSITEr�anyr�lenr
)rr#r+Zfile_optionsr r r!r9�s&


��

��z$ConfigurationCommand._determine_filecCs8|j|ddd�t|j���D]\}}td||�qdS)Nr%r��n�%s=%r)�_get_n_argsr8r:�itemsr�rr#r$r@rAr r r!r/�sz ConfigurationCommand.list_valuescCs*|j|ddd�}|j�|�}td|�dS)Nz
get [name]r.rIz%s)rLr:Z	get_valuerrNr r r!r1�szConfigurationCommand.get_namecCs.|j|ddd�\}}|j�||�|��dS)Nzset [name] [value]�rI)rLr:Z	set_value�_save_configurationrNr r r!r2�sz#ConfigurationCommand.set_name_valuecCs(|j|ddd�}|j�|�|��dS)Nzunset [name]r.rI)rLr:Zunset_valuerP)rr#r$r@r r r!r3�szConfigurationCommand.unset_namec
Cs�|j|ddd�|��t|j���D]h\}}td|�|D]P}t��6tj�	|�}td||�|rn|�
|�Wd�q<1s�0Yq<q&dS)z9List config key-value pairs across different config filesr*rrI�%s:z%s, exists: %rN)rL�print_env_var_valuesr8r:Ziter_config_filesrrrCrDrE�print_config_file_values)rr#r$�variant�files�fnameZfile_existsr r r!r4�s
z'ConfigurationCommand.list_config_values)rTrc	CsP|j�|���D]:\}}t��td||�Wd�q1s@0YqdS)z.Get key-value pairs from the file of a variantz%s: %sN)r:Zget_values_in_configrMrr)rrT�namerAr r r!rS�sz-ConfigurationCommand.print_config_file_valuescCsftdd�t��Bt|j���D]"\}}d|����}td||�q Wd�n1sX0YdS)z5Get key-values pairs present as environment variablesrQ�env_varZPIP_rKN)rrr8r:Zget_environ_vars�upper)rr@rArXr r r!rR�s

z)ConfigurationCommand.print_env_var_valuesc
Csr|�|�}|j��}|dur$td��zt�||g�Wn6tjyl}ztd�|j���WYd}~n
d}~00dS)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {})	�_determine_editorr:Zget_file_to_editr
�
subprocessZ
check_callZCalledProcessError�format�
returncode)rr#r$rrVr=r r r!r0�s


�z#ConfigurationCommand.open_in_editor)r$�examplerJrcCs<t|�|kr$d�|t�|�}t|��|dkr4|dS|SdS)zAHelper to make sure the command got the right number of argumentszJGot unexpected number of arguments, expected {}. (example: "{} config {}")r.rN)rHr\rr
)rr$r^rJ�msgr r r!rL�s��z ConfigurationCommand._get_n_argscCs8z|j��Wn$ty2t�d�td��Yn0dS)Nz:Unable to save configuration. Please report this as a bug.zInternal Error.)r:Zsave�	Exceptionr5�	exceptionr
rr r r!rP�s�z(ConfigurationCommand._save_configuration)r#rcCsD|jdur|jSdtjvr$tjdSdtjvr8tjdStd��dS)NZVISUALZEDITORz"Could not determine editor to use.)rrC�environr
)rr#r r r!rZs




z&ConfigurationCommand._determine_editor)�__name__�
__module__�__qualname__�__doc__Zignore_require_venv�usager"rr�str�intr>�boolrr
r9r/r1r2r3r4rSrRr0rrLrPrZr r r r!rs"
&-r)ZloggingrCr[Zoptparser�typingrrrZpip._internal.cli.base_commandrZpip._internal.cli.status_codesrrZpip._internal.configurationr	r
rrZpip._internal.exceptionsr
Zpip._internal.utils.loggingrZpip._internal.utils.miscrrZ	getLoggerrcr5rr r r r!�<module>s