
    wBfe                    8   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ erddlmZmZmZ ddlmZ ddZddZd Zd Zd Z d Z!i g d	 	 	 	 	 	 	 	 	 ddZ"d dZ#d dZ$d!dZ%d"dZ&d#dZ'd$dZ(d Z)y)%zCLI implementation for `conda config`.

Allows for programmatically interacting with conda's configuration files (e.g., `~/.condarc`).
    )annotationsN)SUPPRESS)MappingSequence)chain)	getLogger)isfilejoin)Path)wrap)TYPE_CHECKING)ArgumentParser	Namespace_SubParsersAction)Anyc           	        ddl m} ddlm} ddlm}m}m} ddlm	} ddl
m} |j                  dd	      }	|j                  dd	      }
d
} |d| d|	 d      } |d| d      } | j                  	 dD|||d|} ||       |j                  dd|	z        }|j                         }|j!                  ddd|
z         |j!                  dddj#                  |j$                  xs d|	             |j!                  ddd       |j                  d      }|j                         }|j!                  ddd d !       |j!                  d"dd#       |j!                  d$dd%       |j!                  d&dd d'!       |j!                  d(dd)       |j                  d*      }|j                         }|j!                  d+ddd,d d-.       |j!                  d/dd0d1g d2.       |j!                  d3d4dd0d5g d2.       |j!                  d6dd0d7g d2.       |j!                  d8dd0d9g d2.       |j!                  d:d0d;g d-<       |j!                  d=dd>       |j!                  d?d@d|t&        A       |j)                  dBC       |S )EN   )dals)CONDA_HOMEPAGE_URLcontextsys_rc_pathuser_rc_path)NULL   )add_parser_json%z%%z(Modify configuration values in .condarc.z	
        zc

        This is modeled after the git config command.  Writes to the user .condarc
        file (z) by default. Use the
        --show-sources flag to display all identified configuration locations on
        your computer.

        z*
        See `conda config --describe` or a  /docs/config.html
        for details on all the options that can go in .condarc.

        Examples:

        Display all configuration values as calculated and compiled::

            conda config --show

        Display all identified configuration sources::

            conda config --show-sources

        Print the descriptions of all available configuration
        options to your command line::

            conda config --describe

        Print the description for the "channel_priority" configuration
        option to your command line::

            conda config --describe channel_priority

        Add the conda-canary channel::

            conda config --add channels conda-canary

        Set the output verbosity to level 3 (highest) for
        the current activate environment::

            conda config --set verbosity 3 --env

        Add the 'conda-forge' channel as a backup to 'defaults'::

            conda config --append channels conda-forge

        )helpdescriptionepilogzConfig File Location SelectionzAWithout one of these flags, the user config file at '%s' is used.z--system
