o g"@sddlZddlZddlZddlmZddlmZmZmZddl m Z ddl m Z m Z ddlmZmZmZmZddlmZddlmZdd lmZmZeeZGd d d e ZdS) N)Values)AnyListOptional)Command)ERRORSUCCESS) ConfigurationKindget_configuration_fileskinds)PipError) indent_log)get_prog write_outputc@sHeZdZdZdZdZd(ddZded ee de fd d Z ded e de efd dZded ee ddfddZded ee ddfddZded ee ddfddZded ee ddfddZded ee ddfddZdeddfddZd(ddZded ee ddfddZd ee d e d!e defd"d#Zd(d$d%Zdede fd&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 [] list %prog [] [--editor ] edit %prog [] get name %prog [] set name value %prog [] unset name %prog [] debug returnNcCsl|jjdddddd|jjdddd d d|jjd d dd d d|jjdddd dd|jd|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_groupselfr#F/usr/lib/python3/dist-packages/pip/_internal/commands/configuration.py add_options4s: z ConfigurationCommand.add_optionsoptionsargsc Cs|j|j|j|j|j|jd}|r|d|vr$tddt |t S|d}z |j ||dvd}Wnt yO}zt|j dt WYd}~Sd}~wwt|j|d|_|jz||||ddWtSt y}zt|j dt WYd}~Sd}~ww) N)listeditgetsetunsetdebugrzNeed an action (%s) to perform.z, )r*r+r,r)) need_value)isolated load_only) list_valuesopen_in_editorget_nameset_name_value unset_namelist_config_valuesloggererrorjoinsortedr_determine_filer r'r isolated_mode configurationloadr)r"r&r'handlersrr0er#r#r$runZsF    zConfigurationCommand.runr.cCszddtj|jftj|jftj|jffD}|s/|sdStddttjDr,tjStjSt |dkr9|dSt d)NcSsg|]\}}|r|qSr#r#).0keyvaluer#r#r$ s z8ConfigurationCommand._determine_file..css|] }tj|VqdS)N)ospathexists)rCsite_config_filer#r#r$ s  z7ConfigurationCommand._determine_file..r1rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) r USERrGLOBALrSITEranyr lenr )r"r&r. file_optionsr#r#r$r<s&      z$ConfigurationCommand._determine_filecCs8|j|dddt|jD] \}}td||qdS)Nr(rn%s=%r) _get_n_argsr;r>itemsrr"r&r'rDrEr#r#r$r2sz ConfigurationCommand.list_valuescCs*|j|ddd}|j|}td|dS)Nz get [name]r1rRz%s)rUr> get_valuerrWr#r#r$r4s zConfigurationCommand.get_namecCs.|j|ddd\}}|j|||dS)Nzset [name] [value]rR)rUr> set_value_save_configurationrWr#r#r$r5s z#ConfigurationCommand.set_name_valuecCs(|j|ddd}|j||dS)Nz unset [name]r1rR)rUr> unset_valuer[)r"r&r'rDr#r#r$r6s  zConfigurationCommand.unset_namec Cs|j|ddd|t|jD]4\}}td||D](}ttj |}td|||r7| |Wdn1sAwYqqdS)z9List config key-value pairs across different config filesr-rrR%s:z%s, exists: %rN) rUprint_env_var_valuesr;r>iter_config_filesrrrGrHrIprint_config_file_values)r"r&r'variantfilesfname file_existsr#r#r$r7s    z'ConfigurationCommand.list_config_valuesrac CsP|j|D]\}}ttd||Wdn1s wYqdS)z.Get key-value pairs from the file of a variantz%s: %sN)r>get_values_in_configrVrr)r"ranamerEr#r#r$r`s z-ConfigurationCommand.print_config_file_valuescCshtddt"t|jD]\}}d|}td||qWddS1s-wYdS)z5Get key-values pairs present as environment variablesr]env_varPIP_rTN)rrr;r>get_environ_varsupper)r"rDrErgr#r#r$r^s "z)ConfigurationCommand.print_env_var_valuesc Csd||}|j}|durtdz t||gWdStjy1}ztd|jd}~ww)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) _determine_editorr>get_file_to_editr subprocess check_callCalledProcessErrorformat returncode)r"r&r'rrcrAr#r#r$r3s   z#ConfigurationCommand.open_in_editorexamplerScCs8t||krd|t|}t||dkr|dS|S)zAHelper to make sure the command got the right number of argumentszJGot unexpected number of arguments, expected {}. (example: "{} config {}")r1r)rPrprr )r"r'rrrSmsgr#r#r$rUs  z ConfigurationCommand._get_n_argscCs2z|jWdStytdtdw)Nz:Unable to save configuration. Please report this as a bug.zInternal Error.)r>save Exceptionr8 exceptionr r!r#r#r$r[s z(ConfigurationCommand._save_configurationcCs@|jdur|jSdtjvrtjdSdtjvrtjdStd)NVISUALEDITORz"Could not determine editor to use.)rrGenvironr )r"r&r#r#r$rks     z&ConfigurationCommand._determine_editor)rN)__name__ __module__ __qualname____doc__ignore_require_venvusager%rrstrintrBboolrr r<r2r4r5r6r7r`r^r3rrUr[rkr#r#r#r$rs$ &-   r)loggingrGrmoptparsertypingrrrpip._internal.cli.base_commandrpip._internal.cli.status_codesrrpip._internal.configurationr r r r pip._internal.exceptionsr pip._internal.utils.loggingrpip._internal.utils.miscrr getLoggerrzr8rr#r#r#r$s