U .e:@sddlZddlZddlZddlmZddlmZmZddlm Z m Z m Z ddl m Z ddlmZmZeeZGdddeZdS) N)Command)ERRORSUCCESS) Configurationget_configuration_fileskinds)PipError)get_prog write_outputcsxeZdZdZdZdZfddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZZS)ConfigurationCommanda9Manage 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 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. Tz %prog [] list %prog [] [--editor ] edit %prog [] get name %prog [] set name value %prog [] unset name cstt|j||d|_|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)superr __init__ configurationZcmd_optsZ add_optionparserZinsert_option_group)selfargskwargs __class__H/usr/lib/python3.8/site-packages/pip/_internal/commands/configuration.pyr0s> zConfigurationCommand.__init__c Cs|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)listeditgetsetunsetrzNeed an action ({}) to perform.z, )r"r#r$r!) need_value)isolated load_only) list_valuesopen_in_editorget_nameset_name_value unset_nameloggererrorformatjoinsortedr_determine_filerrrZ isolated_moderloadr)roptionsrZhandlersrr'errrrunZs>    zConfigurationCommand.runcCsddtj|jftj|jftj|jffD}|s`|s8dStddttjDrXtjStjSnt |dkrt|dSt ddS)NcSsg|]\}}|r|qSrr).0keyvaluerrr sz8ConfigurationCommand._determine_file..css|]}tj|VqdS)N)ospathexists)r8Zsite_config_filerrr sz7ConfigurationCommand._determine_file..r(rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) rZUSERrZGLOBALrZSITEranyrlenr)rr5r%Z file_optionsrrrr3s$     z$ConfigurationCommand._determine_filecCs8|j|dddt|jD]\}}td||qdS)Nr rnz%s=%r) _get_n_argsr2ritemsr rr5rr9r:rrrr)sz ConfigurationCommand.list_valuescCs*|j|ddd}|j|}td|dS)Nz get [name]r(rBz%s)rDrZ get_valuer rFrrrr+s zConfigurationCommand.get_namecCs.|j|ddd\}}|j|||dS)Nzset [name] [value]rB)rDrZ set_value_save_configurationrFrrrr,sz#ConfigurationCommand.set_name_valuecCs(|j|ddd}|j||dS)Nz unset [name]r(rB)rDrZ unset_valuerH)rr5rr9rrrr-s zConfigurationCommand.unset_namec Csp||}|j}|dkr$tdzt||gWn4tjk rj}ztd|jW5d}~XYnXdS)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) _determine_editorrZget_file_to_editr subprocessZ check_callZCalledProcessErrorr0 returncode)rr5rr Zfnamer6rrrr*s  z#ConfigurationCommand.open_in_editorcCs<t||kr$d|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)rAr0r r)rrZexamplerCmsgrrrrDs z ConfigurationCommand._get_n_argscCs>z|jWn*tk r8tjdddtdYnXdS)Nz:Unable to save configuration. Please report this as a bug.r()exc_infozInternal Error.)rZsave Exceptionr.r/r)rrrrrHsz(ConfigurationCommand._save_configurationcCsD|jdk r|jSdtjkr$tjdSdtjkr8tjdStddS)NZVISUALZEDITORz"Could not determine editor to use.)r r<environr)rr5rrrrIs     z&ConfigurationCommand._determine_editor)__name__ __module__ __qualname____doc__Zignore_require_venvZusagerr7r3r)r+r,r-r*rDrHrI __classcell__rrrrr s *+ r )Zloggingr<rJZpip._internal.cli.base_commandrZpip._internal.cli.status_codesrrZpip._internal.configurationrrrZpip._internal.exceptionsrZpip._internal.utils.miscr r Z getLoggerrPr.r rrrrs