store_truez*Write to the system .condarc file at '%s'.)actionr   z--envzzWrite to the active conda environment .condarc file ({}). If no environment is active, write to the user config file ({}).z<no active environment>z--filestorezWrite to the given file.zConfig Subcommandsz--show*z~Display configuration values as calculated and compiled. If no arguments given, show information for all configuration values.)nargsdefaultr   z--show-sourcesz-Display all identified configuration sources.z
--validatezcValidate all configuration sources. Iterates over all .condarc files and checks for parsing errors.z
--describezrDescribe given configuration parameters. If no arguments given, show information for all configuration parameters.z--write-defaultz`Write the default configuration to a file. Equivalent to `conda config --describe > ~/.condarc`.zConfig Modifiersz--getzGet a configuration value.KEY)r%   r"   r   r&   metavarz--appendappendz5Add one configuration value to the end of a list key.)r'   VALUEz	--prepend--addz;Add one configuration value to the beginning of a list key.--setzSet a boolean or string key.z--removezfRemove a configuration value from a list key.
                This removes all instances of the value.z--remove-keyz0Remove a configuration key (and all its values).)r"   r   r&   r(   z--stdinzIApply configuration information given in yaml format piped through stdin.z-fz--force)r"   r&   r   zconda.cli.main_config.execute)func)config)
auxlib.ishr   base.constantsr   base.contextr   r   r   common.constantsr   helpersr   replace
add_parseradd_argument_groupadd_mutually_exclusive_groupadd_argumentformatactive_prefixr   set_defaults)sub_parserskwargsr   r   r   r   r   r   r   escaped_user_rc_pathescaped_sys_rc_pathsummaryr   r    pconfig_file_location_grouplocation_config_subcommandsconfig_subcommands_config_modifiersconfig_modifierss                        5lib/python3.12/site-packages/conda/cli/main_config.pyconfigure_parserrI      s   !3AA'('//T:%--c488G			  $$ %			
K **<)= $>	%	'FR 				
 	A A "#!5!5(K
	"
 *FFHH9<OO  
 6!!>%> 
  	 (79ST
 ../CD,IIK##P	 $  ##< $ 
 ##) $  ##8	 $  ##@ $  ,,-?@(EEG!!) "  !!H  "  !!N  "  !!/  "  !!<  "  !!C "  !!X "  NN   NN7N8H    c                j    ddl m} ddlm} 	 t	        | |      S # |t
        f$ r} ||      d }~ww xY w)Nr   
CondaErrorCouldntParseError) rM   
exceptionsrO   execute_configNotImplementedError)argsparserrM   rO   es        rH   executerW      s:    .dF++23 ms    2-2c                   ddl m} ddlm}m} g }| j                         D ]  \  }}t        |t              rC|r,|j                  d|z         |j                   ||             D|j                  d|z         Y ||      rC|r,|j                  d|z         |j                   ||             |j                  d|z         |j                  dj                  |||nd              |S )	Nr   )
isiterable)pretty_list
pretty_mapz%s:z%s: {}z%s: []z{}: {}None)
common.compatrY   common.configurationrZ   r[   items
isinstancer   r)   r9   )drY   rZ   r[   lineskvs          rH   format_dictre      s    *>E	 M1a!UQY'Z]+X\*]UQY'[^,X\*LLAFKLM LrJ   c                   ddl m} ddlm} ddlm} g }|j                  |       }|d   }|j                  d      }|d   }t        j                  |d   |	      }	|d
   dk(  rH|j                  dj                  | dj                  t        |D 
ch c]  }
|
 c}
                         nK|j                  dj                  | |d
   dj                  t        |D 
ch c]  }
|
 c}
                         |r#|j                  ddj                  |      z         |r|j                  d|z         |j                  d t        |d   d      D               |j                  d       |D cg c]  }d|z   	 }}|j                   || t        j                   |	      i      j#                         j%                  d             |D cg c]  }d|z   	 }}|j                  d       |S c c}
w c c}
w c c}w c c}w )Nr   EntityEncoderr   )yaml_round_trip_dumpaliasesstring_delimiterelement_typesdefault_value)clsparameter_type	primitivez{} ({})z, z{} ({}: {})z  aliases: %sz   env var string delimiter: '%s'c              3  &   K   | ]	  }d |z     yw)z  N ).0lines     rH   	<genexpr>z0parameter_description_builder.<locals>.<genexpr>%  s     L44$;Ls   r   F   rP   z# 
)auxlib.entityrh   r1   r   common.serializerj   describe_parametergetjsondumpsr)   r9   r
   sortedextendr   loadsstripsplit)namerh   r   rj   builderdetailsrk   rl   rm   default_value_stretru   s               rH   parameter_description_builderr     s   -&7G((.Gi G{{#56O,M

7?#;O K/T499V-4PBR4P-Q#RS	
 	  ()		&}!="!=>?	
 7);;<9<LLMNNL40F+KLLNN2'./ttd{/G/NNdDJJ/@$ABCIIKQQRVW (//ttd{/G/NN2N7 5Q "> 0 0s   	G'	G,+G1G6c                    ddl m}  g }d}| j                  j                         D ]  \  }}||v r|j	                  d       |j	                  d|dd       |j	                  d       |j	                  d       |j                  t        j                  d	 |D                     |j	                  d        d
j                  |      S )Nr   ri   zCLI-onlyzHidden and Undocumentedz8# ######################################################z# ## z^48z ##rP   c              3  2   K   | ]  }t        |        y wNr   rt   r   s     rH   rv   z*describe_all_parameters.<locals>.<genexpr>@  s       8<-d3    rx   )	r1   r   category_mapr_   r)   r   r   from_iterabler
   )r   r   skip_categoriescategoryparameter_namess        rH   describe_all_parametersr   3  s    &G=O%,%9%9%?%?%A !/&QRxnC01QRr  @O  	

 	r 99WrJ   c           
     Z   t        d      j                  }t        |t        f      r+|j	                         D ]  \  }}t        | dz   |z   |        y t        |t        t        t        f      r$ |dj                  d| t        |      f             y t        |t        t        f      rt        |      }t        t        |            D ]b  \  }}| dk(  r5|d|dz
  fv r, |dj                  d| t        |      |dk(  rd	nd
f             @ |dj                  d| t        |      f             d y y )Nconda.stdout. r,   channelsr   r   r+   z  # lowest priorityz  # highest priority)r   infor`   dictr_   print_config_itemboolintstrr
   listtuplelen	enumeratereversedrepr)keyvaluestdout_writerc   rd   numitemsqitems           rH   r   r   H  s   ^,11L%$!KKM 	0DAqcCi!mQ/	0	ED#s+	,SXXwSZ89:	ED%=	) u: %1 	CGAtj Q1hl*;%;HH# J56!V1AW		 SXXwT$Z&@AB	C 
