U ÀÒ.e:ã@s‚ddlZddlZddlZddlmZddlmZmZddlm Z m Z m Z ddl m Z ddlmZmZe e¡ZGdd„deƒZdS) éN)ÚCommand)ÚERRORÚSUCCESS)Ú ConfigurationÚget_configuration_filesÚkinds)ÚPipError)Úget_progÚ write_outputcsxeZdZdZdZdZ‡fdd„Zdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Z‡ZS)Ú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 cs„tt|ƒj||Žd|_|jjdddddd�|jjdddd d d�|jjd d dd d d�|jjdddd dd�|j d|j¡dS)Nz--editorÚeditorZstorez\Editor to use to edit the file. Uses VISUAL or EDITOR environment variables if not provided.)ÚdestÚactionÚdefaultÚhelpz--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_optionÚparserZinsert_option_group)ÚselfÚargsÚkwargs©Ú __class__©úH/usr/lib/python3.8/site-packages/pip/_internal/commands/configuration.pyr0s>ú ûûûzConfigurationCommand.__init__c Cs|j|j|j|j|jdœ}|r*|d|krHt d d t |ƒ¡¡¡t S|d}z|j ||dkd�}Wn:t k r }zt |j d¡t WY¢Sd}~XYnXt|j|d�|_|j ¡z||||dd…ƒWn<t k �r}zt |j d¡t WY¢Sd}~XYnXtS) N)ÚlistÚeditÚgetÚsetÚunsetrzNeed an action ({}) to perform.z, )r"r#r$r!)Ú need_value)ÚisolatedÚ load_onlyé)Ú list_valuesÚopen_in_editorÚget_nameÚset_name_valueÚ unset_nameÚloggerÚerrorÚformatÚjoinÚsortedrÚ_determine_filerrrZ isolated_moderÚloadr)rÚoptionsrZhandlersrr'ÚerrrÚrunZs>û  ÿÿ ÿ zConfigurationCommand.runcCs€dd„tj|jftj|jftj|jffDƒ}|s`|s8dStdd„tƒtjDƒƒrXtjStjSnt |ƒdkrt|dSt dƒ‚dS)NcSsg|]\}}|r|‘qSrr)Ú.0ÚkeyÚvaluerrrÚ †süz8ConfigurationCommand._determine_file..css|]}tj |¡VqdS)N)ÚosÚpathÚexists)r8Zsite_config_filerrrÚ �sÿz7ConfigurationCommand._determine_file..r(rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) rZUSERrZGLOBALrZSITErÚanyrÚlenr)rr5r%Z file_optionsrrrr3…s$   ý þ ÿz$ConfigurationCommand._determine_filecCs8|j|ddd�t|j ¡ƒD]\}}td||ƒqdS)Nr r©Únz%s=%r)Ú _get_n_argsr2rÚitemsr ©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$tdƒ‚zt ||g¡Wn4tjk rj}ztd |j¡ƒ‚W5d}~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)rrZexamplerCÚmsgrrrrDÆs ÿýz ConfigurationCommand._get_n_argscCs>z|j ¡Wn*tk r8tjddd�tdƒ‚YnXdS)Nz:Unable to save configuration. Please report this as a bug.r()Úexc_infozInternal Error.)rZsaveÚ Exceptionr.r/r)rrrrrHÕsþz(ConfigurationCommand._save_configurationcCsD|jdk r|jSdtjkr$tjdSdtjkr8tjdStdƒ‚dS)NZVISUALZEDITORz"Could not determine editor to use.)r r<Úenvironr)rr5rrrrIás     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 rrrrÚs