3 Bu_$@sddlZddlZddlZddlmZddlmZmZddlm Z m Z m Z ddl m Z ddlmZddlmZmZddlmZerdd lmZmZmZdd lmZdd lmZejeZGd d d eZdS)N)Command)ERRORSUCCESS) Configurationget_configuration_fileskinds)PipError) indent_log)get_prog write_output)MYPY_CHECK_RUNNING)ListAnyOptional)Values)Kindc@seZdZdZdZdZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd 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|jdS)Nz--editoreditorstorez\Editor to use to edit the file. Uses VISUAL or EDITOR environment variables if not provided.)destactiondefaulthelpz--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_optionparserinsert_option_group)selfr"/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-1.el7.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 dt Sd}~XnXt|j|d |_|jjy||||d dWn2t k r}ztj|j dt Sd}~XnXtS) N)listeditgetsetunsetdebugrzNeed an action (%s) to perform.z, r'r(r)r&) need_value)isolated load_only)r'r(r)r&) list_valuesopen_in_editorget_nameset_name_value unset_namelist_config_valuesloggererrorjoinsortedr_determine_filerargsr isolated_mode configurationloadr)r!optionsr:handlersrr-er"r"r#run_s6  zConfigurationCommand.runcCsddtj|jftj|jftj|jffD}|s`|s8dStddttjDrXtjStjSnt |dkrt|dSt ddS)NcSsg|]\}}|r|qSr"r").0keyvaluer"r"r# sz8ConfigurationCommand._determine_file..css|]}tjj|VqdS)N)ospathexists)rBsite_config_filer"r"r# sz7ConfigurationCommand._determine_file..r.rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) rUSERrGLOBALrSITEranyrlenr)r!r>r+Z file_optionsr"r"r#r9s    z$ConfigurationCommand._determine_filecCs<|j|dddx&t|jjD]\}}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#r1s zConfigurationCommand.get_namecCs.|j|ddd\}}|jj|||jdS)Nzset [name] [value])rP)rQr< set_value_save_configuration)r!r>r:rCrDr"r"r#r2sz#ConfigurationCommand.set_name_valuecCs(|j|ddd}|jj||jdS)Nz unset [name]r.)rP)rQr< unset_valuerV)r!r>r:rCr"r"r#r3s zConfigurationCommand.unset_namec Cs|j|ddd|jxjt|jjD]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) rQprint_env_var_valuesr8r<iter_config_filesr r rFrGrHprint_config_file_values)r!r>r:variantfilesfnameZ file_existsr"r"r#r4s   z'ConfigurationCommand.list_config_valuesc Cs@x:|jj|jD]&\}}ttd||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#rZsz-ConfigurationCommand.print_config_file_valuesc CsVtddt<x4t|jjD]"\}}dj|j}td||q"WWdQRXdS)z5Get key-values pairs present as environment variablesz%s:env_varzPIP_{}z%s=%rN)r r r8r<get_environ_varsformatupper)r!rCrDr`r"r"r#rXs  z)ConfigurationCommand.print_env_var_valuescCsp|j|}|jj}|dkr$tdytj||gWn4tjk rj}ztdj|jWYdd}~XnXdS)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) _determine_editorr<get_file_to_editr subprocess check_callCalledProcessErrorrb returncode)r!r>r:rr]r@r"r"r#r0s  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:ZexamplerPmsgr"r"r#rQs  z ConfigurationCommand._get_n_argsc Cs:y|jjWn&tk r4tjdtdYnXdS)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$tjdSdtjkr8tjdStddS)NZVISUALZEDITORz"Could not determine editor to use.)rrFenvironr)r!r>r"r"r#rds     z&ConfigurationCommand._determine_editorN)__name__ __module__ __qualname____doc__ignore_require_venvusager$rAr9r/r1r2r3r4rZrXr0rQrVrdr"r"r"r#rs" '.  r) loggingrFrfpip._internal.cli.base_commandrpip._internal.cli.status_codesrrpip._internal.configurationrrrpip._internal.exceptionsrpip._internal.utils.loggingr pip._internal.utils.miscr r pip._internal.utils.typingr typingr rroptparserr getLoggerror5rr"r"r"r#s