*rJ   r}   warningsc               b   ddl m} | j                  d      }|d   |j                         vrF|j                  r|j                  d|d          y t        d|d   t        j                         y |}	 |D ]  }||   }	 	 |j                  r||| <   y t        | |       y # t        $ r Y y w xY w)Nr   ri   r   r   zUnknown key: )file)r1   r   r   list_parametersr}   r)   printsysstderrr   KeyError)r   r.   r}   r   r   	key_parts
sub_configparts           rH   _get_keyr   d  s     '		#I|72244<<OOmIaL+;<= 	 M)A,!12DJ
/ 	*D#D)J	* <<"DIc:.  s   6B" "	B.-B.c                n   ddl m} | j                  d      }	 |j                  |d         d   }|dk(  r)t        |      d	k(  r|\  } |j                  | |d
      || <   y |dk(  r)t        |      dk(  r|\  } }||j                  | i       |<   y ddlm}  || d      # t        $ r ddlm}  || d      w xY w)Nr   ri   r   r   rp   CondaKeyErrorunknown parameterrq   r   z--set parametermapinvalid parameter)
r1   r   r   r{   r   rQ   r   r   typify_parameter
setdefault)r   r   r.   r   r   rp   r   subkeys           rH   _set_keyr     s    &		#I6 33IaLABRS $Y1)<..sD:KLs	5	 S^q%8V-1#r"6*.C!455  6.C!455	6s   B B4c                   ddl m} | j                  d      }	 |j                  |d         d   }|dk(  rgt        |      d	k(  rY|\  } | |vr| d
k7  rddlm}  || d      dg|| <   |||    vrddlm}  || d|d      ||    D cg c]
  }||k7  s	| c}|| <   y ddlm}  || d      # t        $ r ddlm}  || d      w xY wc c}w )Nr   ri   r   r   rp   r   r   sequencer   r   undefined in configdefaultszvalue z not present in configr   )r1   r   r   r{   r   rQ   r   r   )r   r   r.   r   r   rp   r   is           rH   _remove_itemr     s    &		#I6 33IaLABRS #I!(;fj 6#C)>??%,F3Kvc{"2vdX5K%LMM"(+;Qdq;s.C!455/  6.C!455	6& <s   B+ 
CC+Cc                    | j                  d      }|}	 |d d D ]  }||   }	 ||d   = y # t        $ r ddlm}  || d      w xY w)Nr   r   r   r   )r   r   rQ   r   )r   r.   r   r   r   r   s         rH   _remove_keyr     sd    		#IJ8crN 	*D#D)J	*y}% 8.C!677	8s	   + Ac                x    ddl m} 	  |t        |       j                               xs i S # t        $ r i cY S w xY w)Nr   yaml_round_trip_load)rz   r   r   	read_textFileNotFoundError)pathr   s     rH   _read_rcr     s;    7#DJ$8$8$:;ArA 	s   "+ 99c                   ddl m} ddlm}m}m}m}m}m} ddl	m
}	m}
 d }|	j                  j                  j                  ||       |	j                  j                  j                  ||       |	j                  j                  j                  ||       |	j                  j                  j                  ||       |	j                  j                  j                  ||       |	j                  j                  j                  ||       	 t        |       j!                   |
