Ë
    ®Ó^jí   ã                  ód  — U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ e
rd dlmZ e G d„ d«      «       Zedgedz  f   Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Z dd„Z!eeee e!fZ"de#d<   d d„Z$ejJ                  d!d„«       Z&d"d„Z'y)#é    )Ú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                  ó*   — e Zd ZU ded<   ded<   dd„Zy)ÚLocatedHeaderDirú
str | NoneÚabs_pathÚstrÚ	found_viac                ó8   — t        | j                  «      | _        y ©N)Ú	_abs_normr   )Úselfs    úw/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/cuda/pathfinder/_headers/find_nvidia_headers.pyÚ__post_init__zLocatedHeaderDir.__post_init__&   s   € Ü! $§-¡-Ó0ˆ�ó    N)ÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r   © r   r   r   r   !   s   … àÓØƒNô1r   r   r   c                ó€   — | r<t         j                  j                  t         j                  j                  | «      «      S y r   )ÚosÚpathÚnormpathÚabspath)r%   s    r   r   r   2   s*   € ÙÜ�w‰w×Ñ¤§¡§¡°Ó 5Ó6Ð6Ør   c                ó|   — t         j                  j                  t         j                  j                  | |«      «      S r   )r$   r%   ÚisfileÚjoin)ÚdirpathÚbasenames     r   Ú_joined_isfiler-   8   s$   € Ü�7‰7�>‰>œ"Ÿ'™'Ÿ,™, w°Ó9Ó:Ð:r   c                ó"  — | j                   }| j                  D ]t  }t        j                  j	                  ||«      }t        | «      D ]4  }t        j                  j	                  ||«      }t        ||«      sŒ0|c c S  t        ||«      sŒr|c S  y)zNSearch for a header under *anchor_point* using the descriptor's layout fields.N)Úheader_basenameÚanchor_include_rel_dirsr$   r%   r*   r
   r-   )ÚdescÚanchor_pointÚ
h_basenameÚrel_dirÚidirÚsubdirÚcdirs          r   Ú_locate_in_anchor_layoutr8   <   sƒ   € à×%Ñ%€JØ×/Ñ/ò ˆÜ�w‰w�|‰|˜L¨'Ó2ˆÜ.¨tÓ4ò 	ˆFÜ—7‘7—<‘<  fÓ-ˆDÜ˜d JÕ/Ø”ð	ô ˜$ 
Õ+ØŠKðð r   c                óÄ   — | j                   D ]Q  }t        t        |j                  d«      «      «      D ])  }t	        || j
                  «      sŒt        |d¬«      c c S  ŒS y)z#Search pip wheel install locations.ú/zsite-packages©r   r   N)Úsite_packages_dirsr   ÚtupleÚsplitr-   r/   r   )r1   Úsub_dirÚhdr_dirs      r   Úfind_in_site_packagesrA   O   s_   € à×*Ñ*ò Uˆä5´e¸G¿M¹MÈ#Ó<NÓ6OÓPò 	UˆGÜ˜g t×';Ñ';Õ<Ü'°ÀOÔTÔTñ	UðUð
 r   c                óœ   — t         j                  j                  d«      }|syt        | |«      }|€yt	        | |«      }|rt        |d¬«      S y)zSearch ``$CONDA_PREFIX``.ÚCONDA_PREFIXNÚcondar;   )r$   ÚenvironÚgetr   r8   r   )r1   Úconda_prefixr2   Úfound_header_paths       r   Úfind_in_condarI   Y   sP   € ä—:‘:—>‘> .Ó1€LÙØÜ'¨¨lÓ;€LØÐØÜ0°°|ÓDÐÙÜÐ):ÀgÔNÐNØr   c                óT   — t        «       }|€yt        | |«      }|�t        |d¬«      S y)z'Search ``$CUDA_PATH`` / ``$CUDA_HOME``.NÚ	CUDA_PATHr;   )r   r8   r   )r1   Ú	cuda_homeÚresults      r   Úfind_in_cuda_pathrN   g   s5   € ä%Ó'€IØÐØÜ% d¨IÓ6€FØÐÜ¨¸;ÔGÐGØr   c                óŒ   — | j                   syt        d«      }|€yt        |«      }|€yt        | |«      }|�t	        |d¬«      S y)aL  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   r8   r   )r1   Úcanary_abs_pathÚctk_rootrM   s       r   Úfind_via_ctk_root_canaryrT   r   sY   € ð ×#Ò#ØÜCÀHÓM€OØÐØÜ˜Ó/€HØÐØÜ% d¨HÓ5€FØÐÜ¨Ð;LÔMÐMØr   c                ó¾   — | j                   D ]N  }t        t        j                  |«      d¬«      D ])  }t        || j                  «      sŒt        |d¬«      c c S  ŒP y)z2Search system install directories (glob patterns).T)ÚreverseÚsupported_install_dirr;   N)Úsystem_install_dirsÚsortedÚglobr-   r/   r   )r1   Úpatternr@   s      r   Úfind_in_system_install_dirsr\   ˆ   s]   € à×+Ñ+ò ]ˆÜœdŸi™i¨Ó0¸$Ô?ò 	]ˆGÜ˜g t×';Ñ';Õ<Ü'°ÐD[Ô\Ô\ñ	]ð]ð r   útuple[HeaderFindStep, ...]Ú
FIND_STEPSc                ó.   — |D ]  } || «      }|€Œ|c S  y)z1Run find steps in order, returning the first hit.Nr"   )r1   ÚstepsÚsteprM   s       r   Úrun_find_stepsrb   Ÿ   s*   € àò ˆÙ�d“ˆØÑØŠMðð r   c                ól   — t        j                  | «      }|€t        d| ›�«      ‚t        |t        «      S )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	   rF   ÚRuntimeErrorrb   r^   )Úlibnamer1   s     r   Úlocate_nvidia_header_directoryrf   ­   s9   € ô0 ×!Ñ! 'Ó*€DØ€|ÜÐ. g ZÐ0Ó1Ð1Ü˜$¤
Ó+Ð+r   c                ó8   — t        | «      }|r|j                  S dS )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:
        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)rf   r   )re   Úfounds     r   Úfind_nvidia_header_directoryri   Ë   s   € ô, +¨7Ó3€EÙ"ˆ5�>‰>Ð,¨Ð,r   )r%   r   r   r   )r+   r   r,   r   r   Úbool)r1   r   r2   r   r   r   )r1   r   r   úLocatedHeaderDir | None)r1   r   r`   r]   r   rk   )re   r   r   rk   )re   r   r   r   )(Ú
__future__r   Ú	functoolsrZ   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   r-   r8   rA   rI   rN   rT   r\   r^   r!   rb   Úcacherf   ri   r"   r   r   ú<module>rx      sÞ   ðö #ã Û Û 	Ý $Ý !Ý  õõ G÷ñ õ
 BÝ OáÝKð ÷1ð 1ó ð1ð Ð-Ð.Ð0@À4Ñ0GÐGÑH€óó;óó&óóóó,ð ØØØØð*€
Ð&ó óð ‡�ò,ó ð,ô:-r   