
    $TXgf                        d Z ddlZddlZddlmZmZmZ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 dd
lmZ ddlmZmZmZ ddlmZ ddlmZ  eddd      dddefd       Z eddd      ddefd       Zdede fdZ!d(dZ"d)dZ# ejH                  dejJ                        Z&d Z'd Z(d)dZ)d  Z*d! Z+ed"        Z,d*d#Z- eddd$      d*d%       Z.d& Z/d' Z0y)+z.Common utilities for conda command line tools.    N)isdirisfilejoinnormcase   )dals)contextenv_name)NULL)swallow_broken_pipe)paths_equal)
deprecated)
CondaError"DirectoryNotACondaEnvironmentErrorEnvironmentLocationNotFound)	MatchSpecrenderz25.3z25.9z)Use `conda.reporters.confirm_yn` instead.)addendumProceedyesnor   c                 L   ||v sJ |       |t         u rt        j                  s|rddlm}  |       g }|D ]4  }||k(  r|j                  d|d    d       !|j                  |d          6 dj                  | dj                  |            } |D ci c]  }||d   fD ]  }||  }}}||d<   	 t        j                  j                  |        t        j                  j                          	 t        j                  j                         j                         j                         }	|	|vrt%        d
|	        nBt        j                  j                  d       t        j                  j                          ||	   S c c}}w # t         $ r}
t#        d	|
       d }
~
ww xY w)Nr   
DryRunExit[r   ]z	{} ({})? / zcannot read from stdin: zInvalid choice: 
)r   r	   dry_run
exceptionsr   appendformatr   sysstdoutwriteflushstdinreadlinestriplowerOSErrorr   print)messagechoicesdefaultr"   r   optionsoptionchoicealtuser_choicees              0lib/python3.12/site-packages/conda/cli/common.pyconfirmr:      s    g&w&4GOO+lGWNNQvayk+,NN6!9%	 
   #((7*;<G)0PvVVAY<OSsF{<OsGPGBK


!

	=)),,.446<<>K g%$[M23JJT"JJ;''  Q  	=7s;<<	=s   F1:F 	F#FF#c                     |t         u rt        j                  s|rddlm}  |       t        j
                  ry	 t        | d||      }|dk(  rddlm}  |d	      y# t        $ r ddlm}  |d      w xY w)
Nr   r   Tr   )r0   r1   r2   r"   )CondaSystemExitz
Operation aborted.  Exiting.r   zExiting.)	r   r	   r"   r#   r   
always_yesr:   KeyboardInterruptr<   )r0   r2   r"   r   r5   r<   s         r9   
confirm_ynr?   =   s     	4GOO+l@]GW
 ~0j))  @0>??@s   A A5prefixreturnc                     t         j                  yt        | t         j                        xs. t        |       t        t	        t         j                              k(  S )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
   r@   s    r9   is_active_prefixrE   X   sK     $FG112 	IFx1F1F(GHH    c           
          	 t        |       }|j                  }|j	                         s0|r.ddlm}  |d|dt        |        d| dt        |             t        |      S #  ddlm}  |d|        xY w)Nr   CondaValueErrorzinvalid package specification: zHversion specifications not allowed with 'update'; use
    conda update  <z  or
    conda install )r   r#   rI   name
_is_simplelenstr)argjsonupdatespecrI   rK   s         r9   arg2specrS   g   s    G~ 99D??0!!%aCz\ 2 3!!$Qs4ykM 24
 	
 t9G0 ?uEFFs   A$ $A7c                 B    | D cg c]  }t        ||       c}S c c}w )N)rP   )rS   )argsrP   rO   s      r9   specs_from_argsrV   |   s!    045HSt$555s   a  
    (?P<name>[^=<>!\s]+)                # package name
    \s*                                 # ignore spaces
    (
        (?P<cc>=[^=]+(=[^=]+)?)         # conda constraint
        |
        (?P<pc>(?:[=!]=|[><]=?|~=).+)   # new pip-style constraints
    )?$
    c                 F    | j                  d      d   j                         S )N#r   )splitrstrip)lines    r9   strip_commentr\      s    ::c?1$$&&rF   c                 L   t         j                  t        |             }|y |j                  d      j	                         |j                  d      |j                  d      }}}|r||j                  dd      z   S |r|j                  d      r|j                  d      dk(  s
