U ʗRe%@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@s*eZdZdZdZdZddddZeee e dd d Z ee e ed d d Zeee ddddZeee ddddZeee ddddZeee ddddZeee ddddZeddddZddddZeee ddddZee e e edd d!Zddd"d#Zee d$d%d&ZdS)'ConfigurationCommanda 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 command.option - set: Set the command.option=value - unset: Unset the value associated with command.option - debug: List the configuration files and values defined under them Configuration keys should be dot separated command and option name, with the special prefix "global" affecting any command. For example, "pip config set global.index-url https://example.org/" would configure the index url for all commands, but "pip config set download.timeout 10" would configure a 10 second timeout only for "pip download" commands. 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 command.option %prog [] set command.option value %prog [] unset command.option %prog [] debug N)returncCsl|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#/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_internal/commands/configuration.py add_options:s: z ConfigurationCommand.add_options)optionsargsrc Cs|j|j|j|j|j|jd}|r.|d|krHtddt |t S|d}z|j ||dkd}Wn:t k r}zt|j dt WYSd}~XYnXt|j|d|_|jz||||ddWn<t k r}zt|j dt WYSd}~XYnXtS) 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$run`sB    zConfigurationCommand.run)r&r.rcCsddtj|jftj|jftj|jffD}|s`|s8dStddttjDrXtjStjSnt |dkrt|dSt ddS)NcSsg|]\}}|r|qSr#r#).0keyvaluer#r#r$ sz8ConfigurationCommand._determine_file..css|]}tj|VqdS)N)ospathexists)rCsite_config_filer#r#r$ sz7ConfigurationCommand._determine_file..r1rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) r USERrGLOBALrSITEranyr lenr )r"r&r.Z 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]r1rQz%s)rTr> get_valuerrVr#r#r$r4s zConfigurationCommand.get_namecCs.|j|ddd\}}|j|||dS)Nzset [name] [value]rQ)rTr> set_value_save_configurationrVr#r#r$r5sz#ConfigurationCommand.set_name_valuecCs(|j|ddd}|j||dS)Nz unset [name]r1rQ)rTr> unset_valuerZ)r"r&r'rDr#r#r$r6s zConfigurationCommand.unset_namec Cs|j|ddd|t|jD]T\}}td||D]<}t,tj |}td|||rn| |W5QRXqiter_config_filesrrrGrHrIprint_config_file_values)r"r&r'variantfilesfnameZ file_existsr#r#r$r7s   z'ConfigurationCommand.list_config_values)r`rc Cs<|j|D]&\}}ttd||W5QRXqdS)z.Get key-value pairs from the file of a variantz%s: %sN)r>get_values_in_configrUrr)r"r`namerEr#r#r$r_sz-ConfigurationCommand.print_config_file_valuesc CsRtddt8t|jD]"\}}d|}td||q W5QRXdS)z5Get key-values pairs present as environment variablesr\env_varPIP_rSN)rrr;r>get_environ_varsupper)r"rDrErer#r#r$r]s  z)ConfigurationCommand.print_env_var_valuesc Cs||}|j}|dkr$tdzt||gWnbtk rf}z|jsT||_W5d}~XYn4tjk r}ztd |j W5d}~XYnXdS)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) _determine_editorr>get_file_to_editr subprocess check_callFileNotFoundErrorfilenameCalledProcessErrorformat returncode)r"r&r'rrbrAr#r#r$r3s   z#ConfigurationCommand.open_in_editor)r'examplerRrcCs<t||kr$d|t|}t||dkr4|dS|SdS)zAHelper to make sure the command got the right number of argumentszJGot unexpected number of arguments, expected {}. (example: "{} config {}")r1rN)rPrprr )r"r'rrrRmsgr#r#r$rTs z ConfigurationCommand._get_n_argscCs:z|jWn&tk r4tdtdYnXdS)Nz:Unable to save configuration. Please report this as a bug.zInternal Error.)r>save Exceptionr8 exceptionr r!r#r#r$rZsz(ConfigurationCommand._save_configuration)r&rcCsD|jdk r|jSdtjkr$tjdSdtjkr8tjdStddS)NZVISUALZEDITORz"Could not determine editor to use.)rrGenvironr )r"r&r#r#r$ri s     z&ConfigurationCommand._determine_editor)__name__ __module__ __qualname____doc__ignore_require_venvusager%rrstrintrBboolrr r<r2r4r5r6r7r_r]r3rrTrZrir#r#r#r$rs" &- r)loggingrGrkoptparsertypingrrrpip._internal.cli.base_commandrpip._internal.cli.status_codesrrpip._internal.configurationr r r r pip._internal.exceptionsr pip._internal.utils.loggingrpip._internal.utils.miscrr getLoggerrxr8rr#r#r#r$s