Ë
    ®Ó^jº  ã            	       ó  — U d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZ dd	lmZ e G d
„ d«      «       Ze G d„ d«      «       Zeegedz  f   Zdededededz  fd„Zdededz  dedz  fd„Zdededz  fd„Zdededz  fd„Zdededz  fd„Zdedededz  fd„Zdededz  fd„Zdededz  fd„Zdededz  fd„Z eefZ!e"edf   e#d <   e fZ$e"edf   e#d!<   ded"e"edf   dedz  fd#„Z%y)$a¬  Composable search steps for locating NVIDIA libraries.

Each find step is a callable with signature::

    (SearchContext) -> FindResult | None

Find steps locate a library file on disk without loading it.  The
orchestrator in :mod:`load_nvidia_dynamic_lib` handles loading, the
already-loaded check, and dependency resolution.

Step sequences are defined per search strategy so that adding a new
step or strategy only requires adding a function and a tuple entry.

This module is intentionally platform-agnostic: it does not branch on the
current operating system. Platform differences are routed through the
:data:`~cuda.pathfinder._dynamic_libs.search_platform.PLATFORM` instance.
é    N)ÚCallable)Ú	dataclassÚfield)ÚNoReturnÚcast)ÚLibDescriptor)ÚDynamicLibNotFoundError)ÚPLATFORMÚSearchPlatform)Úget_cuda_path_or_homec                   ó&   — e Zd ZU dZeed<   eed<   y)Ú
FindResultz0A library file located on disk (not yet loaded).Úabs_pathÚ	found_viaN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__© ó    úu/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/cuda/pathfinder/_dynamic_libs/search_steps.pyr   r   &   s   … á:àƒMØ„Nr   r   c                   ó¦   — e Zd ZU dZeed<   eZeed<    e	e
¬«      Ze
e   ed<    e	e
¬«      Ze
e   ed<   edefd„«       Zedefd	„«       Zdefd
„Zy)ÚSearchContextz4Mutable state accumulated during the search cascade.ÚdescÚplatform)Údefault_factoryÚerror_messagesÚattachmentsÚreturnc                 ó.   — | j                   j                  S ©N)r   Úname©Úselfs    r   ÚlibnamezSearchContext.libname7   s   € à�y‰y�~‰~Ðr   c                 óh   — t        t        | j                  j                  | j                  «      «      S r#   )r   r   r   Úlib_searched_forr'   r%   s    r   r)   zSearchContext.lib_searched_for;   s"   € ä”C˜Ÿ™×7Ñ7¸¿¹ÓEÓFÐFr   c                 óª   — dj                  | j                  «      }dj                  | j                  «      }t        d| j                  › d|› d|› �«      ‚)Nz, ú
zFailure finding "z": )Újoinr   r    r	   r)   )r&   ÚerrÚatts      r   Úraise_not_foundzSearchContext.raise_not_found?   sV   € Ø�i‰i˜×+Ñ+Ó,ˆØ�i‰i˜×(Ñ(Ó)ˆÜ%Ð(9¸$×:OÑ:OÐ9PÐPSÐTWÐSXÐXZÐ[^ÐZ_Ð&`ÓaÐar   N)r   r   r   r   r   r   r
   r   r   r   Úlistr   r   r    Úpropertyr'   r)   r   r/   r   r   r   r   r   .   s€   … á>à
ÓØ'€HˆnÓ'Ù %°dÔ ;€N�D˜‘IÓ;Ù"°4Ô8€K��c‘Ó8àð˜ò ó ðð ðG #ò Gó ðGðb ô br   r   r   r   Úanchor_pointr!   c           	      ó:  — |j                  | «      }|D ]…  }t        t        j                  t        j                  j                  ||«      «      «      D ]D  }t        j                  j                  |«      sŒ#t        j                  j                  |«      c c S  Œ‡ y)zVFind the library directory under *anchor_point* using the descriptor's relative paths.N)Úanchor_rel_dirsÚsortedÚglobÚosÚpathr,   ÚisdirÚnormpath)r   r   r2   Úrel_dirsÚrel_pathÚdirnames         r   Ú_find_lib_dir_using_anchorr>   I   sw   € à×'Ñ'¨Ó-€HØò 1ˆÜœdŸi™i¬¯©¯©°\À8Ó(LÓMÓNò 	1ˆGÜ�w‰w�}‰}˜WÕ%Ü—w‘w×'Ñ'¨Ó0Ô0ñ	1ð1ð r   ÚctxÚlib_dirc           
      ó¸   — |€yt        t        dz  | j                  j                  || j                  | j
                  | j                  | j                  «      «      S )z0Find a library file in a resolved lib directory.N)r   r   r   Úfind_in_lib_dirr'   r)   r   r    )r?   r@   s     r   Ú_find_using_lib_dirrC   S   sS   € à€ØÜÜˆd‰
Ø�‰×$Ñ$ØØ�K‰KØ× Ñ Ø×ÑØ�O‰Oó	
ó	ð 	r   Úresolved_lib_pathc                 óŠ  — t         j                  j                  | «      }t         j                  j                  |«      }|dv r�t         j                  j                  |«      }t         j                  j                  |«      }t         j                  j                  |«      dk(  rt         j                  j                  |«      S |S y)zñDerive CTK root from Linux canary path.

    Supports:
    - ``$CTK_ROOT/lib64/libfoo.so.*``
    - ``$CTK_ROOT/lib/libfoo.so.*``
    - ``$CTK_ROOT/targets/<triple>/lib64/libfoo.so.*``
    - ``$CTK_ROOT/targets/<triple>/lib/libfoo.so.*``
    )Úlib64ÚlibÚtargetsN)r7   r8   r=   Úbasename)rD   r@   rI   ÚparentÚgrandparents        r   Ú_derive_ctk_root_linuxrL   c   sŠ   € ô �g‰g�o‰oÐ/Ó0€GÜ�w‰w×Ñ Ó(€HØÐ#Ñ#Ü—‘—‘ Ó)ˆÜ—g‘g—o‘o fÓ-ˆÜ�7‰7×Ñ˜KÓ(¨IÒ5Ü—7‘7—?‘? ;Ó/Ð/ØˆØr   c                 ó,  — ddl }|j                  | «      }|j                  |«      j                  «       }|dk(  rE|j                  |«      }|j                  |«      j                  «       dk(  r|j                  |«      S y|dk(  r|j                  |«      S y)zŸDerive CTK root from Windows canary path.

    Supports:
    - ``$CTK_ROOT/bin/x64/foo.dll`` (CTK 13 style)
    - ``$CTK_ROOT/bin/foo.dll`` (CTK 12 style)
    r   NÚx64Úbin)Úntpathr=   rI   Úlower)rD   rP   r@   rI   rJ   s        r   Ú_derive_ctk_root_windowsrR   w   s�   € ó à�n‰nÐ.Ó/€GØ�‰˜wÓ'×-Ñ-Ó/€HØ�5ÒØ—‘ Ó(ˆØ�?‰?˜6Ó"×(Ñ(Ó*¨eÒ3Ø—>‘> &Ó)Ð)ð ð 
�UÒ	Ø�~‰~˜gÓ&Ð&Ør   c                 ó6   — t        | «      }|�|S t        | «      S )z4Derive CTK root from a resolved canary library path.)rL   rR   )rD   Úctk_roots     r   Úderive_ctk_rootrU   ‹   s$   € ä%Ð&7Ó8€HØÐØˆÜ#Ð$5Ó6Ð6r   rT   c                 óz   — t        | j                  | j                  |«      }t        | |«      }|€yt	        |d«      S )z3Find a library under a previously derived CTK root.Nzsystem-ctk-root)r>   r   r   rC   r   )r?   rT   r@   r   s       r   Úfind_via_ctk_rootrW   “   s;   € ä(¨¯©°3·<±<ÀÓJ€GÜ" 3¨Ó0€HØÐØÜ�hÐ 1Ó2Ð2r   c                 óè   — | j                   j                  | j                  «      }|sy| j                   j                  || j                  | j
                  | j                  «      }|�t        |d«      S y)z#Search pip wheel install locations.Nzsite-packages)r   Úsite_packages_rel_dirsr   Úfind_in_site_packagesr)   r   r    r   )r?   r;   r   s      r   rZ   rZ   ¡   sd   € à�|‰|×2Ñ2°3·8±8Ó<€HÙØØ�|‰|×1Ñ1°(¸C×<PÑ<PÐRU×RdÑRdÐfi×fuÑfuÓv€HØÐÜ˜( OÓ4Ð4Ør   c                 óô   — t         j                  j                  d«      }|sy| j                  j	                  |«      }t        | j                  | j                  |«      }t        | |«      }|�t        |d«      S y)zSearch ``$CONDA_PREFIX``.ÚCONDA_PREFIXNÚconda)	r7   ÚenvironÚgetr   Úconda_anchor_pointr>   r   rC   r   )r?   Úconda_prefixÚanchorr@   r   s        r   Úfind_in_condarc   ¬   sf   € ä—:‘:—>‘> .Ó1€LÙØØ�\‰\×,Ñ,¨\Ó:€FÜ(¨¯©°3·<±<ÀÓH€GÜ" 3¨Ó0€HØÐÜ˜( GÓ,Ð,Ør   c                 ó”   — t        «       }|€yt        | j                  | j                  |«      }t	        | |«      }|�t        |d«      S y)aõ  Search ``$CUDA_PATH`` / ``$CUDA_HOME``.

    On Windows, this is the normal fallback for system-installed CTK DLLs when
    they are not already discoverable via the native ``LoadLibraryExW(..., 0)``
    path used by :func:`cuda.pathfinder._dynamic_libs.load_dl_windows.load_with_system_search`.
    Python 3.8+ does not include ``PATH`` in that native DLL search.

    The returned ``found_via`` is always ``"CUDA_PATH"`` regardless of which
    environment variable actually provided the value.
    NÚ	CUDA_PATH)r   r>   r   r   rC   r   )r?   Ú	cuda_homer@   r   s       r   Úfind_in_cuda_pathrg   ¹   sM   € ô &Ó'€IØÐØÜ(¨¯©°3·<±<ÀÓK€GÜ" 3¨Ó0€HØÐÜ˜( KÓ0Ð0Ør   .ÚEARLY_FIND_STEPSÚLATE_FIND_STEPSÚstepsc                 ó.   — |D ]  } || «      }|€Œ|c S  y)z1Run find steps in order, returning the first hit.Nr   )r?   rj   ÚstepÚresults       r   Úrun_find_stepsrn   Þ   s*   € àò ˆÙ�c“ˆØÑØŠMðð r   )&r   r6   r7   Úcollections.abcr   Údataclassesr   r   Útypingr   r   Ú,cuda.pathfinder._dynamic_libs.lib_descriptorr   Ú,cuda.pathfinder._dynamic_libs.load_dl_commonr	   Ú-cuda.pathfinder._dynamic_libs.search_platformr
   r   Úcuda.pathfinder._utils.env_varsr   r   r   ÚFindStepr   r>   rC   rL   rR   rU   rW   rZ   rc   rg   rh   Útupler   ri   rn   r   r   r   ú<module>rx      sÈ  ðòó$ Û 	Ý $ß (ß !å FÝ Pß RÝ Að ÷ð ó ðð ÷bð bó ðbð. �]�O Z°$Ñ%6Ð6Ñ7€ð ]ð ¸nð Ð\_ð ÐdgÐjnÑdnó ð˜]ð °S¸4±Zð ÀCÈ$ÁJó ð ¨cð °c¸D±jó ð(°ð ¸¸d¹
ó ð(7 sð 7¨s°T©zó 7ð3˜=ð 3°Cð 3¸JÈÑ<Mó 3ð˜}ð °¸dÑ1Bó ð
�}ð 
¨°dÑ):ó 
ð˜=ð ¨Z¸$Ñ->ó ð4 +@ÀÐ)OÐ �%˜ #˜Ñ&Ó Oð *;Ð(<€��x �}Ñ%Ó <ð˜ð ¨e°H¸c°MÑ.Bð ÀzÐTXÑGXô r   