
    ; j                        % S SK Jr  S SK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JrJr  S S	KJr  S S
KJr  \
(       a  S SKJr  \ " S S5      5       r\S/\S-  4   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!\\\\ \!4r"S\#S'   S S jr$\RJ                  S!S j5       r&S"S jr'g)#    )annotationsN)Callable)	dataclass)TYPE_CHECKING)-_resolve_system_loaded_abs_path_in_subprocess)derive_ctk_root)HEADER_DESCRIPTORSplatform_include_subdirsresolve_conda_anchor)get_cuda_path_or_home)find_sub_dirs_all_sitepackages)HeaderDescriptorc                  4    \ rS rSr% S\S'   S\S'   S	S jrSrg)
LocatedHeaderDir!   
str | Noneabs_pathstr	found_viac                8    [        U R                  5      U l        g N)	_abs_normr   )selfs    }/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/cuda/pathfinder/_headers/find_nvidia_headers.py__post_init__LocatedHeaderDir.__post_init__&   s    !$--0    )r   N)returnNone)__name__
__module____qualname____firstlineno____annotations__r   __static_attributes__ r   r   r   r   !   s    N1r   r   r   c                    U (       a<  [         R                  R                  [         R                  R                  U 5      5      $ g r   )ospathnormpathabspath)r)   s    r   r   r   2   s*    ww 566r   c                z    [         R                  R                  [         R                  R                  X5      5      $ r   )r(   r)   isfilejoin)dirpathbasenames     r   _joined_isfiler1   8   s"    77>>"'',,w9::r   c                6   U R                   nU R                   H}  n[        R                  R	                  X5      n[        U 5       H8  n[        R                  R	                  XE5      n[        Xb5      (       d  M4  Us  s  $    [        XB5      (       d  M{  Us  $    g)zNSearch for a header under *anchor_point* using the descriptor's layout fields.N)header_basenameanchor_include_rel_dirsr(   r)   r.   r
   r1   )descanchor_point
h_basenamerel_diridirsubdircdirs          r   _locate_in_anchor_layoutr<   <   sw    %%J//ww||L2.t4F77<<-Dd// 5 $++K 0 r   c                    U R                    HU  n[        [        UR                  S5      5      5       H+  n[	        X R
                  5      (       d  M  [        USS9s  s  $    MW     g)z#Search pip wheel install locations./zsite-packagesr   r   N)site_packages_dirsr   tuplesplitr1   r3   r   )r5   sub_dirhdr_dirs      r   find_in_site_packagesrE   O   sS    **5eGMM#<N6OPGg';';<<'OTT Q +
 r   c                    [         R                  R                  S5      nU(       d  g[        X5      nUc  g[	        X5      nU(       a
  [        USS9$ g)zSearch ``$CONDA_PREFIX``.CONDA_PREFIXNcondar?   )r(   environgetr   r<   r   )r5   conda_prefixr6   found_header_paths       r   find_in_condarM   Y   sL    ::>>.1L';L0D):gNNr   c                P    [        5       nUc  g[        X5      nUb
  [        USS9$ g)z'Search ``$CUDA_PATH`` / ``$CUDA_HOME``.N	CUDA_PATHr?   )r   r<   r   )r5   	cuda_homeresults      r   find_in_cuda_pathrR   g   s3    %'I%d6F;GGr   c                    U R                   (       d  g[        S5      nUc  g[        U5      nUc  g[        X5      nUb
  [	        USS9$ g)a8  Try CTK header lookup via CTK-root canary probing.

Skips immediately if the descriptor does not opt in (``use_ctk_root_canary``).
Otherwise, system-loads ``cudart`` in a fully isolated Python subprocess, derives
CTK root from the resolved library path, and searches the expected include
layout under that root.
Ncudartzsystem-ctk-rootr?   )use_ctk_root_canaryr   r   r<   r   )r5   canary_abs_pathctk_rootrQ   s       r   find_via_ctk_root_canaryrX   r   sW     ##CHMO/H%d5F;LMMr   c                    U R                    HP  n[        [        R                  " U5      SS9 H+  n[        X R                  5      (       d  M  [        USS9s  s  $    MR     g)z2Search system install directories (glob patterns).T)reversesupported_install_dirr?   N)system_install_dirssortedglobr1   r3   r   )r5   patternrD   s      r   find_in_system_install_dirsr`      sQ    ++dii0$?Gg';';<<'D[\\ @ , r   tuple[HeaderFindStep, ...]
FIND_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&   )r5   stepssteprQ   s       r   run_find_stepsrf      s%    dM  r   c                r    [         R                  " U 5      nUc  [        SU < 35      e[        U[        5      $ )u  Locate the header directory for a supported NVIDIA library.

Args:
    libname (str): The short name of the library whose headers are needed
        (e.g., ``"nvrtc"``, ``"cusolver"``, ``"nvshmem"``).

Returns:
    LocatedHeaderDir or None: A LocatedHeaderDir object containing the absolute path
    to the discovered header directory and information about where it was found,
    or ``None`` if the headers cannot be found.

Raises:
    RuntimeError: If ``libname`` is not in the supported set.

Search order:
    1. **NVIDIA Python wheels** — site-packages directories from the descriptor.
    2. **Conda environments** — platform-specific conda include layouts.
    3. **CUDA Toolkit environment variables** — ``CUDA_PATH`` / ``CUDA_HOME``.
    4. **CTK root canary probe** — subprocess canary (descriptors with
       ``use_ctk_root_canary=True`` only).
    5. **System install directories** — glob patterns from the descriptor.
zUNKNOWN libname=)r	   rJ   RuntimeErrorrf   rb   )libnamer5   s     r   locate_nvidia_header_directoryrj      s9    0 !!'*D|.gZ011$
++r   c                B    [        U 5      nU(       a  UR                  $ S$ )uL  Locate the header directory for a supported NVIDIA library.

Args:
    libname (str): The short name of the library whose headers are needed
        (e.g., ``"nvrtc"``, ``"cusolver"``, ``"nvshmem"``).

Returns:
    str or None: Absolute path to the discovered header directory, or ``None``
    if the headers cannot be found.

Raises:
    RuntimeError: If ``libname`` is not in the supported set.

Search order:
    1. **NVIDIA Python wheels** — site-packages directories from the descriptor.
    2. **Conda environments** — platform-specific conda include layouts.
    3. **CUDA Toolkit environment variables** — ``CUDA_PATH`` / ``CUDA_HOME``.
    4. **CTK root canary probe** — subprocess canary (descriptors with
       ``use_ctk_root_canary=True`` only).
    5. **System install directories** — glob patterns from the descriptor.
N)rj   r   )ri   founds     r   find_nvidia_header_directoryrm      s    , +73E"5>>,,r   )r)   r   r   r   )r/   r   r0   r   r   bool)r5   r   r6   r   r   r   )r5   r   r   LocatedHeaderDir | None)r5   r   rd   ra   r   ro   )ri   r   r   ro   )ri   r   r   r   )(
__future__r   	functoolsr^   r(   collections.abcr   dataclassesr   typingr   5cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_libr   *cuda.pathfinder._dynamic_libs.search_stepsr   *cuda.pathfinder._headers.header_descriptorr	   r
   r   cuda.pathfinder._utils.env_varsr   $cuda.pathfinder._utils.find_sub_dirsr   r   r   HeaderFindStepr   r1   r<   rE   rM   rR   rX   r`   rb   r$   rf   cacherj   rm   r&   r   r   <module>r|      s    #   	 $ !   G 
 B OK 1 1 1 -.0@40GGH;&, *
&  , ,:-r   