
    si.                       S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	J
r
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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%J&r&J'r'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0  \(       a  SSK1J2r2  \" \35      r4S.S jr5\ " SSSS9S/S0S jj5       r6\ Rn                  " SSS5      S1S j5       r8\Rr                  " S\Rt                  5      r;S2S jr<S2S jr=\ Rn                  " SSS5      S3S j5       r>S  r?S! r@\S" 5       rAS4S# jrBS$ rC\ " S%SS&S9S5S' j5       rD\ " S%SS(S9S6S) j5       rES* rFS+ rGS7S, jrHS8S- jrIg)9z.Common utilities for conda command line tools.    )annotationsN)	getLogger)dirnameexistsisdirisfilejoinnormcase)TYPE_CHECKING   )dals)CMD_LINE_SOURCECONFIGURATION_SOURCESENV_VARS_SOURCEEXPLICIT_MARKERPREFIX_MAGIC_FILE)contextenv_name)swallow_broken_pipe)expandpaths_equal)
deprecated)"DirectoryNotACondaEnvironmentErrorEnvironmentFileNotFound EnvironmentFileTypeMismatchErrorEnvironmentLocationNotFoundEnvironmentNotWritableErrorInvalidSpecOperationNotAllowed)CONDA_SESSION_SCHEMES)file_path_is_writable)	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+   3   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"   
exceptionsr0   name
_is_simplelenstr)argupdatespecr0   r3   s        r*   arg2specr:   B   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)r6   r"   )argsr7   s     r*   specs_from_argsr?   \   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_commentrE   o   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$ )Nr3   ccpc= z~= z~=   z5Overly complex 'Compatible release' spec not handled .z'No '.' in 'Compatible release' version  z.*z >=z,==)spec_patmatchrE   grouplowerreplace
startswithcountr   r	   rB   )rD   mr3   rG   rH   verver2s          r*   spec_from_linerY   s   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)verboserA   Tr/   zcould not parse 'z' in: )CondaFileIOError)gateways.connection.downloadr[   openstriprT   r   appendrY   r2   r0   OSErrorr]   )
urlr[   explicitpathspecsrD   r9   r0   er]   s
             r*   specs_from_urlrh      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)rB   ).0r9   namess     r*   	<genexpr>!names_in_specs.<locals>.<genexpr>   s     :EDzz|A%'Es   "%)any)rl   rf   s   ` r*   names_in_specsrp      s    :E:::r,   c                R    U (       a   SR                  SR                  U 5      5      $ g)Nz[{}]rJ   rM   )formatr	   )featuress    r*   disp_featuresrt      s     }}SXXh/00r,   c                    [        U 5        g r=   r#   )ds    r*   stdout_jsonrw      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_dumpr8   rw   )ry   kwargsresultrz   precs        r*   stdout_json_successr      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_enabledr2   r   r   )r   r   s     r*   check_non_adminr      s9    %$$XZZ4!
 	
 .8$r,   z25.9z#Use PrefixData.assert_environment()c                    [        U 5      (       a,  [        [        U [        5      5      (       d  [	        U 5      e U $ [        U 5      e)zVerifies the prefix is a valid conda environment.

:raises EnvironmentLocationNotFound: Non-existent path or not a directory.
:raises DirectoryNotACondaEnvironmentError: Directory is not a conda environment.
:returns: Valid prefix.
:rtype: str
)r   r   r	   r   r   r   r(   s    r*   validate_prefixr      sD     V}}d6#45664V<< 7
 M *&11r,   z Use PrefixData.assert_writable()c                    [        U [        5      n[        [        U5      5      (       a  [	        U5      (       a  U $ [        U 5      e)aE  Verifies the environment directory is writable by trying to access
the conda-meta/history file. If this file is not writable then we assume
the whole prefix is not writable and raise an exception.

:raises EnvironmentNotWritableError: Conda does not have permission to write to the prefix
:returns: Valid prefix.
:rtype: str
)r	   r   r   r   r!   r   )r)   	test_paths     r*   validate_prefix_is_writabler      s<     V./IWY  %:9%E%E
%f
--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r=   )r   r   r   r'   parent)rk   re   configs      r*   rm   )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 )NrJ   "zp
            #
            # To activate this environment, use
            #
            #     $ conda activate z
            #
            # To deactivate an active environment, use
            #
            #     $ conda deactivate
            )r   quietr;   r   print)env_name_or_prefixmessages     r*   print_activater   %  sZ    ==$$#$%7$8!:$ %7#7 8		
 	g ".=r,   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
rK   N)r5   r   plugin_managerget_environment_specifierr3   setvaluesr   )filesfile
file_typess      r*   &validate_environment_files_consistencyr   8  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://rK   r   r   rN   N)filename)rB   r   r    r   r   )r   
url_schemes     r*   validate_file_existsr   N  sl      q)!,JV(..2267	0	0(#(%x88 r,   )r)   r6   returnbool)F)r7   r6   r8   r   r   r6   )r>   zIterable[str]r   	list[str])rD   r6   r   r6   )rc   r6   r   r   )T)r   r6   )r)   r6   r   r6   )r   r   r   None)r   r6   )J__doc__
__future__r   reloggingr   os.pathr   r   r   r   r	   r
   typingr   
auxlib.ishr   base.constantsr   r   r   r   r   base.contextr   r   	common.ior   common.pathr   r   deprecationsr   r2   r   r   r   r   r   r   r   gateways.connection.sessionr    gateways.disk.testr!   models.match_specr"   	reportersr$   collections.abcr%   __name__logr+   r:   argumentr?   compileVERBOSErO   rE   rY   rh   rp   rt   rw   r   r   r   r   r   r   r   r    r,   r*   <module>r      s{   5 " 	   !   - + - %   @ 6 ) ( 

7

* VVV,1 -1 :: JJ'0 VVV, -:;  

  FF%JK L" FF%GH. I.*/Z&;,9r,   