
    ; j              	          % S r SSKrSSKrSSKJr  SSKJrJr  SSKJ	r	J
r
  SSKJr  SSKJr  SSKJrJr  SS	KJr  \ " S
 S5      5       r\ " S S5      5       r\\/\S-  4   rS\S\S\S\S-  4S jrS\S\S-  S\S-  4S jrS\S\S-  4S jrS\S\S-  4S jrS\S\S-  4S jrS\S\S\S-  4S jrS\S\S-  4S jrS\S\S-  4S jrS\S\S-  4S jr \\4r!\"\S4   \#S '   \ 4r$\"\S4   \#S!'   S\S"\"\S4   S\S-  4S# jr%g)$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                   .    \ rS rSr% Sr\\S'   \\S'   Srg)
FindResult&   z0A library file located on disk (not yet loaded).abs_path	found_via N)__name__
__module____qualname____firstlineno____doc__str__annotations____static_attributes__r       {/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/cuda/pathfinder/_dynamic_libs/search_steps.pyr   r   &   s    :MNr   r   c                       \ rS rSr% Sr\\S'   \r\	\S'   \
" \S9r\\   \S'   \
" \S9r\\   \S'   \S\4S	 j5       r\S\4S
 j5       rS\4S jrSrg)SearchContext.   z4Mutable state accumulated during the search cascade.descplatform)default_factoryerror_messagesattachmentsreturnc                 .    U R                   R                  $ N)r    nameselfs    r   libnameSearchContext.libname7   s    yy~~r   c                 h    [        [        U R                  R                  U R                  5      5      $ r'   )r   r   r!   lib_searched_forr+   r)   s    r   r.   SearchContext.lib_searched_for;   s"    C77EFFr   c                     SR                  U R                  5      nSR                  U R                  5      n[        SU R                   SU SU 35      e)Nz, 
zFailure finding "z": )joinr#   r$   r	   r.   )r*   erratts      r   raise_not_foundSearchContext.raise_not_found?   sV    ii++,ii(()%(9$:O:O9PPSTWSXXZ[^Z_&`aar   r   N)r   r   r   r   r   r   r   r
   r!   r   r   listr#   r   r$   propertyr+   r.   r   r5   r   r   r   r   r   r   .   s    >
'Hn' %d ;NDI;"48Kc8   G# G Gb br   r   r    r!   anchor_pointr%   c           	      L   UR                  U 5      nU H  n[        [        R                  " [        R                  R                  X$5      5      5       HJ  n[        R                  R                  U5      (       d  M)  [        R                  R                  U5      s  s  $    M     g)zVFind the library directory under *anchor_point* using the descriptor's relative paths.N)anchor_rel_dirssortedglobospathr2   isdirnormpath)r    r!   r9   rel_dirsrel_pathdirnames         r   _find_lib_dir_using_anchorrE   I   so    ''-Hdii\(LMNGww}}W%%ww''00 O  r   ctxlib_dirc           
          Uc  g[        [        S-  U R                  R                  UU R                  U R
                  U R                  U R                  5      5      $ )z0Find a library file in a resolved lib directory.N)r   r   r!   find_in_lib_dirr+   r.   r#   r$   )rF   rG   s     r   _find_using_lib_dirrJ   S   sS    d
$$KK  OO	
	 	r   resolved_lib_pathc                    [         R                  R                  U 5      n[         R                  R                  U5      nUS;   a  [         R                  R                  U5      n[         R                  R                  U5      n[         R                  R                  U5      S:X  a  [         R                  R                  U5      $ U$ g)zDerive 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)r>   r?   rD   basename)rK   rG   rP   parentgrandparents        r   _derive_ctk_root_linuxrS   c   s     ggoo/0Gww(H##)ggoof-77K(I577??;//r   c                 4   SSK nUR                  U 5      nUR                  U5      R                  5       nUS:X  aG  UR                  U5      nUR                  U5      R                  5       S:X  a  UR                  U5      $  gUS:X  a  UR                  U5      $ g)zDerive 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)ntpathrD   rP   lower)rK   rW   rG   rP   rQ   s        r   _derive_ctk_root_windowsrY   w   s     nn./Gw'--/H5(??6"((*e3>>&)) 4  
U	~~g&&r   c                 8    [        U 5      nUb  U$ [        U 5      $ )z4Derive CTK root from a resolved canary library path.)rS   rY   )rK   ctk_roots     r   derive_ctk_rootr\      s$    %&78H#$566r   r[   c                 z    [        U R                  U R                  U5      n[        X5      nUc  g[	        US5      $ )z3Find a library under a previously derived CTK root.Nzsystem-ctk-root)rE   r    r!   rJ   r   )rF   r[   rG   r   s       r   find_via_ctk_rootr^      s9    (3<<JG"30Hh 122r   c                     U R                   R                  U R                  5      nU(       d  gU R                   R                  XR                  U R
                  U R                  5      nUb  [        US5      $ g)z#Search pip wheel install locations.Nzsite-packages)r!   site_packages_rel_dirsr    find_in_site_packagesr.   r#   r$   r   )rF   rB   r   s      r   ra   ra      sb    ||22388<H||11(<P<PRURdRdfifufuvH(O44r   c                     [         R                  R                  S5      nU(       d  gU R                  R	                  U5      n[        U R                  U R                  U5      n[        X5      nUb  [        US5      $ g)zSearch ``$CONDA_PREFIX``.CONDA_PREFIXNconda)	r>   environgetr!   conda_anchor_pointrE   r    rJ   r   )rF   conda_prefixanchorrG   r   s        r   find_in_condarj      sd    ::>>.1L\\,,\:F(3<<HG"30H(G,,r   c                     [        5       nUc  g[        U R                  U R                  U5      n[	        X5      nUb  [        US5      $ g)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   rE   r    r!   rJ   r   )rF   	cuda_homerG   r   s       r   find_in_cuda_pathrn      sK     &'I(3<<KG"30H(K00r   .EARLY_FIND_STEPSLATE_FIND_STEPSstepsc                 4    U H  nU" U 5      nUc  M  Us  $    g)z1Run find steps in order, returning the first hit.Nr   )rF   rq   stepresults       r   run_find_stepsru      s%    cM  r   )&r   r=   r>   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   rE   rJ   rS   rY   r\   r^   ra   rj   rn   ro   tupler   rp   ru   r   r   r   <module>r      s  $  	 $ ( ! F P R A    b b b. ]OZ$%667] n \_ dgjndn ] S4Z C$J  c cDj ( d
 (7s 7sTz 73= 3C 3J<M 3} d1B 
} 
d): 
= Z$-> 4 +@)O %#& O *;(<x}% < eHcM.B zTXGX r   