+
    :1j                    >   R t ^ RIHt ^ RIt^ RIHtHtHt ^ RIH	t	 ^ RI
HtHtHtHtHt ^ RIHt ^RIHt ^RIHt ^R	IHtHtHt ^R
IHt ^RIHt ^RIHt ]'       d   ^ RI H!t! ]	! ]"4      t#RR R llt$R R lt%R R lt&R R lt'R R lt(RR R llt)R R lt*R# )z&Tools for managing conda environments.)annotationsN)EACCESENOENTEROFS)	getLogger)dirnameisdirisfilejoinnormpath)TYPE_CHECKING)context)is_admin)ensure_text_typeon_win	open_utf8)expand)yield_lines)
PrefixData)Iteratorc                    V ^8  d   QhRRRR/# )   userhomestrreturn )formats   "7lib/python3.14/site-packages/conda/core/envs_manager.py__annotate__r      s     	@ 	@S 	@3 	@    c                .    \        \        V RR4      4      # )z
Gets the path to the user's environments.txt file.

:param userhome: The home directory of the user.
:type userhome: str
:return: Path to the environments.txt file.
:rtype: str
z.condazenvironments.txt)r   r
   )r   s   &r   get_user_environments_txt_filer!      s     $x+=>??r   c                    V ^8  d   QhRRRR/# r   locationr   r   Noner   )r   s   "r   r   r   &   s     8 83 84 8r   c                L   \         P                  '       g   R# \        4       p\        V 4      p \	        V 4      p \
        P                  ! V4       RT 9   g   RT 9   g   T\
        P                  8X  d   R# T \        T4      9   d   R# \
        P                  P	                  T4      p \
        P                  ! TRR7        \        TR4      ;_uu_ 4       pTP                  \        T 4      4       TP                  R4       RRR4       R#     L; i  \         d#   p\        P                  RTT4        Rp?R# Rp?ii ; i  + '       g   i     R# ; i  \         dD   pTP                   \"        \$        \&        39   d   \        P                  R	T T4        Rp?R# h Rp?ii ; i)
z
Registers an environment by adding it to environments.txt file.

:param location: The file path of the environment to register.
:type location: str
:return: None
Nplacehold_pl	skeleton_T)exist_okz?Unable to register environment. Could not create %s. Reason: %sa
zlUnable to register environment. Path not writable or missing.
  environment location: %s
  registry file: %s)r   register_envsr!   r   r   osmakedirsdevnullr   pathOSErrorlogwarningr   writer   errnor   r   r   )r$   user_environments_txt_filefolderuser_environments_txt_directoryexcfhes   &      r   register_envr<   &   s_       !?!A!HXF
F
 	("("%3 	;9::&(ggoo6P&Q#
3dC13772HH%h/0HHTN 877"  M+	

 	 877  
77vuf--KK& *  
s_   D
 'D  E ,E E 
DD>D99D>E	E E F# 7FFF#c                    V ^8  d   QhRRRR/# r#   r   )r   s   "r   r   r   a   s     H HS HT Hr   c                V   \        V 4      '       d   \        V R4      p\        V4      '       dg   \        ;QJ d(    . R \        P                  ! V4       4       F  NK  	  5M!! R \        P                  ! V4       4       4      p\        V4      ^8  d   R# \        \        4       V 4       R# )a  
Unregisters an environment by removing its entry from the environments.txt file if certain conditions are met.

The environment is only unregistered if its associated 'conda-meta' directory exists and contains no significant files other than 'history'. If these conditions are met, the environment's path is removed from environments.txt.

:param location: The file path of the environment to unregister.
:type location: str
:return: None
z
conda-metac              3  8   "   T F  qP                   x  K  	  R # 5iN)name.0entrys   & r   	<genexpr>!unregister_env.<locals>.<genexpr>n   s     %S>RUjj>R   N)r   r
   tupler-   scandirlen_clean_environments_txtr!   )r$   meta_dirmeta_dir_contentss   &  r   unregister_envrN   a   st     X,/?? %%Sbjj>R%S%Sbjj>R%S S$%) :<hGr   c                   V ^8  d   QhRR/# )r   r   	list[str]r   )r   s   "r   r   r   w   s     +! +! +!r   c                   a \        4       o\        4       '       d   \        '       dj   \        \	        R4      4      p \
        ;QJ d(    . R \        P                  ! V 4       4       F  NK  	  5M!! R \        P                  ! V 4       4       4      pM]^ RIH	p \
        ;QJ d    . R V! 4        4       F  NK  	  5M! R V! 4        4       4      ;'       g    \	        R4      3pM\	        R4      3p\        RV4       F<  p\        V4      p\        V4      '       g   K!   SP                  \        V4      4       K>  	  R \$        P&                   4       pSP                  V3R lR	 V 4        4       4       SP)                  \$        P*                  4       \-        S4      #   \         d    \         P#                  RT4        K  i ; i)
zy
Lists all known conda environment prefixes.

:return: A list of all known conda environment prefixes.
:rtype: List[str]
~c              3  8   "   T F  qP                   x  K  	  R # 5ir@   )r0   rB   s   & r   rE   *list_all_known_prefixes.<locals>.<genexpr>   s     Q8Pu

