3 (\T@sddlZddlZddlZddlmZddlmZmZddlm Z m Z ddl m Z ddl mZmZddlmZddlmZejeZGd d d eZdS) N)Command)ERRORSUCCESS) Configurationkinds)PipError)running_under_virtualenvsite_config_file) deprecated)get_progcs|eZdZdZdZdZdZfddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZZS)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. configz %prog [] list %prog [] [--editor ] edit %prog [] get name %prog [] set name value %prog [] unset name z&Manage local and global configuration.cstt|j||d|_|jjdddddd|jjdddd d d|jjd d dd d d|jjdddd dd|jjdddd dd|jjd|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 onlyz--venv venv_filezY[Deprecated] Use the current environment configuration file in a virtual environment onlyr)superr __init__ configurationcmd_opts add_optionparserinsert_option_group)selfargskwargs) __class__w/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/commands/configuration.pyr-sBzConfigurationCommand.__init__cCs|j|j|j|j|jd}| s,|d|krJtjdjdjt |t S|d}y|j ||d kd }Wn0t k r}ztj|j dt Sd}~XnXt|j|d |_|jjy||||d dWn2t k r}ztj|j dt Sd}~XnXtS) N)listeditgetsetunsetrzNeed an action ({}) to perform.z, r(r)r*r') need_value)isolated load_only)r(r)r*r') list_valuesopen_in_editorget_nameset_name_value unset_nameloggererrorformatjoinsortedr_determine_filerr!r isolated_moderloadr)r optionsr!handlersrr-er$r$r%runbs2  zConfigurationCommand.runcCs|jr2|j r2tr*d|_tddddntdddtj|jftj|j ftj |jffD}|s|sjdSt j j tr|tj StjSnt|d kr|d Std dS) NTz&The --venv option has been deprecated.z--sitez19.3) replacementZgone_inzHLegacy --venv option requires a virtual environment. Use --site instead.cSsg|]\}}|r|qSr$r$).0keyvaluer$r$r% sz8ConfigurationCommand._determine_file..r.rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.)rrrr rrUSERrGLOBALrZSITEospathexistsr len)r r<r+Z file_optionsr$r$r%r9s.     z$ConfigurationCommand._determine_filecCs>|j|dddx(t|jjD]\}}tjd||q WdS)Nr&r)nz%s=%r) _get_n_argsr8ritemsr4info)r r<r!rBrCr$r$r%r/sz ConfigurationCommand.list_valuescCs,|j|ddd}|jj|}tjd|dS)Nz get [name]r.)rKz%s)rLr get_valuer4rN)r r<r!rBrCr$r$r%r1s zConfigurationCommand.get_namecCs.|j|ddd\}}|jj|||jdS)Nzset [name] [value])rK)rLrZ set_value_save_configuration)r r<r!rBrCr$r$r%r2sz#ConfigurationCommand.set_name_valuecCs(|j|ddd}|jj||jdS)Nz unset [name]r.)rK)rLrZ unset_valuerQ)r r<r!rBr$r$r%r3s zConfigurationCommand.unset_namecCsp|j|}|jj}|dkr$tdytj||gWn4tjk rj}ztdj|jWYdd}~XnXdS)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) _determine_editorrZget_file_to_editr subprocess check_callCalledProcessErrorr6 returncode)r r<r!rfnamer>r$r$r%r0s  z#ConfigurationCommand.open_in_editorcCs<t||kr$dj|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)rJr6r r)r r!ZexamplerKmsgr$r$r%rLs  z ConfigurationCommand._get_n_argsc Cs>y|jjWn*tk r8tjdddtdYnXdS)Nz:Unable to save configuration. Please report this as a bug.r.)exc_infozInternal Error.)rsave Exceptionr4r5r)r r$r$r%rQsz(ConfigurationCommand._save_configurationcCsD|jdk r|jSdtjkr$tjdSdtjkr8tjdStddS)NZVISUALZEDITORz"Could not determine editor to use.)rrGenvironr)r r<r$r$r%rRs     z&ConfigurationCommand._determine_editor)__name__ __module__ __qualname____doc__nameusagesummaryrr?r9r/r1r2r3r0rLrQrR __classcell__r$r$)r#r%r s 5+& r )loggingrGrSZpip._internal.cli.base_commandrZpip._internal.cli.status_codesrrZpip._internal.configurationrrZpip._internal.exceptionsrZpip._internal.locationsrr Zpip._internal.utils.deprecationr Zpip._internal.utils.miscr getLoggerr]r4r r$r$r$r%s