
    3i2                    h   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
mZ d dlmZ ddlmZ dd	lmZ dd
lmZ e
rd dlmZmZmZmZmZ ddlmZ  ej8                  e      Zded<   ej@                  dk(  Z!ded<   	 	 	 	 d+	 	 	 	 	 	 	 	 	 	 	 d,dZ"	 	 	 d-	 	 	 	 	 	 	 	 	 	 	 d.dZ#d/dZ$d0dZ%	 	 d1	 	 	 	 	 	 	 	 	 d2dZ&	 	 	 	 	 	 	 	 	 	 	 	 d3dZ'	 	 	 	 	 	 	 	 	 	 d4dZ(	 	 	 	 	 	 	 	 	 	 d4dZ)	 	 	 	 	 	 d5dZ*d6dZ+ G d d      Z,d7dZ-d8dZ.g d Z/d!ed"<   d9d#Z0d:d$Z1d%d&d;d'Z2 G d( d)e      Z3g d*Z4y)<    )annotationsN)suppress)Path)TYPE_CHECKINGFinal)user_data_path   )
fs_path_id)
PythonInfo)
PythonSpec)Callable	GeneratorIterableMappingSequence)PyInfoCachezFinal[logging.Logger]_LOGGERwin32zFinal[bool]IS_WINc                n    t        | t              r| gn| }|D ]  }t        ||xs d|||      x}s|c S  y)u  
    Find a Python interpreter matching *key*.

    Iterates over one or more specification strings and returns the first interpreter that satisfies the spec and passes
    the optional *predicate*.

    :param key: interpreter specification string(s) — an absolute path, a version (``3.12``), an implementation prefix
        (``cpython3.12``), or a PEP 440 specifier (``>=3.10``). When a sequence is given each entry is tried in order.
    :param try_first_with: executables to probe before the normal discovery search.
    :param cache: interpreter metadata cache; when ``None`` results are not cached.
    :param env: environment mapping for ``PATH`` lookup; defaults to :data:`os.environ`.
    :param predicate: optional callback applied after an interpreter matches the spec. Return ``True`` to accept the
        interpreter, ``False`` to skip it and continue searching.
    :return: the first matching interpreter, or ``None`` if no match is found.
     N)
isinstancestr_find_interpreter)keytry_first_withcacheenv	predicatespecsspec_strresults           N/var/www/opsc/venv/lib/python3.12/site-packages/python_discovery/_discovery.pyget_interpreterr$      sM    ,  S)SEsE &x1E2ucS\]]6]M     c                   t        j                  |       }t        j                  d|       t	               }|t
        j                  n|}t        ||||      D ]y  \  }}|	|j                  |f}	|	|v rt        j                  d|       |j                  ||      r$| ||      rt        j                  d|       |c S |j                  |	       { y )Nzfind interpreter for spec %rzproposed %s)impl_must_matchzaccepted %s)r   from_string_specr   infosetosenvironpropose_interpreterssystem_executable	satisfiesdebugadd)
r   r   r   r   r   specproposed_pathsinterpreterr'   proposed_keys
             r#   r   r   6   s     &&s+DLL/6365N"**C(<T>SXZ](^ )$_"44oE>)]K0   G;!7MM-5<() r%   c                   	 t        j                  |        t        t	        |       j                               }t        |      }||v ry|j                  |       t        t	        |       j                               S # t        $ r Y yw xY w)zWResolve *path* to an absolute path and return it if not yet tested, otherwise ``None``.N)	r+   lstatOSErrorr   r   resolver
   r1   absolute)pathtested_exesresolvedexe_ids       r#   
_check_exer?   Q   sx    
 4:%%'(H!FOOFtDz""$%%  s   A< <	BBc                F    t        |       }||v ry|j                  |       y)zDReturn ``True`` and register *exe_raw* if it hasn't been tested yet.FT)r
   r1   )exe_rawr<   r>   s      r#   _is_new_exerB   _   s&     FOOFr%   c              #    K   |t         j                  n|}t               }| j                  rA| j                  5t        | j                  |      x}rt        j                  |||      df yt        | ||||      E d{    | j                  | j                  ryt        | |||      E d{    t        ||      E d{    y7 H7 7 	w)a  
    Yield ``(interpreter, impl_must_match)`` candidates for *spec*.

    :param spec: the parsed interpreter specification to match against.
    :param try_first_with: executable paths to probe before the standard search.
    :param cache: interpreter metadata cache; when ``None`` results are not cached.
    :param env: environment mapping for ``PATH`` lookup; defaults to :data:`os.environ`.
    Nr   T)r+   r,   r*   is_absr;   r?   r   from_exe_propose_explicit_propose_from_path_propose_from_uv)r2   r   r   r   r<   rA   s         r#   r-   r-   h   s      "**CEK{{tyy, K8878%%gu#>DD ~uc;OOOyy!$sK@@@s+++	 P A+s6   A>C C	.C/C0CCCCCc              #  d  K   |D ]M  }t        t        t        |      j                               |      x}s2t	        j
                  |||      df O | j                  6t        | j                  |      x}rt	        j
                  |||      df y y t        | |||      E d {    y 7 w)NrD   T)r?   r   r   r9   r   rF   r;   _propose_current_and_windows)r2   r   r   r   r<   py_exerA   s          r#   rG   rG      s      ! E T&\%9%9%;!<kJJ7J%%gu#>DDE yy K8878%%gu#>DD 9 0eS+NNNs   4B0A1B0(B.)B0c              #    K   t        j                  |      }t        t        |j                        |      r|df t
        r<ddlm}  || ||      D ](  }t        t        |j                        |      s#|df * y y w)NTr	   )r-   )r   current_systemrB   r   
