
    i                     l    S r SSKrSSKrSSKrSrS\S\S\4S jr\R                  S\S-  4S j5       r	g)	a  Centralized CUDA environment variable handling.

This module defines the canonical search order for CUDA Toolkit environment variables
used throughout cuda-python packages (cuda.pathfinder, cuda.core, cuda.bindings).

Search Order Priority:
    1. CUDA_PATH (higher priority)
    2. CUDA_HOME (lower priority)

If both are set and differ, CUDA_PATH takes precedence and a warning is issued.

Important Note on Caching:
    The result of get_cuda_path_or_home() is cached for the process lifetime. The first
    call determines the CUDA Toolkit path, and all subsequent calls return the cached
    value, even if environment variables change later. This ensures consistent behavior
    throughout the application lifecycle.
    N)	CUDA_PATH	CUDA_HOMEabreturnc                    [         R                  R                  [         R                  R                  U 5      5      n[         R                  R                  [         R                  R                  U5      5      nX#:X  a  g [         R                  R	                  U 5      (       aH  [         R                  R	                  U5      (       a$  [         R                  R                  X5      (       + $ g! [         a     gf = f)a{  
Return True if paths are observably different.

Strategy:
1) Compare os.path.normcase(os.path.normpath(...)) for quick, robust textual equality.
   - Handles trailing slashes and case-insensitivity on Windows.
2) If still different AND both exist, use os.path.samefile to resolve symlinks/junctions.
3) Otherwise (nonexistent paths or samefile unavailable), treat as different.
FT)ospathnormcasenormpathexistssamefileOSError)r   r   norm_anorm_bs       ^/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/cuda/pathfinder/_utils/env_vars.py_paths_differr      s     WWbgg..q12FWWbgg..q12F77>>!!2!2ww''---    s    A+C- -
C:9C:c                  J   0 n [          H/  n[        R                  R                  U5      nU(       d  M+  X U'   M1     U (       d  g[	        U 5      S:  a  [        U R                  5       5      nSn[        [	        U5      S-
  5       H%  n[        X5   S   X5S-      S   5      (       d  M#  Sn  O   U(       aN  SR                  S U R                  5        5       5      n[        R                  " SU S[         S	    S
3[        SS9  [        [        U R                  5       5      5      $ )a'  Get CUDA Toolkit path from environment variables.

Returns the value of CUDA_PATH or CUDA_HOME. If both are set and differ,
CUDA_PATH takes precedence and a warning is issued.

The result is cached for the process lifetime. The first call determines the CUDA
Toolkit path, and subsequent calls return the cached value.

Returns:
    Path to CUDA Toolkit, or None if neither variable is set or all are empty.

Warnings:
    UserWarning: If multiple CUDA environment variables are set but point to
        different locations (only on the first call).

N   FT
c              3   6   #    U  H  u  pS U SU 3v   M     g7f)z  =N ).0varvals      r   	<genexpr>(get_cuda_path_or_home.<locals>.<genexpr>_   s!      SBRhc2cU!C5!1BRs   z8Multiple CUDA environment variables are set but differ:
z
Using r   z (highest priority).   )
stacklevel)_CUDA_PATH_ENV_VARS_ORDEREDr	   environgetlenlistitemsranger   joinwarningswarnUserWarningnextitervalues)set_varsr   r   r.   values_differivar_lists          r   get_cuda_path_or_homer3   8   s   ( H*jjnnS!3SM +
  8}qhnn&'s6{Q'AVYq\6a%=+;<< $ (
 yy S(..BR SSHMMK* 4Q788LN  X__&'((    )
__doc__	functoolsr	   r)   r!   strboolr   cacher3   r   r4   r   <module>r:      sX   $  	 8 S S T 6 0)sTz 0) 0)r4   