
    <Bh                       S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJrJr  \" \5      rSrSrSS jrSS jrSS jrSS jrSS jr SS jr!SS jr"SS jr#\S 5       r$g)z0Backend logic implementation for `conda doctor`.    )annotationsN)	getLogger)Path)RequestException   )context)get_user_environments_txt_file)
CondaError)get_session)compute_sum   )CondaHealthCheckhookimplu   ✅u   ❌c                r   [        U 5      n [        [        5       5      nSS jn UR                  5       R                  5        H5  nUR	                  5       nU(       d  M  U" U [        U5      5      (       d  M5    g   g! [
        [        [        4 a$  n[        R                  U SU 35         SnAgSnAff = f)zEChecks whether the environment is listed in the environments.txt filec                N     U R                  U5      $ ! [         a    X:H  s $ f = f)N)samefileFileNotFoundError)path1path2s     Nlib/python3.13/site-packages/conda/plugins/subcommands/doctor/health_checks.pyr   %check_envs_txt_file.<locals>.samefile    s-    	">>%((  	">!	"s    $$Tz7 could not be accessed because of the following error: NF)r   r   r   r   returnbool)
r   r	   	read_text
splitlinesstripIsADirectoryErrorr   PermissionErrorloggererror)prefixenvs_txt_filer   linestripped_lineerrs         r   check_envs_txt_filer&      s    &\F79:M"	
!++-88:D JJLM}&$}2E!F!F ;  0/B 
o 88;u>	
 	
 
s)   6A= A= 8A= :A= =B6B11B6c                (    SnU R                  U5      $ )N)z.pycz.pyo)endswith)filenameexcluded_extensionss     r   excluded_files_checkr+   4   s    *011    c                x   0 n[        U 5      n U S-  R                  S5       H  n[        R                  " UR	                  5       5      R                  S/ 5       HY  n[        U5      (       a  M  X-  R                  5       (       a  M.  UR                  UR                  / 5      R                  U5        M[     M     U$ )z=Finds packages listed in conda-meta which have missing files.
conda-meta*.jsonfiles)r   globjsonloadsr   getr+   exists
setdefaultstemappend)r!   packages_with_missing_filesfile	file_names       r    find_packages_with_missing_filesr<   9   s    "$&\F,&,,X6DNN$4599'2FI )33+3355+66tyy"ELLYW G 7 '&r,   c           
        0 n[        U 5      n U S-  R                  S5       H  n [        R                  " UR	                  5       5      n US   nUS   nUR                  S	5      S
:w  a  MJ  U H  nUR                  S5      nUR                  S5      n	Ub  U	c  M-  X-  n
U
R                  5       (       d  MH   [        U
S5      nX:w  d  M\  UR                  UR                  / 5      R!                  U5        M     M     U$ ! [
         a(  n[        R                  SU SU S35         SnAGM
  SnAff = f! [         a     GM   f = f! [         a  n[        SU
 SU S35      eSnAff = f)zFinds altered packagesr.   r/   zCould not load the json file z! because of the following error: .N
paths_datapathspaths_version   _pathsha256_in_prefixsha256z%Could not generate checksum for file )r   r1   r2   r3   r   	Exceptionr   r    KeyErrorr4   is_filer   OSErrorr
   r6   r7   r8   )r!   altered_packagesr:   metadataexcr?   r@   pathrC   
old_sha256file_location
new_sha256r%   s                r   find_altered_packagesrQ   H   s   &\F,&,,X6	zz$.."23H	!,/Jw'E >>/*a/DHHW%E"45J}
 2"NM ((**(A
 ' ++DIIr:AA%H' % 7N I  	LL/v5VWZV[[\] 		  		$   ;M? K77:e1> sA   $C?
D47E?
D1	D,,D14
EE
E'E""E'c           	     0   [        U 5      nU(       ar  [        [         S35        UR                  5        HK  u  p2U(       a%  Sn[        U SU UR	                  U5       35        M1  [        U S[        U5       S35        MM     g [        [         S35        g )Nz Missing Files:

  :: 
z+ There are no packages with missing files.
)r<   printX_MARKitemsjoinlenOK_MARK)r!   verbosemissing_filespackage_name	delimiters        r   r^   r^   w   s    4V<M)*++8+>+>+@'L"	a	{9>>-3P2QRSb]);(<B?@ ,A 		EFGr,   c           	     2   [        U 5      nU(       as  [        [         S35        UR                  5        HL  u  p4U(       a&  Sn[        U SU UR	                  U5       S35        M2  [        U S[        U5       S35        MN     g [        [         S35        g )Nz Altered Files:
rS   rT   rV   rU   z+ There are no packages with altered files.
)rQ   rW   rX   rY   rZ   r[   r\   )r!   r]   rJ   r_   altered_filesr`   s         r   rb   rb      s    ,V4)*++;+A+A+C'L"	a	{9>>-3P2QQSTUb]);(<B?@ ,D 		EFGr,   c                n    [        U 5      (       a  [        [         S35        g [        [         S35        g )Nz9 The environment is listed in the environments.txt file.
z= The environment is not listed in the environments.txt file.
)r&   rW   r\   rX   )r!   r]   s     r   env_txt_checkrd      s-    6""	STUVWXr,   c                   [         R                  R                  5       S   n[        R                  " S5      nU(       d  g [        U5      R                  5       (       d  [        [         S35        g [        U5      n UR                  U5      nUR                  5         [        [         S35        g ! [        [        4 a  n[        [         SU S35         S nAg S nAff = f)Nr   REQUESTS_CA_BUNDLEzB Env var `REQUESTS_CA_BUNDLE` is pointing to a non existent file.
z$ `REQUESTS_CA_BUNDLE` was verified.
zC The following error occured while verifying `REQUESTS_CA_BUNDLE`: rV   )r   channel_aliasurlsosgetenvr   r5   rW   rX   r   r4   raise_for_statusr\   rI   r   )r!   r]   ca_bundle_test_urlrequests_ca_bundlesessionresponsees          r   requests_ca_bundle_checkrq      s     !..335a8#78$%,,..hYZ	
 01	{{#56H%%'WIBCD)* 	(]^_]``bc 	s   =3B1 1C CC c               #     #    [        S[        S9v   [        S[        S9v   [        S[        S9v   [        S[        S9v   g 7f)NzMissing Files)nameactionzAltered FileszEnvironment.txt File CheckzREQUESTS_CA_BUNDLE Check)r   r^   rb   rd   rq    r,   r   conda_health_checksrv      s@     

FF

FF
 <]
SS
'0H s   AA)r!   zstr | os.PathLike | Pathr   r   )r)   strr   r   )r!   z
str | Pathr   zdict[str, list[str]])r!   rw   r]   r   r   None)%__doc__
__future__r   r2   ri   loggingr   pathlibr   requests.exceptionsr   base.contextr   core.envs_managerr	   
exceptionsr
   gateways.connection.sessionr   gateways.disk.readr    r   r   __name__r   r\   rX   r&   r+   r<   rQ   r^   rb   rd   rq   rv   ru   r,   r   <module>r      s    7 "  	   0 $ @ % 7 . *	8	
	22
',^HHY0 
 
r,   