o Ec"@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--editoreditorZstorez\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)Zcmd_optsZ add_optionparserZinsert_option_groupselfrW/opt/alt/python310/lib/python3.10/site-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 Z isolated_mode configurationloadr)rr"r#handlersrr,errr runZsF    zConfigurationCommand.runr*cCszddtj|jftj|jftj|jffD}|s/|sdStddttjDr,tjStjSt |dkr9|dSt d)NcSsg|]\}}|r|qSrr).0keyvaluerrr s z8ConfigurationCommand._determine_file..css|] }tj|VqdS)N)ospathexists)r>Zsite_config_filerrr s  z7ConfigurationCommand._determine_file..r-rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) r ZUSERrZGLOBALrZSITEranyr lenr )rr"r*Z file_optionsrrr r8s&      z$ConfigurationCommand._determine_filecCs8|j|dddt|jD] \}}td||qdS)Nr$rn%s=%r) _get_n_argsr7r9itemsrrr"r#r?r@rrr r.sz ConfigurationCommand.list_valuescCs*|j|ddd}|j|}td|dS)Nz get [name]r-rHz%s)rKr9Z get_valuerrMrrr r0s zConfigurationCommand.get_namecCs.|j|ddd\}}|j|||dS)Nzset [name] [value]rH)rKr9Z set_value_save_configurationrMrrr r1s z#ConfigurationCommand.set_name_valuecCs(|j|ddd}|j||dS)Nz unset [name]r-rH)rKr9Z unset_valuerO)rr"r#r?rrr r2s  zConfigurationCommand.unset_namec Cs|j|ddd|t|jD]4\}}td||D](}ttj |}td|||r7| |Wdn1sAwYqqdS)z9List config key-value pairs across different config filesr)rrH%s:z%s, exists: %rN) rKprint_env_var_valuesr7r9Ziter_config_filesrrrBrCrDprint_config_file_values)rr"r#variantfilesfnameZ file_existsrrr r3s    z'ConfigurationCommand.list_config_valuesrSc CsP|j|D]\}}ttd||Wdn1s wYqdS)z.Get key-value pairs from the file of a variantz%s: %sN)r9Zget_values_in_configrLrr)rrSnamer@rrr rRs z-ConfigurationCommand.print_config_file_valuescCshtddt"t|jD]\}}d|}td||qWddS1s-wYdS)z5Get key-values pairs present as environment variablesrPenv_varZPIP_rJN)rrr7r9Zget_environ_varsupper)rr?r@rWrrr rQs "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_editorr9Zget_file_to_editr subprocessZ check_callZCalledProcessErrorformat returncode)rr"r#rrUr<rrr r/s   z#ConfigurationCommand.open_in_editorexamplerIcCs8t||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 {}")r-r)rGr[rr )rr#r]rImsgrrr rKs  z ConfigurationCommand._get_n_argscCs2z|jWdStytdtdw)Nz:Unable to save configuration. Please report this as a bug.zInternal Error.)r9Zsave Exceptionr4 exceptionr rrrr rOs z(ConfigurationCommand._save_configurationcCs@|jdur|jSdtjvrtjdSdtjvrtjdStd)NZVISUALZEDITORz"Could not determine editor to use.)rrBenvironr )rr"rrr rYs     z&ConfigurationCommand._determine_editor)rN)__name__ __module__ __qualname____doc__Zignore_require_venvZusager!rrstrintr=boolrr r8r.r0r1r2r3rRrQr/rrKrOrYrrrr rs$ &-   r)ZloggingrBrZZoptparsertypingrrrZpip._internal.cli.base_commandrZpip._internal.cli.status_codesrrZpip._internal.configurationr r r r Zpip._internal.exceptionsr Zpip._internal.utils.loggingrZpip._internal.utils.miscrrZ getLoggerrbr4rrrrr s