zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
U
H=®d€$ã@sÊddlZddlZddlZddlmZddlmZmZddlm    Z    m
Z
m Z ddl m Z ddlmZddlmZmZddlmZer¬dd    lmZmZmZdd
lmZdd lmZe e¡ZGd d „d eƒZdS)éN)ÚCommand)ÚERRORÚSUCCESS)Ú ConfigurationÚget_configuration_filesÚkinds)ÚPipError)Ú
indent_log)Úget_progÚ write_output)ÚMYPY_CHECK_RUNNING)ÚListÚAnyÚOptional)ÚValues)ÚKindc@sˆeZdZdZdZdZdd„Zdd„Zdd    „Zd
d „Z    d d „Z
dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd S)!ÚConfigurationCommandah
    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 on the to the user file by
    default.
    Ta
        %prog [<file-option>] list
        %prog [<file-option>] [--editor <editor-path>] edit
 
        %prog [<file-option>] get name
        %prog [<file-option>] set name value
        %prog [<file-option>] unset name
        %prog [<file-option>] debug
    cCsl|jjdddddd|jjdddd    d
d|jjd d dd    d d|jjdddd    dd|j d|j¡dS)Nz--editorÚeditorÚstorez\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)Úcmd_optsÚ
add_optionÚparserÚinsert_option_group©Úself©r#ú[D:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_internal/commands/configuration.pyÚ add_options8s:ú ûûûz ConfigurationCommand.add_optionsc
Cs|j|j|j|j|j|jdœ}|r.|d|krHt dd 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ÚunsetÚdebugrzNeed an action (%s) to perform.z, )r(r)r*r')Ú
need_value)ÚisolatedÚ    load_onlyé)Ú list_valuesÚopen_in_editorÚget_nameÚset_name_valueÚ
unset_nameÚlist_config_valuesÚloggerÚerrorÚjoinÚsortedrÚ_determine_filerÚargsrÚ isolated_modeÚ configurationÚloadr)r"Úoptionsr;Úhandlersrr.Úer#r#r$Úrun_sBú
 þÿ
ÿ
zConfigurationCommand.runcCs€dd„tj|jftj|jftj|jffDƒ}|s`|s8dStdd„tƒtjDƒƒrXtjStjSnt    |ƒdkrt|dSt
dƒ‚dS)NcSsg|]\}}|r|‘qSr#r#)Ú.0ÚkeyÚvaluer#r#r$Ú
<listcomp>süz8ConfigurationCommand._determine_file.<locals>.<listcomp>css|]}tj |¡VqdS)N)ÚosÚpathÚexists)rCÚsite_config_filer#r#r$Ú    <genexpr>™sÿz7ConfigurationCommand._determine_file.<locals>.<genexpr>r/rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) rÚUSERrÚGLOBALrÚSITErÚanyrÚlenr)r"r?r,Z file_optionsr#r#r$r:s$
 
 
ý
þ ÿz$ConfigurationCommand._determine_filecCs8|j|dddt|j ¡ƒD]\}}td||ƒqdS)Nr&r©Únú%s=%r)Ú _get_n_argsr9r=Úitemsr ©r"r?r;rDrEr#r#r$r0¨sz ConfigurationCommand.list_valuescCs*|j|ddd}|j |¡}td|ƒdS)Nz
get [name]r/rQz%s)rTr=Ú    get_valuer rVr#r#r$r2¯s zConfigurationCommand.get_namecCs.|j|ddd\}}|j ||¡| ¡dS)Nzset [name] [value]érQ)rTr=Ú    set_valueÚ_save_configurationrVr#r#r$r3¶sz#ConfigurationCommand.set_name_valuecCs(|j|ddd}|j |¡| ¡dS)Nz unset [name]r/rQ)rTr=Ú unset_valuerZ)r"r?r;rDr#r#r$r4½s zConfigurationCommand.unset_namec Cs€|j|ddd| ¡t|j ¡ƒD]T\}}td|ƒ|D]<}tƒ,tj     |¡}td||ƒ|rn| 
|¡W5QRXq<q&dS)z9List config key-value pairs across different config filesr+rrQú%s:z%s, exists: %rN) rTÚprint_env_var_valuesr9r=Úiter_config_filesr r    rGrHrIÚprint_config_file_values)r"r?r;ÚvariantÚfilesÚfnameZ file_existsr#r#r$r5Äs
 ÿz'ConfigurationCommand.list_config_valuesc
Cs<|j |¡ ¡D]&\}}tƒtd||ƒW5QRXqdS)z.Get key-value pairs from the file of a variantz%s: %sN)r=Úget_values_in_configrUr    r )r"r`ÚnamerEr#r#r$r_Ös
ÿz-ConfigurationCommand.print_config_file_valuesc    CsRtddƒtƒ8t|j ¡ƒD]"\}}d | ¡¡}td||ƒq W5QRXdS)z5Get key-values pairs present as environment variablesr\Úenv_varzPIP_{}rSN)r r    r9r=Úget_environ_varsÚformatÚupper)r"rDrErer#r#r$r]Þs
 
z)ConfigurationCommand.print_env_var_valuesc
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_editorr=Úget_file_to_editrÚ
subprocessÚ
check_callÚCalledProcessErrorrgÚ
returncode)r"r?r;rrbrAr#r#r$r1ç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)rPrgr
r)r"r;ZexamplerRÚmsgr#r#r$rT÷s ÿýz ConfigurationCommand._get_n_argscCs:z|j ¡Wn&tk
r4t d¡tdƒ‚YnXdS)Nz:Unable to save configuration. Please report this as a bug.zInternal Error.)r=ÚsaveÚ    Exceptionr6Ú    exceptionrr!r#r#r$rZsÿz(ConfigurationCommand._save_configurationcCsD|jdk    r|jSdtjkr$tjdSdtjkr8tjdStdƒ‚dS)NZVISUALZEDITORz"Could not determine editor to use.)rrGÚenvironr)r"r?r#r#r$ris
 
 
 
 
z&ConfigurationCommand._determine_editorN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__Úignore_require_venvÚusager%rBr:r0r2r3r4r5r_r]r1rTrZrir#r#r#r$rs"
'.     r) ÚloggingrGrkÚpip._internal.cli.base_commandrÚpip._internal.cli.status_codesrrÚpip._internal.configurationrrrÚpip._internal.exceptionsrÚpip._internal.utils.loggingr    Úpip._internal.utils.miscr
r Úpip._internal.utils.typingr Útypingr rrÚoptparserrÚ    getLoggerrtr6rr#r#r#r$Ú<module>s