executabler   _windowsr-   )r2   r   r   r<   current_pythonwin_proposer4   s          r#   rK   rK      s{       ..u5N3~001;?d""A&tUC8 	(K3{556D!4''	( s   A3B 6
B c              #  |  K   t        |       }t        t        |            D ]  \  }}t        j	                  t        |||              ||      D ]f  \  }}t        |      }	t        |	|      x}
rt        j	                  d|	|
       |
}	t        |	|      sEt        j                  |	|d|      }|a||f h  y w)Nzresolved shim %s to %sFraise_on_errorr   )path_exe_finder	enumerate	get_pathsr   r0   LazyPathDumpr   _resolve_shimrB   PathPythonInforF   )r2   r   r   r<   find_candidatesposr;   exer'   rA   r=   r4   s               r#   rH   rH      s      &d+Oy~. 3	Tl3c23$3D$9 		3 C#hG(#66x66J"w4(11'5QV\_1`K&!?22		33s   B.B<1B<c              #  z  K   t        j                  d      x}rt        |      j                         }nEt        j                  d      x}r t        |      j                         dz  dz  }nt	        d      dz  }|j                  d      D ]-  }t        j                  t        |      | d|      }|(|df / y w)	NUV_PYTHON_INSTALL_DIRXDG_DATA_HOMEuvpythonz*/bin/pythonFrT   T)	r+   getenvr   
expanduserr   globr[   rF   r   )r   r   uv_python_diruv_python_pathxdg_data_homeexe_pathr4   s          r#   rI   rI      s      		"9::}:m,779))O4	4	4m,779D@8K'-8"''7 $$--c(mUSX^a-b"t##$s   B/B;2	B;c              #    K   | j                  dd       }|	 t        j                  d      }|ryt        t        |j                  t        j                              D ]H  }t        t              5  |j                         rt        |j                         d       r| d d d        J y y # t        t        f$ r t        j
                  }Y w xY w# 1 sw Y   {xY ww)NPATHCS_PATH)getr+   confstrAttributeError
ValueErrordefpathmapr   splitpathsepr   r8   is_dirnextiterdir)r   r;   entrys      r#   rX   rX      s     7764 D|	::i(D tzz"**56 	 E'"  <<>d5==?D&AK   	   
+ 	::D	   s@   CB) AC./CC)CC
CCC	Cc                      e Zd ZddZddZy)rY   c                .    || _         || _        || _        y N)r]   r;   r   )selfr]   r;   r   s       r#   __init__zLazyPathDump.__init__   s    	r%   c                   d| j                    d| j                   }| j                  j                  d      r|dz  }| j                  j	                         D ]  	 j                         rt        r@| j                  j                  dd      j                  d      }t        fd|D              s-[j                         j                  t        j                  z  s|d	z  }|j                  z  } |S # t        $ r Y #w xY w)
Nzdiscover PATH[z]=_VIRTUALENV_DEBUGz with =>PATHEXTz.COM;.EXE;.BAT;.CMD;c              3  p   K   | ]-  }j                   j                         j                  |       / y wr|   )nameupperendswith).0ext	file_paths     r#   	<genexpr>z(LazyPathDump.__repr__.<locals>.<genexpr>   s)     "[C9>>#7#7#9#B#B3#G"[s   36 )r]   r;   r   rn   rx   rv   r   rt   anystatst_moder+   X_OKr8   r   )r}   contentpathextr   s      @r#   __repr__zLazyPathDump.__repr__   s    "488*Btyyk:88<<+,z!G!YY..0 *	
 '') "&((,,y:O"P"V"VWZ"[""[SZ"[[$'nn.66@  39>>)* 	  s   C7-AC73+C77	DDN)r]   intr;   r   r   Mapping[str, str]returnNone)r   r   )__name__
__module____qualname__r~   r   r   r%   r#   rY   rY      s    
r%   rY   c                    | j                  t        j                  dk(        | j                  t        j                  dk(  r ddfd}|S )z^Given a spec, return a function that can be called on a path to find all matching files in it.r   )windowsz.exec              3     K   | z  }|j                         r|df | j                         D ]:  }j                  |j                        }|s!|j	                         |d   dk(  f < y w)NFimplrc   )existsrx   	fullmatchr   r:   )r;   direct_pathr^   matchdirectpats       r#   	path_exesz"path_exe_finder.<locals>.path_exes   sm     Vmu$$<<> 	@CMM#((+EllneFmx&???	@s   AA-A-)r;   r   r   z(Generator[tuple[Path, bool], None, None])generate_resysplatformstr_spec)r2   r   r   r   s     @@r#   rV   rV      sM    


3<<7#:

;C]]F
||w84@ r%   c                h   t         D ]  \  }}|j                  |      x}st        j                  j	                  |d      }t        j                  j                  |       |k(  s]t        j                  j                  |       }t        j                  j                  |g| }t        |||      c S  y)z;Resolve a version-manager shim to the actual Python binary.shimsN)_VERSION_MANAGER_LAYOUTSrn   r+   r;   joindirnamebasename_resolve_shim_to_binary)rj   r   shims_dir_envversions_pathroot	shims_direxe_nameversions_dirs           r#   rZ   rZ     s    (@ L$}77=))4)T73Iwwx(I577++H5!ww||DA=A.xsKKL r%   ))
PYENV_ROOT)versions)MISE_DATA_DIRinstallsrc   )ASDF_DATA_DIRr   z!list[tuple[str, tuple[str, ...]]]r   c                    t        |      D ]f  }t        j                  j                  ||d|       }t	        |      j                         s?t        j                  |t        j                        sd|c S  y )Nbin)_active_versionsr+   r;   r   r   is_fileaccessr   )r   r   r   versionr=   s        r#   r   r     sY    #C( 77<<guhG>!!#		(BGG(DO r%   c              #  ^  K   | j                  d      x}r|j                  d      E d{    yt        t        j                               x}r|E d{    y| j                  d      x}r9t        t
        j                  j                  |d      d      x}r|E d{    yyy7 |7 T7 w)zMYield active Python version strings by reading version-manager configuration.PYENV_VERSION:Nr   r   Fsearch_parents)rn   rt   _read_python_version_filer   cwdr+   r;   r   )r   pyenv_versionr   
pyenv_roots       r#   r   r   &  s     00}0 &&s+++,TXXZ88x8ggl++
+-bggll:y.Qbghhh 	i 	, 	, 	
 	s4   (B-B')B-B)A
B-B+ B-)B-+B-Tr   c                  | }	 t        |      j                         r t        j                  j	                  |d      n|}t        |      j                         rgt        |      j                  d      5 }|D cg c])  }|j                         x}s|j                  d      r(|+ c}x}r|cddd       S 	 ddd       |syt        |      j                  }||k(  ry|}c c}w # 1 sw Y   /xY w)zIRead a ``.python-version`` file, optionally searching parent directories.z.python-versionzutf-8)encoding#N)
r   rv   r+   r;   r   r   openstrip
startswithparent)	startr   current	candidatefhlinevr   r   s	            r#   r   r   4  s    G
@DW@T@T@VBGGLL*;<\c		?""$i%%w%7 $2.0bd$**,5FQ5FPQP\P\]`Pabb8b#$ $b$ g%%W   c$ $s*   3C%8C C "C &C% C%%C.c                      e Zd ZdZy)r[   zpython info from path.N)r   r   r   __doc__r   r%   r#   r[   r[   E  s     r%   r[   )rY   r[   r$   rX   r-   )NNNN)r   zstr | Sequence[str]r   zIterable[str] | Noner   PyInfoCache | Noner   Mapping[str, str] | Noner   #Callable[[PythonInfo], bool] | Noner   PythonInfo | None)NNN)r   r   r   Iterable[str]r   r   r   r   r   r   r   r   )r;   r   r<   set[str]r   
str | None)rA   r   r<   r   r   bool)NN)
r2   r   r   r   r   r   r   r   r   5Generator[tuple[PythonInfo | None, bool], None, None])r2   r   r   r   r   r   r   r   r<   r   r   r   )
r2   r   r   r   r   r   r<   r   r   r   )r   r   r   r   r   r   )r   r   r   zGenerator[Path, None, None])r2   r   r   z:Callable[[Path], Generator[tuple[Path, bool], None, None]])rj   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   zGenerator[str, None, None])r   z
str | Pathr   r   r   zlist[str] | None)5
__future__r   loggingr+   r   
contextlibr   pathlibr   typingr   r   platformdirsr   _compatr
   _py_infor   _py_specr   collections.abcr   r   r   r   r   _cacher   	getLoggerr   r   __annotations__r   r   r$   r   r?   rB   r-   rG   rK   rH   rI   rX   rY   rV   rZ   r   r   r   r   r[   __all__r   r%   r#   <module>r      sQ   "  	 
   ' '     PP#!2!2!28!<	 <llg- -
 ,0 $$(59	(  
"	
 3 @ !%$(59	!  
"	
 3 6& !%$(	,
,!, , 
"	,
 ;,8O
O!O O 
	O
 O ;O$(
(( 
( 	(
 ;($3
33 
3 	3
 ;3*$$	$ ;$"  6(	? ;  LP "!Z !r%   