3 ”Re€$ã@sÊddlZddlZddlZddlmZddlmZmZddlm Z m Z m Z ddl m Z ddlmZddlmZmZddlmZer¬dd lmZmZmZdd lmZdd lmZejeƒZGd d „d eƒZdS)éN)ÚCommand)ÚERRORÚSUCCESS)Ú ConfigurationÚget_configuration_filesÚkinds)ÚPipError)Ú indent_log)Úget_progÚ write_output)ÚMYPY_CHECK_RUNNING)ÚListÚAnyÚOptional)ÚValues)ÚKindc@sˆeZdZdZdZdZdd„Zdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd S)!ÚConfigurationCommandah 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 on the to the user file by default. Ta %prog [] list %prog [] [--editor ] edit %prog [] get name %prog [] set name value %prog [] unset name %prog [] debug cCsl|jjdddddd�|jjdddd d d�|jjd d dd d d�|jjdddd dd�|jjd|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)Úcmd_optsÚ add_optionÚparserÚinsert_option_group)Úself©r"ú“/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/commands/configuration.pyÚ add_options8s2z ConfigurationCommand.add_optionscCs|j|j|j|j|j|jdœ}| s0|d|krJtjddjt |ƒƒƒt S|d}y|j ||d kd �}Wn0t k r˜}ztj|j dƒt Sd}~XnXt|j|d �|_|jjƒy||||d d…ƒWn2t k �r}ztj|j dƒt Sd}~XnXtS) N)ÚlistÚeditÚgetÚsetÚunsetÚdebugrzNeed an action (%s) to perform.z, r'r(r)r&)Ú need_value)ÚisolatedÚ load_onlyé)r'r(r)r&)Ú list_valuesÚopen_in_editorÚget_nameÚset_name_valueÚ unset_nameÚlist_config_valuesÚloggerÚerrorÚjoinÚsortedrÚ_determine_filerÚargsrÚ isolated_modeÚ configurationÚloadr)r!Úoptionsr:Úhandlersrr-Úer"r"r#Úrun_s6  zConfigurationCommand.runcCs€dd„tj|jftj|jftj|jffDƒ}|s`|s8dStdd„tƒtjDƒƒrXtjStjSnt |ƒdkrt|dSt dƒ‚dS)NcSsg|]\}}|r|‘qSr"r")Ú.0ÚkeyÚvaluer"r"r#ú �sz8ConfigurationCommand._determine_file..css|]}tjj|ƒVqdS)N)ÚosÚpathÚexists)rBÚsite_config_filer"r"r#ú šsz7ConfigurationCommand._determine_file..r.rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) rÚUSERrÚGLOBALrÚSITErÚanyrÚlenr)r!r>r+Z file_optionsr"r"r#r9�s    z$ConfigurationCommand._determine_filecCs<|j|ddd�x&t|jjƒƒD]\}}td||ƒq WdS)Nr%r)Únz%s=%r)Ú _get_n_argsr8r<Úitemsr )r!r>r:rCrDr"r"r#r/¨sz ConfigurationCommand.list_valuescCs*|j|ddd�}|jj|ƒ}td|ƒdS)Nz get [name]r.)rPz%s)rQr<Ú get_valuer )r!r>r:rCrDr"r"r#r1¯s zConfigurationCommand.get_namecCs.|j|ddd�\}}|jj||ƒ|jƒdS)Nzset [name] [value]é)rP)rQr<Ú set_valueÚ_save_configuration)r!r>r:rCrDr"r"r#r2¶sz#ConfigurationCommand.set_name_valuecCs(|j|ddd�}|jj|ƒ|jƒdS)Nz unset [name]r.)rP)rQr<Ú unset_valuerV)r!r>r:rCr"r"r#r3½s zConfigurationCommand.unset_namec Csˆ|j|ddd�|jƒxjt|jjƒƒD]X\}}td|ƒxD|D]<}tƒ�,tjj |ƒ}td||ƒ|rr|j |ƒWdQRXq@Wq(WdS)z9List config key-value pairs across different config filesr*r)rPz%s:z%s, exists: %rN) rQÚprint_env_var_valuesr8r<Úiter_config_filesr r rFrGrHÚprint_config_file_values)r!r>r:ÚvariantÚfilesÚfnameZ file_existsr"r"r#r4Äs   z'ConfigurationCommand.list_config_valuesc Cs@x:|jj|ƒjƒD]&\}}tƒ�td||ƒWdQRXqWdS)z.Get key-value pairs from the file of a variantz%s: %sN)r<Úget_values_in_configrRr r )r!r[ÚnamerDr"r"r#rZÖsz-ConfigurationCommand.print_config_file_valuesc CsVtddƒtƒ�<x4t|jjƒƒD]"\}}dj|jƒƒ}td||ƒq"WWdQRXdS)z5Get key-values pairs present as environment variablesz%s:Úenv_varzPIP_{}z%s=%rN)r r r8r<Úget_environ_varsÚformatÚupper)r!rCrDr`r"r"r#rXÞs  z)ConfigurationCommand.print_env_var_valuescCsp|j|ƒ}|jjƒ}|dkr$tdƒ‚ytj||gƒWn4tjk rj}ztdj|jƒƒ‚WYdd}~XnXdS)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) Ú_determine_editorr<Úget_file_to_editrÚ subprocessÚ check_callÚCalledProcessErrorrbÚ returncode)r!r>r:rr]r@r"r"r#r0çs  z#ConfigurationCommand.open_in_editorcCs<t|ƒ|kr$dj|tƒ|ƒ}t|ƒ‚|dkr4|dS|SdS)zJHelper to make sure the command got the right number of arguments zJGot unexpected number of arguments, expected {}. (example: "{} config {}")r.rN)rOrbr r)r!r:ZexamplerPÚmsgr"r"r#rQ÷s  z ConfigurationCommand._get_n_argsc Cs:y|jjƒWn&tk r4tjdƒtdƒ‚YnXdS)Nz:Unable to save configuration. Please report this as a bug.zInternal Error.)r<ÚsaveÚ Exceptionr5Ú exceptionr)r!r"r"r#rVs z(ConfigurationCommand._save_configurationcCsD|jdk r|jSdtjkr$tjdSdtjkr8tjdStdƒ‚dS)NZVISUALZEDITORz"Could not determine editor to use.)rrFÚenvironr)r!r>r"r"r#rds     z&ConfigurationCommand._determine_editorN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Úignore_require_venvÚusager$rAr9r/r1r2r3r4rZrXr0rQrVrdr"r"r"r#rs" '.  r) ÚloggingrFrfÚpip._internal.cli.base_commandrÚpip._internal.cli.status_codesrrÚpip._internal.configurationrrrÚpip._internal.exceptionsrÚpip._internal.utils.loggingr Úpip._internal.utils.miscr r Úpip._internal.utils.typingr Útypingr rrÚoptparserrÚ getLoggerror5rr"r"r"r#Ús