8PrG   )getpwallc              3  8   "   T F  qP                   x  K  	  R # 5ir@   )pw_dir)rC   pwentrys   & r   rE   rT      s     Ij7jrG   NzUnable to access %sc              3  L   "   T F  p\        V4      '       g   K  Vx  K  	  R # 5ir@   )r   )rC   envs_dirs   & r   rE   rT      s     O*;huX*;s   $
$c              3  |   <"   T F1  pVS9  g   K  \        V4      P                  4       '       g   K-  Vx  K3  	  R # 5ir@   r   is_environment)rC   r0   all_env_pathss   & r   rE   rT      s@      
D }$	 	 *4D)9)H)H)J	 	
   	<<
<c              3  r   "   T F-  p\         P                  ! V4       F  q"P                  x  K  	  K/  	  R # 5ir@   )r-   rI   r0   )rC   rZ   rD   s   &  r   rE   rT      s'      
'08bjj>RUJJ>RJys   57)setr   r   r   r   rH   r-   rI   pwdrU   filterr!   r	   updaterK   PermissionErrorr2   r3   r   	envs_dirsaddroot_prefixsorted)home_dir_dirsearch_dirsrU   home_direnvironments_txt_filerf   r^   s         @r   list_all_known_prefixesrn   w   s`    EMzz6"6#;/L%Q

<8PQ%%Q

<8PQQK$%IhjI%%IhjII  sNK c{n4- >x H'((J $$%<=R%ST . P'*;*;OI 
'0
  g))*-   # J13HIJs   F!GGc                    V ^8  d   QhRRRR/# )r   specr   r   zIterator[tuple[str, tuple]]r   )r   s   "r   r   r      s     & &S &%@ &r   c              #     "   \        4        F5  p\        \        V4      P                  V 4      4      pV'       g   K0  W3x  K7  	  R# 5i)z
Queries all known prefixes for a given specification.

:param spec: The specification to query for.
:type spec: str
:return: An iterator of tuples containing the prefix and the query results.
:rtype: Iterator[Tuple[str, Tuple]]
N)rn   rH   r   query)rp   prefixprefix_recss   &  r   query_all_prefixesru      s<      *+Jv.44T:;;%% ,s
   6AAc               $    V ^8  d   QhRRRRRR/# )r   rm   r   remove_locationz
str | Noner   ztuple[str, ...]r   )r   s   "r   r   r      s&     * *** *r   c                  a \        V 4      '       g   R# S'       d   \        S4      o\        \        V 4      4      p\        ;QJ d    . V3R lV 4       F  NK  	  5M! V3R lV 4       4      pW28w  d   \	        W4       V# )aM  
Cleans the environments.txt file by removing specified locations.

:param environments_txt_file: The file path of environments.txt.
:param remove_location: Optional location to remove from the file.
:type environments_txt_file: str
:type remove_location: Optional[str]
:return: A tuple of the cleaned lines.
:rtype: Tuple[str, ...]
c              3  |   <"   T F1  pVS8w  g   K  \        V4      P                  4       '       g   K-  Vx  K3  	  R # 5ir@   r\   )rC   rs   rw   s   & r   rE   *_clean_environments_txt.<locals>.<genexpr>   s8      +,F_$ 	)3F);)J)J)L 	,r_   r   )r	   r   rH   r   _rewrite_environments_txt)rm   rw   environments_txt_linesenvironments_txt_lines_cleaneds   &f  r   rK   rK      sv     '((	"?3";/D#EF%*U +,+UU +,+ &"
 &?!"7X))r   c               $    V ^8  d   QhRRRRRR/# )r   rm   r   prefixesrP   r   r%   r   )r   s   "r   r   r      s"     * *S *I *RV *r   c                Z    \        V R4      ;_uu_ 4       pVP                  RP                  V4      4       VP                  R4       RRR4       R#   + '       g   i     R# ; i  \         d:   p\        P                  RT 4       \        P                  RTRR7        Rp?R# Rp?ii ; i)a  
Rewrites the environments.txt file with the specified prefixes.

:param environments_txt_file: The file path of environments.txt.
:param prefixes: List of prefixes to write into the file.
:type environments_txt_file: str
:type prefixes: List[str]
:return: None
wr+   NzFile not cleaned: %sz%rT)exc_info)r   r4   r
   r1   r2   infodebug)rm   r   r:   r;   s   &&  r   r{   r{      s|    *,c22bHHTYYx()HHTN 3222  *')>?		$D	))*s4   A& 2AA& A#	A& #A& &B*1.B%%B*)rR   r@   )+__doc__
__future__r   r-   r5   r   r   r   loggingr   os.pathr   r   r	   r
   r   typingr   base.contextr   
common._osr   common.compatr   r   r   common.pathr   gateways.disk.readr   prefix_datar   collections.abcr   __name__r2   r!   r<   rN   rn   ru   rK   r{   r   r   r   <module>r      sn    - " 	 ' '  : :   " ! ? ?   , #(	@8vH,+!\&*<*r   