Re$@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 c Cs|jjddddddddd|jjd dd dd dd dd |jjddddd dd dd|jjddddd dd dd|jjd|jdS)Nz--editordesteditoractionstoredefaulthelpz\Editor to use to edit the file. Uses VISUAL or EDITOR environment variables if not provided.z--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-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_internal/commands/configuration.py add_options8s2    z ConfigurationCommand.add_optionscCsjd|jd|jd|jd|jd|jd|ji}| sS|d|krvtjdd jt |t S|d}y|j |d |dk}Wn=t k r}ztj|j dt SWYdd}~XnXtd |jd ||_|jjy||||d dWn=t k re}ztj|j dt SWYdd}~XnXtS)NlisteditgetsetunsetdebugrzNeed an action (%s) to perform.z, need_valueisolated 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|sPdStddttjDrztjStjSnt |dkr|dSt ddS)NcSs"g|]\}}|r|qSr"r").0keyvaluer"r"r# s z8ConfigurationCommand._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_filecCsP|j|dddx3t|jjD]\}}td||q,WdS)Nr%nrz%s=%r) _get_n_argsr8r<itemsr )r!r>r:rCrDr"r"r#r/s"z ConfigurationCommand.list_valuescCs;|j|ddd}|jj|}td|dS)Nz get [name]rPr.z%s)rQr< get_valuer )r!r>r:rCrDr"r"r#r1szConfigurationCommand.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_valuecCs6|j|ddd}|jj||jdS)Nz unset [name]rPr.)rQr< unset_valuerV)r!r>r:rCr"r"r#r3szConfigurationCommand.unset_namec Cs|j|ddd|jxt|jjD]p\}}td|xT|D]L}t:tjj |}td|||r|j |WdQRXqVWq6WdS)z9List config key-value pairs across different config filesr*rPrz%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 CsNxG|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#rZs  z-ConfigurationCommand.print_config_file_valuesc CsmtddtPxHt|jjD]1\}}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_valuescCs|j|}|jj}|dkr6tdytj||gWn@tjk r}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_editorcCsRt||kr6dj|t|}t||dkrJ|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 CsCy|jjWn+tk r>tjdtdYnXdS)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_configurationcCsZ|jdk r|jSdtjkr0tjdSdtjkrJtjdStddS)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