o
    f                     @  s  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m	Z	 d dl
mZmZ ddlmZ ddlmZ dd	lmZ erTd d
lmZ d dlmZmZmZmZ d dlmZ G dd deZ	d*d+ddZ		d*d,ddZd-d d!ZG d"d# d#Z d.d%d&Z!G d'd( d(eZ"g d)Z#dS )/    )annotationsN)Path)TYPE_CHECKINGCallable)IS_WIN
fs_path_id   )Discover)
PythonInfo)
PythonSpec)ArgumentParser)	GeneratorIterableMappingSequence)AppDatac                      sZ   e Zd ZU ded< ded< ded< d fdd	ZedddZdddZdddZ  Z	S )BuiltinzSequence[str]python_specr   app_datatry_first_withreturnNonec                   s0   t  | |jptjg| _|j| _|j| _d S N)super__init__pythonsys
executabler   r   r   )selfoptions	__class__ R/var/www/html/dev/env/lib/python3.10/site-packages/virtualenv/discovery/builtin.pyr      s   zBuiltin.__init__parserr   c              
   C  s6   |j ddddtdg dd |j dd	d
tdg dd d S )Nz-pz--pythonr   pyappendzinterpreter based on what to create environment (path/identifier) - by default use the interpreter where the tool is installed - first found wins)destmetavartypeactiondefaulthelpz--try-first-withr   py_exez:try first these interpreters before starting the discovery)add_argumentstr)clsr$   r"   r"   r#   add_parser_arguments!   s&   
zBuiltin.add_parser_argumentsPythonInfo | Nonec                 C  s4   | j D ]}t|| j| j| j}|d ur|  S qd S r   )r   get_interpreterr   r   _env)r   r   resultr"   r"   r#   run8   s   
zBuiltin.runr/   c                 C  s0   t | jdkr| jd n| j}| jj d|S )Nr   r   z discover of python_spec=)lenr   r!   __name__)r   specr"   r"   r#   __repr__?   s   zBuiltin.__repr__)r   r   )r$   r   r   r   )r   r2   r   r/   )
r8   
__module____qualname____annotations__r   classmethodr1   r6   r:   __classcell__r"   r"   r    r#   r      s   
 
r   r   Iterable[str]r   AppData | NoneenvMapping[str, str] | Noner   r2   c                 C  s   t | }td| t }|d u rtjn|}t||||D ])\}}|j|f} | |v r,qtd| |	||rBt
d| |  S ||  qd S )Nzfind interpreter for spec %rzproposed %szaccepted %s)r   from_string_speclogginginfosetosenvironpropose_interpreterssystem_executable	satisfiesdebugadd)keyr   r   rC   r9   proposed_pathsinterpreterimpl_must_matchr"   r"   r#   r3   D   s   

r3   r9   r   .Generator[tuple[PythonInfo, bool], None, None]c              	   c  s*   |d u rt jn|}t }|D ]8}t j|}zt | W n	 ty'   Y qw t j|}t|}||v r7q|| t	j
|||ddfV  q| jd urzt | j W n tyb   | jr` Y n w t j| j}t|}||vr|| t	j
|||ddfV  | jrd S nEt	|}	t|	j}t|}||vr|| |	dfV  trddlm}
 |
| ||D ]}t|j}t|}||v rq|| |dfV  qt| }tt|D ];\}}tt||| ||D ])\}}t|}t|}||v rq|| tj
||d|d}|d ur||fV  qqd S )N)rC   Tr   )rK   F)raise_on_errorrC   )rI   rJ   rH   pathabspathlstatOSErrorr   rO   r
   from_exeis_abscurrent_systemr/   r   r   windowsrK   path_exe_finder	enumerate	get_pathsrF   rN   LazyPathDumpPathPythonInfo)r9   r   r   rC   tested_exesr-   rV   exe_rawexe_idcurrent_pythonrK   rR   find_candidatesposexerS   r"   r"   r#   rK   W   s|   











rK   Mapping[str, str]Generator[Path, None, None]c              	   c  st    |  dd }|d u r!ztd}W n ttfy    tj}Y nw |r6tt|tj	D ]}|
 r5|V  q,d S d S )NPATHCS_PATH)getrI   confstrAttributeError
ValueErrordefpathmapr   splitpathsepexists)rC   rV   pr"   r"   r#   r`      s   
r`   c                   @  s    e Zd Zdd	d
ZdddZdS )ra   rh   intrV   r   rC   rj   r   r   c                 C  s   || _ || _|| _d S r   )rh   rV   rC   )r   rh   rV   rC   r"   r"   r#   r      s   
zLazyPathDump.__init__r/   c              	   C  s   d| j  d| j }| jdr?|d7 }| j D ]%}z| s(| jtj	@ s*W qW n	 t
y4   Y nw |d7 }||j7 }q|S )Nzdiscover PATH[z]=_VIRTUALENV_DEBUGz with => )rh   rV   rC   rn   iterdiris_dirstatst_moderI   X_OKrY   name)r   content	file_pathr"   r"   r#   r:      s   zLazyPathDump.__repr__N)rh   rx   rV   r   rC   rj   r   r   r;   )r8   r<   r=   r   r:   r"   r"   r"   r#   ra      s    
ra   :Callable[[Path], Generator[tuple[Path, bool], None, None]]c                   s@   | j tjdkd| j tjdkr  d d fdd	}|S )z^Given a spec, return a function that can be called on a path to find all matching files in it.win32)r]   z.exerV   r   r   (Generator[tuple[Path, bool], None, None]c                 3  sT    |   }|  r|dfV  |  D ]}|j}|r'| |d dkfV  qd S )NFimplr   )rv   r{   	fullmatchr   absolute)rV   direct_pathri   matchdirectpatr"   r#   	path_exes   s   
z"path_exe_finder.<locals>.path_exesN)rV   r   r   r   )generate_rer   platformstr_spec)r9   r   r"   r   r#   r^      s   

r^   c                   @  s   e Zd ZdZdS )rb   zpython info from path.N)r8   r<   r=   __doc__r"   r"   r"   r#   rb      s    rb   )r   rb   r3   )NN)r   rA   r   rB   rC   rD   r   r2   )
r9   r   r   rA   r   rB   rC   rD   r   rT   )rC   rj   r   rk   )r9   r   r   r   )$
__future__r   rF   rI   r   pathlibr   typingr   r   virtualenv.infor   r   discoverr	   py_infor
   py_specr   argparser   collections.abcr   r   r   r   virtualenv.app_data.baser   r   r3   rK   r`   ra   r^   rb   __all__r"   r"   r"   r#   <module>   s2    /
I
