
    \Zif+                    H   S r SSKJr  SSKrSSKJr  SSKJrJr  SSK	J
r
  SSKJr  SS	KJrJrJrJr  SS
KJrJr  SSKJr  SSKJrJr  SSKJr  SSKJrJrJrJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&  \
(       a  SSK'J(r(  \" \)5      r*S)S jr+\" SSSS9S*S+S jj5       r,\RZ                  " SSS5      S,S j5       r.\R^                  " S\R`                  5      r1S-S jr2S-S jr3\RZ                  " SSS5      S.S j5       r4S r5S  r6\S! 5       r7S/S" jr8S# r9S$ r:S% r;S0S& jr<S1S' jr=S2S( jr>g)3z.Common utilities for conda command line tools.    )annotationsN)	getLogger)existsnormcase)TYPE_CHECKING   )dals)CMD_LINE_SOURCECONFIGURATION_SOURCESENV_VARS_SOURCEEXPLICIT_MARKER)contextenv_name)swallow_broken_pipe)expandpaths_equal)
deprecated)EnvironmentFileNotFound EnvironmentFileTypeMismatchErrorInvalidSpecOperationNotAllowed)CONDA_SESSION_SCHEMES)	MatchSpecrender)Iterablec                    [         R                  c  g[        U [         R                  5      =(       d.    [        U 5      [        [	        [         R                  5      5      :H  $ )z
Determines whether the args we pass in are pointing to the active prefix.
Can be used a validation step to make sure operations are not being
performed on the active prefix.
F)r   active_prefixr   r   r   )prefixs    0lib/python3.13/site-packages/conda/cli/common.pyis_active_prefixr!   *   sK     $FG112 	IFx1F1F(GHH    z26.3z26.9z(Use `spec = str(MatchSpec(arg))` instead)addendumc           
         [        U 5      nUR                  nUR	                  5       (       d5  U(       a.  SSKJn  U" SUS[        U 5       3 SU S[        U5       3 35      e[        U5      $ !   SSKJn  U" SU  35      e= f)Nr   CondaValueErrorzinvalid package specification: zHversion specifications not allowed with 'update'; use
    conda update  <z  or
    conda install )r   
exceptionsr&   name
_is_simplelenstr)argupdatespecr&   r)   s        r    arg2specr0   9   s    G~ 99D??0!!%aCz\ 2 3!!$Qs4ykM 24
 	
 t9G0 ?uEFFs   A. .Bjsonc                V    U  Vs/ s H  n[        [        U5      5      PM     sn$ s  snf N)r,   r   )argsr-   s     r    specs_from_argsr5   S   s#    +/04CC	#4000s   &a  
    (?P<name>[^=<>!\s]+)                # package name
    \s*                                 # ignore spaces
    (
        (?P<cc>=[^=]+(=[^=]+)?)         # conda constraint
        |
        (?P<pc>(?:[=!]=|[><]=?|~=).+)   # new pip-style constraints
    )?$
    c                F    U R                  S5      S   R                  5       $ )N#r   )splitrstrip)lines    r    strip_commentr;   f   s    ::c?1$$&&r"   c                   [         R                  [        U 5      5      nUc  g UR                  S5      R	                  5       UR                  S5      UR                  S5      pCnU(       a  X#R                  SS5      -   $ U(       a  UR                  S5      (       a  UR                  S5      S:  a  [        S	U  S
35      eUR                  S
5      (       d  [        SU  35      eUR                  SS5      nS
R                  UR                  S
5      S S 5      S-   nUS-   U-   S-   U-   $ US-   UR                  SS5      -   $ U$ )Nr)   ccpc= z~= z~=   z5Overly complex 'Compatible release' spec not handled .z'No '.' in 'Compatible release' version  z.*z >=z,==)spec_patmatchr;   grouplowerreplace
startswithcountr   joinr8   )r:   mr)   r=   r>   verver2s          r    spec_from_linerP   j   s(   }T*+AyGGFO))+QWWT]AGGDMbD	jjc***	==xx~!!KD6QRS  88C==!$KD6"RSS**UB'C88CIIcN3B/047D%<#%-44#:

3 333r"   c                   SSK Jn  SnU" U SS9 n/ n [        U5       H  nUR                  5       nU(       a  UR	                  S5      (       a  M2  U[
        :X  a  SnU(       a  UR                  U5        MX  [        U5      nUc  SSKJ	n  U" SU S	U  35      eUR                  U5        M      S S S 5        U$ ! [         a  nSS
KJn	  U	" X85      eS nAff = f! , (       d  f       W$ = f)Nr   )TmpDownloadF)verboser7   Tr%   zcould not parse 'z' in: )CondaFileIOError)gateways.connection.downloadrR   openstriprJ   r   appendrP   r(   r&   OSErrorrT   )
urlrR   explicitpathspecsr:   r/   r&   erT   s
             r    specs_from_urlr_      s    :H	S%	(D	,T
zz|ts33?*#HLL&%d+<<),=dV6#*OPPT" # 
), L	  	,5"4++	,% 
)	(, Ls)   CBB99
CCCC
C(c                .   ^  [        U 4S jU 5       5      $ )Nc              3  N   >#    U  H  oR                  5       S    T;   v   M     g7f)r   N)r8   ).0r/   namess     r    	<genexpr>!names_in_specs.<locals>.<genexpr>   s     :EDzz|A%'Es   "%)any)rc   r]   s   ` r    names_in_specsrg      s    :E:::r"   c                R    U (       a   SR                  SR                  U 5      5      $ g)Nz[{}]r@   rC   )formatrL   )featuress    r    disp_featuresrk      s     }}SXXh/00r"   c                    [        U 5        g r3   r   )ds    r    stdout_jsonrn      s	    
1Ir"   c                B   SU 0nUR                  SS 5      nU(       a\  SU;   a&  US    Vs/ s H  oDR                  5       PM     snUS'   SU;   a&  US    Vs/ s H  oDR                  5       PM     snUS'   X2S'   UR                  U5        [        U5        g s  snf s  snf )NsuccessactionsLINKUNLINK)popdist_fields_dumpr.   rn   )rp   kwargsresultrq   precs        r    stdout_json_successry      s    !FjjD)GWCJ6?S?4446?SGFOwELXEV WEVT!6!6!8EV WGH#y
MM& T Ws   BBc                     SSK Jn   [        R                  (       d$  U " 5       (       d  SSKJn  U" [        S5      5      eg g )Nr   )is_admin)r   z
            The create, install, update, and remove operations have been disabled
            on your system for non-privileged users.
        )
common._osr{   r   non_admin_enabledr(   r   r	   )r{   r   s     r    check_non_adminr~      s9    %$$XZZ4!
 	
 .8$r"   c                    [         R                  [         R                  " 5       :w  Ga1  [         R                  " 5       n U R	                  [
        0 5      R	                  S5      [         R                  :X  a  gU R	                  [        0 5      R	                  S5      [         R                  :X  a  g[        [         R                  [         R                  5      (       d~  [        S U R                  5        5       0 5      nUR	                  S5      [         R                  :X  a9  [        S[         R                   S[         R                   S35      n[        U5      eggg)a?  Validates that the configured subdir is ok. A subdir that is different from
the native system is only allowed if it comes from the global configuration, or
from an environment variable.

:raises OperationNotAllowed: Active environment is not allowed to request
                             non-native platform packages
subdirc              3     #    U  H@  u  pU[         ;  d  M  [        [        R                  UR                  5      (       d  M<  Uv   MB     g 7fr3   )r   r   r   r   parent)rb   r\   configs      r    rd   )validate_subdir_config.<locals>.<genexpr>   s?      (?#88  $G$9$94;;G F(?s   A
'A
	A
z7
                    Active environment configuration (zF) is
                    implicitly requesting a non-native platform (z).
                    Please deactivate first or explicitly request the platform via
                    the --platform=[value] command line flag.
                    N)r   r   _native_subdircollect_allgetr
   r   r   r   root_prefixnextitemsr	   r   )context_sourcesactive_env_configmsgs      r    validate_subdir_configr      s(    ~~//11
 "--/377AW^^S  "599(Cw~~U W22G4G4GHH $(7(=(=(? ! !$$X.'..@ 77>7L7L6M NBBI..AQ R *#.. A I 2r"   c                    [         R                  (       d=  [         R                  (       d'  SU ;   a  SU  S3n [        SU  S35      n[	        U5        g g g )Nr@   "zp
            #
            # To activate this environment, use
            #
            #     $ conda activate z
            #
            # To deactivate an active environment, use
            #
            #     $ conda deactivate
            )r   quietr1   r	   print)env_name_or_prefixmessages     r    print_activater      sZ    ==$$#$%7$8!:$ %7#7 8		
 	g ".=r"   c                P    [         R                  R                  U [         R                  S9nUR	                  U 5      R
                  nUR                  c  UR                  b  UR                  UR                  4$  g! [         a  n[        R                  USS9   SnAgSnAff = f)zf
Get name and prefix from an environment spec file.

Intentionally swallows all errors and logs them.
)sourcer)   NT)exc_info)NN)r   plugin_managerget_environment_specifierenvironment_specifierenvironment_specenvr)   r   	Exceptionloginfo)file	spec_hookr   excs       r    get_name_prefix_from_env_filer     s    	%**DD.. E 
	 ((.22883::#988SZZ'' $:
   %t$%s   A8A= =
B%B  B%c                   U (       a  [        U 5      S::  a  gU  Vs0 s H-  nU[        R                  R                  U5      R                  _M/     nn[        [        UR                  5       5      5      S:  a  [        U5      egs  snf )a  Validates that all the provided environment files are of the same format type.

This function checks if all provided environment files are of the same format type
using the conda plugin system's environment specifiers. It prevents mixing different
environment file formats (e.g., YAML, explicit package lists, requirements.txt).

:raises EnvironmentFileTypeMismatchError: When files with different formats are found
rA   N)r+   r   r   r   r)   setvaluesr   )filesr   
file_typess      r    &validate_environment_files_consistencyr   !  s     CJ!O
 D 	g$$>>tDIII  
 3z  "#$q(.z:: )s   4Bc                    U R                  SS5      S   nUS:X  a  [        U R                  SS5      S   5      n OU[        ;  a  [        U 5      n Og[        U 5      (       d	  [	        U S9eg)aT  
Validate the existence of an environment file.

This function checks if the given ``filename`` exists as an environment file.
If the `filename` has a URL scheme supported by ``CONDA_SESSION_SCHEMES``,
it assumes the file is accessible and returns without further validation.
Otherwise, it expands the given path and verifies its existence. If the file
does not exist, an ``EnvironmentFileNotFound`` exception is raised.

Parameters:
    filename (str): The path or URL of the environment file to validate.

Raises:
    EnvironmentFileNotFound: If the file does not exist and is not a valid URL.
z://rA   r   r   rD   N)filename)r8   r   r   r   r   )r   
url_schemes     r    validate_file_existsr   7  sl      q)!,JV(..2267	0	0(#(%x88 r"   )r   r,   returnbool)F)r-   r,   r.   r   r   r,   )r4   zIterable[str]r   	list[str])r:   r,   r   r,   )rZ   r,   r   r   )T)r   r,   r   ztuple[str | None, str | None])r   r   r   None)r   r,   )?__doc__
__future__r   reloggingr   os.pathr   r   typingr   
auxlib.ishr	   base.constantsr
   r   r   r   base.contextr   r   	common.ior   common.pathr   r   deprecationsr   r(   r   r   r   r   gateways.connection.sessionr   models.match_specr   	reportersr   collections.abcr   __name__r   r!   r0   argumentr5   compileVERBOSErE   r;   rP   r_   rg   rk   rn   ry   r~   r   r   r   r   r    r"   r    <module>r      s5   5 " 	  !   - + - %  @ ) ( 

7

* VVV,1 -1 :: JJ'0 VVV, -:;  

 */Z&(;,9r"   