a [f"@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)'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 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)Zcmd_optsZ add_optionparserZinsert_option_groupselfr H/usr/lib/python3.9/site-packages/pip/_internal/commands/configuration.py add_options4s: z ConfigurationCommand.add_options)optionsargsrc Cs|j|j|j|j|j|jd}|r.|d|vrHtddt |t S|d}z|j ||dvd}Wn8t y}z t|j dt WYd}~Sd}~00t|j|d|_|jz||||ddWn:t y}z t|j dt WYd}~Sd}~00tS) 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-er r r!runZs>    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)r?Zsite_config_filer r r! sz7ConfigurationCommand._determine_file..r.rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) r ZUSERrZGLOBALrZSITEranyr lenr )rr#r+Z file_optionsr r r!r9s&      z$ConfigurationCommand._determine_filecCs8|j|dddt|jD]\}}td||qdS)Nr%rn%s=%r) _get_n_argsr8r:itemsrrr#r$r@rAr r r!r/sz ConfigurationCommand.list_valuescCs*|j|ddd}|j|}td|dS)Nz get [name]r.rIz%s)rLr:Z get_valuerrNr r r!r1s zConfigurationCommand.get_namecCs.|j|ddd\}}|j|||dS)Nzset [name] [value]rI)rLr:Z set_value_save_configurationrNr r r!r2sz#ConfigurationCommand.set_name_valuecCs(|j|ddd}|j||dS)Nz unset [name]r.rI)rLr:Z unset_valuerP)rr#r$r@r r r!r3s zConfigurationCommand.unset_namec Cs|j|ddd|t|jD]h\}}td||D]P}t6tj |}td|||rn| |Wdq<1s0Yqboolrr r9r/r1r2r3r4rSrRr0rrLrPrZr r r r!rs" &- r)ZloggingrCr[ZoptparsertypingrrrZpip._internal.cli.base_commandrZpip._internal.cli.status_codesrrZpip._internal.configurationr r r r Zpip._internal.exceptionsr Zpip._internal.utils.loggingrZpip._internal.utils.miscrrZ getLoggerrcr5rr r r r!s