|             y # t"        $ r} |d|  d|      d }~ww xY w)Nr   rL   )ChannelPriorityDepsModifierPathConflictSafetyChecksSatSolverChoiceUpdateModifier)yamlrj   c                6    | j                  t        |            S r   )represent_strr   )dumperdatas     rH   enum_representerz#_write_rc.<locals>.enum_representer  s    ##CI..rJ   z Cannot write to condarc file at z
Caused by )rP   rM   r0   r   r   r   r   r   r   rz   r   rj   representerRoundTripRepresenteradd_representerr   
write_textOSError)r   r.   rM   r   r   r   r   r   r   r   rj   r   rV   s                rH   	_write_rcr     s.     >/ 	))99& 	))99& 	))99& 	))99( 	))99) 	))99)UT
26:; U;D6aUSTTUs    D( (	E1D??Ec                `    t        |       }|D ]  \  }}t        |||        t        | |       y r   )r   r   r   )r   rT   r.   r   r   s        rH   set_keysr     s4    d^F %
UeV$%dFrJ   c                  345 ddl m} ddlm} ddlm3m}m} ddlm	} ddl
m} ddlm} t        d      j                  }	t        d	      j                  }
g }i }| j                   r3j"                  rZ |	t#        j$                  3j'                         j)                         D ci c]  \  }}t+        |      | c}}d
dd|             y g }3j'                         j)                         D ]D  \  }}|j-                  d|z         |j/                  t1        |             |j-                  d       F  |	dj3                  |             y | j4                  | j4                  rR| j4                  }3j7                         }t9        |      t9        |      z
  }|r-ddlm} ddlm}  |d ||      z        3j7                         }|D ci c]  }|tA        3|       }}3j"                  r! |	t#        j$                  |d
dd|             nd|v rH|d   jC                         D ci c](  }|jD                  |jF                   d|jH                   * c}|d<   d|v r8ddlm} |d   j)                         D ci c]  \  }}| ||d       c}}|d<   d|v rd4tK        4fd|d   D              |d<    |	dj3                  t1        |                   3jM                          y | jN                  | jN                  r| jN                  }3j7                         }t9        |      t9        |      z
  }|rddlm} ddlm}  |d ||      z        3j"                  r> |	t#        j$                  |D cg c]  }3jQ                  |       c}d
dd|             y g }|j/                  tS        jT                  d |D                      |	dj3                  |             y 3j"                  rd5tW        tS        jT                  5fd3jX                  j)                         D                    } |	t#        j$                  |D cg c]  }3jQ                  |       c}d
dd|             y  |	t[                      y | j\                  r3j_                          y | j`                  r|}nM| jb                  r&3jd                  rt3        3jd                  d      }n|}n| jf                  r| jf                  }n|}| jh                  rytk        |      r?tm        |      5 }|jo                         jq                         }d d d        r |d|z        tm        |d       5 }|js                  t[                      d d d        y tt        jv                  jy                  |      r!tm        |      5 } ||      xs i } d d d        nBtt        jv                  jy                  |      r!tm        |      5 } ||      xs i } d d d        ni }  |3fd!3j7                               }!|!d"   }"|!d#   }#| jz                  K3j_                          | jz                  xs tW         j}                               D ]  }t        | ||$        | j                  r> |d%t        j                  jn                        }$|$sy 	  ||$      }% j                  |%       t        | j                  | j,                  fd(      D ]  \  }'}(|'D ]w  \  }})d)|v r|j                  d)d*      n|d f\  }}*|d+k(  r
| vrd,g| |<   ||"v r j                  |g       }+n8||#v r# j                  |i       j                  |*g       }+ndd-lmI},  |,d.|z        t        |+t              rt        |+t*              r.dd/lmL}- | |   j                  j                  }. |-d0|d1|. d)      |)|+v r|*|d)z   |*z   n|}/d2j                  |)|/|(rd3nd4      }0|*|+D 1cg c]
  }1|1|)k7  s	|1 c}1x}+| |<   n|+D 1cg c]
  }1|1|)k7  s	|1 c}1x}+| |   |*<   3j"                  s	 |