J d	|         |j                  d
      s
J d|         |j                  dd      }d
j                  |j                  d
      d d       dz   }|dz   |z   dz   |z   S |dz   |j                  dd      z   S |S )NrK   ccpc= z~= z~=   z5Overly complex 'Compatible release' spec not handled .z'No '.' in 'Compatible release' version r    z.*z >=z,==)
spec_patmatchr\   groupr-   replace
startswithcountr   rY   )r[   mrK   r^   r_   verver2s          r9   spec_from_linern      s#   }T*+AyGGFO))+QWWT]AGGDMb"D	bjjc***	==!#NFtfMN#88C=R$KD6"RR=**UB'C88CIIcN3B/047D%<#%-44#:

3 333rF   c                    ddl m} d} || d      5 }g }	 t        |      D ]s  }|j                         }|r|j	                  d      r'|dk(  rd}|r|j                  |       Bt        |      }|ddlm}  |d	| d
|        |j                  |       u 	 d d d        |S # t        $ r}	ddlm
}
  |
||	      d }	~	ww xY w# 1 sw Y   S xY w)Nr   )TmpDownloadF)verboserX   z	@EXPLICITTrH   zcould not parse 'z' in: )CondaFileIOError)gateways.connection.downloadrp   openr,   ri   r$   rn   r#   rI   r.   rr   )urlrP   rp   explicitpathspecsr[   rR   rI   r8   rr   s              r9   specs_from_urlry      s    :H	S%	(D	,T
zz|ts3;&#HLL&%d+<<),=dV6#*OPPT" # 
), L	  	,5"4++	,% 
), Ls)   CBB##	C ,B;;C  CCc                 ,     t         fd|D              S )Nc              3   H   K   | ]  }|j                         d    v   yw)r   N)rY   ).0rR   namess     r9   	<genexpr>z!names_in_specs.<locals>.<genexpr>   s!     :EDtzz|A%'Es   ")any)r}   rx   s   ` r9   names_in_specsr      s    :E:::rF   c                 H    | r dj                  dj                  |             S y)Nz[{}]ra   r    )r%   r   )featuress    r9   disp_featuresr      s     }}SXXh/00rF   c                     t        |        y )Nr   )ds    r9   stdout_jsonr      s	    
1IrF   c                 *   d| i}|j                  dd       }|rUd|v r$|d   D cg c]  }|j                          c}|d<   d|v r$|d   D cg c]  }|j                          c}|d<   ||d<   |j                  |       t        |       y c c}w c c}w )NsuccessactionsLINKUNLINK)popdist_fields_dumprQ   r   )r   kwargsresultr   precs        r9   stdout_json_successr      s    !FjjD)GWCJ6?S?4t446?SGFOwELXEV WEVT!6!6!8EV WGH#y
MM& T Ws   BBz7Use `conda.reporters.render(style='env_list')` instead.c                      t        | d|       y )N	envs_list)styleoutputr   )known_conda_prefixesr   s     r9   print_envs_listr      s     {6BrF   c                  n    ddl m}  t        j                  s |        sddlm}  |t        d            y y )Nr   )is_admin)OperationNotAllowedz
            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     r9   check_non_adminr      s7    %$$XZ4!
 	
 .8$rF   c                 t    t        |       r#t        t        | dd            st        |       | S t	        |       )a  Verifies 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
    z
conda-metahistory)r   r   r   r   r   rD   s    r9   validate_prefixr      s;     V}d6<;<4V<< M *&11rF   )FF)F)T)1__doc__rer&   os.pathr   r   r   r   
auxlib.ishr   base.contextr	   r
   common.constantsr   	common.ior   common.pathr   deprecationsr   r#   r   r   r   models.match_specr   	reportersr   r:   r?   rN   boolrE   rS   rV   compileVERBOSEre   r\   rn   ry   r   r   r   r   r   r   r    rF   r9   <module>r      s0   5 	 
 1 1  , # + % % 
 *  

8
 }eT (
(@ 

8
 !% 
,S T *6 2:: JJ',:;  
 

F
C
C
 rF   