|0       n|j-                  |0       |+j                  |(rd5n
t        |+      |)       z  | j8                  D ]  \  }})t        ||)         | j                  D ]  \  }})t        ||)         | j                  D ]  }t        |         | jz                  st        |        3j"                  rd*d6lXmY}2  |2|||7       y y c c}}w c c}w c c}w c c}}w c c}w c c}w # 1 sw Y   xY w# 1 sw Y   y xY w# 1 sw Y   GxY w# 1 sw Y   TxY w# t        $ r dd&lmD}&  |&d'|$z        w xY wc c}1w c c}1w )8Nr   rL   rg   r   )timeout)groupby_to_dictr   r   zconda.stderrT),z: )	sort_keysindent
separatorsro   z
==> %s <==rP   rx   )dashlist)ArgumentErrorz$Invalid configuration parameters: %scustom_channelsz://custom_multichannels   )r   channel_settingsz    c              3  X   K   | ]!  }d  j                  t        |             # yw)rx   N)r
   re   )rt   mappingidents     rH   rv   z!execute_config.<locals>.<genexpr>V  s/      . L%%k'&:;.s   '*c              3  2   K   | ]  }t        |        y wr   r   r   s     rH   rv   z!execute_config.<locals>.<genexpr>x  s      (@D5d;(r   r   c              3  0   K   | ]  \  }}|vr|  y wr   rs   )rt   r   r   r   s      rH   rv   z!execute_config.<locals>.<genexpr>  s%      (5Ho#?: ((s   z.condarczThe file '%s' already contains configuration information.
Remove the file to proceed.
Use `conda config --describe` to display default configuration.wc                ,    j                  |       d   S )Nrp   )r{   )rA   r   s    rH   <lambda>z execute_config.<locals>.<lambda>  s    ',,Q/0@A rJ   r   r   r      )
ParseErrorzinvalid yaml content:
%s)TFr   r   r   r   )CondaValueErrorz+Key '%s' is not a known sequence parameter.rN   zkey z should be a list, not z4Warning: '{}' already in '{}' list, moving to the {}topbottomr   )stdout_json_success)rc_pathr   r|   )ZrP   rM   ry   rh   r1   r   r   r   	common.ior   common.iteratorsr   rz   r   r   r   show_sourcesr}   r~   collect_allr_   r   r)   r   re   r
   showr   setr   rQ   r   getattrvaluesr   schemerC   r   validate_configurationdescriber{   r   r   r   r   r   validatevalidate_allsystemenvr:   r   write_defaultr	   openreadr   writeosr   existsr|   keysr   stdinr   update	Exceptionr   zipprependr   r   r  r`   r   rO   	__class____name__r9   insertr   r   remover   
remove_keyr   r   commonr  )6rT   rU   rM   rh   r   r   r   groupbyr   r   stderr_writejson_warningsjson_getsourcer  rb   reprsparamater_names	all_names
not_paramsr   r   r   ra   channelmultichannel_namer   r   r   r  fhr   	rc_configgrouped_paramaterssequence_parametersmap_parameterscontentparsedr   argr   r   r   arglistr  rO   badmessage_keymessagerA   r  r   r   r   s6                                                      @@@rH   rR   rR     sQ	   -AA#=7^,11L^,11LMH<<

 /6.A.A.C.I.I.K*FF FV+ #*%	& 	 E!(!4!4!6!<!<!> !\F23[/0R ! 5)*yy99"iiO//1I_-I>J06#:Xj=QQ  &557O3BCCS''3''CC<<

"*% !A% $%%6#7#>#>#@( LLW^^$4C8H8H7I"JJ(#$ &*0 899O7P7V7V7X-3)8 &x'CC-() "Q&(- .#$%7#8. )$%
 ;q>23&&(}} =="mmO//1I_-I>J06#:Xj=QQ  ||JJFUVd33D9V"& #.)L 	9 '' (HW( 
 TYYw/0, 	) ||"I"('' (9@9M9M9S9S9U( # JJFUVd33D9V"& #.) 	 467}}{{	  700*=G"G	))'?g )"wwy() V 	  '3 	02HH,./	0 
ww~~g'] 	7b,R06BI	7 	7 
	$+ 	7",R06BI	7 	7 	 A! -Z8'.N xx887vinn&67 	LCS)(]K	L zz!SYY^^,	D)'2FV$ T\\4;;7G "AW !	AIC/2cz#))C+T{KCj S	%9",	#))#..sB7&#..sB7BB62N8%ACG  w1*Wc:R:n..77'$sg5LSEQR(STTw4:4FcCi&0CPWW+uX >;B/Paa4i/PPGinCJ7XaaSWi7XXGinV4|| )!((1NN1S\4@C!	A"AJ XX '	TdI&' [[ +	TS$	*+  $C#$ 88'9%||/GmR qD D(-< W6 W:) )	0	7 	7
	7 	76  	D/87BCC	DB 0Q7Xsx   $d 
d&-d9d2ddd d-$d9$e(e )
e14e1
e6e6 d*-d69eee.)r<   r   returnr   )rT   r   rU   r   r>  r   )
r   r   r.   r   r}   zdict[str, Any]r   z	list[str]r>  r\   )r   r   r   r   r.   r   r>  r\   )r   r   r.   r   r>  r\   )r   str | os.PathLike | Pathr>  r   )r   r?  r.   r   r>  r\   )rT   ztuple[str, Any]r   r?  r>  r\   )*__doc__
__future__r   r}   r  r   argparser   collections.abcr   r   	itertoolsr   loggingr   os.pathr	   r
   pathlibr   textwrapr   typingr   r   r   r   r   rI   rW   re   r   r   r   r   r   r   r   r   r   r   rR   rs   rJ   rH   <module>rJ     s   
 #  	 
  -        EEHV.)X*C@ /	// 	/
 / 
/@606@8)UXLSrJ   