o
    vi7                     @  sF  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dl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jd	 ZeeZG d
d dejZd%d&ddZG dd deZ G dd dejZ!G dd de!Z"G dd de!Z#ej$d'dd Z%d(d#d$Z&ddgZ'dS ))    )annotationsN)
CollectionMapping   )_ctx)run_subprocess)FailedProcessError)check_dependency)pipuvc                   @  s4   e Zd ZdZeejd
ddZejdddZd	S )IsolatedEnvzIsolated build environment ABC.returnstrc                 C     dS )z2The Python executable of the isolated environment.N selfr   r   H/home/air/biblejyuku/back/venv/lib/python3.10/site-packages/build/env.pypython_executable        zIsolatedEnv.python_executableMapping[str, str] | Nonec                 C  r   )zBGenerate additional env vars specific to the isolated environment.Nr   r   r   r   r   make_extra_environ%   r   zIsolatedEnv.make_extra_environNr   r   )r   r   )	__name__
__module____qualname____doc__propertyabcabstractmethodr   r   r   r   r   r   r      s    r   namer   minimum_version_str
str | Nonedistargsobjectr   bool | Nonec                K  sn   ddl m} ddlm} ztt|jjdd| i|}W n
 ty'   Y dS w |du r.dS ||j	||kS )	z
    Given a distribution name, see if it is present and return True if the version is
    sufficient for build, False if it is not, None if the package is missing.
    r   )Versionr   	importlibr    NTr   )
packaging.versionr&   _compatr(   nextitermetadatadistributionsStopIterationversion)r    r!   r#   r&   r(   distributionr   r   r   _has_dependency*   s   "r2   c                   @  sd   e Zd ZdZddddd	Zdd
dZdddZed ddZed ddZ	d!ddZ
d"ddZdS )#DefaultIsolatedEnvz[
    Isolated environment which supports several different underlying implementations.
    r
   	installerr5   	Installerr   Nonec                C  s
   || _ d S Nr4   )r   r5   r   r   r   __init__C   s   
zDefaultIsolatedEnv.__init__c                 C  s   z4t jdd}tj|}|| _|  | jdkrt | _nt	 | _t
d| jj d | j| j W | S  tyC   | jt    w )Nz
build-env-prefixr   zCreating isolated environment: z...)tempfilemkdtempospathrealpath_pathr5   
_UvBackend_env_backend_PipBackendr   logdisplay_namecreate	Exception__exit__sysexc_infor   r?   r   r   r   	__enter__J   s   

zDefaultIsolatedEnv.__enter__argsr$   c                 G  s"   t j| jrt| j d S d S r8   )r>   r?   existsrA   shutilrmtree)r   rN   r   r   r   rI   f   s   zDefaultIsolatedEnv.__exit__r   c                 C  s   | j S )z/The location of the isolated build environment.)rA   r   r   r   r   r?   j   s   zDefaultIsolatedEnv.pathc                 C  s   | j jS )z8The python executable of the isolated build environment.)rC   r   r   r   r   r   r   o   s   z$DefaultIsolatedEnv.python_executabledict[str, str]c                 C  s6   t jd}d|d urt j| jj|giS | jjiS )NPATH)r>   environgetpathsepjoinrC   scripts_dirrL   r   r   r   r   t   s   z%DefaultIsolatedEnv.make_extra_environrequirementsCollection[str]c                 C  s:   |sdS t dddd t|D   | j| dS )at  
        Install packages from PEP 508 requirements in the isolated build environment.

        :param requirements: PEP 508 requirement specification to install

        :note: Passing non-PEP 508 strings will result in undefined behavior, you *should not* rely on it. It is
               merely an implementation detail, it may change any time without warning.
        Nz-Installing packages in isolated environment:

c                 s  s    | ]}d | V  qdS )z- Nr   ).0rr   r   r   	<genexpr>   s    z-DefaultIsolatedEnv.install.<locals>.<genexpr>)r   rE   rW   sortedrC   install_requirementsr   rY   r   r   r   install|   s   	"zDefaultIsolatedEnv.installN)r5   r6   r   r7   )r   r3   )rN   r$   r   r7   r   )r   rR   rY   rZ   r   r7   )r   r   r   r   r9   rM   rI   r   r?   r   r   rb   r   r   r   r   r3   >   s    


r3   c                   @  s@   e Zd ZU ded< ded< dddZdddZedddZdS )_EnvBackendr   r   rX   r?   r   r7   c                 C     d S r8   r   rL   r   r   r   rG      r   z_EnvBackend.createrY   rZ   c                 C  re   r8   r   ra   r   r   r   r`      r   z _EnvBackend.install_requirementsc                 C  re   r8   r   r   r   r   r   rF      s   z_EnvBackend.display_nameNr?   r   r   r7   rc   r   )r   r   r   __annotations__rG   r`   r   rF   r   r   r   r   rd      s   
 

rd   c                   @  sf   e Zd ZdddZejdddZejdd	d
ZedddZ	dddZ
dddZedddZdS )rD   r   r7   c                 C  s   | j  o| j| _d S r8   )_has_valid_outer_pip_has_virtualenv_create_with_virtualenvr   r   r   r   r9      s   z_PipBackend.__init__r%   c                 C  sh   t ddsdS t  td tjddu r"	 W d   dS W d   dS 1 s-w   Y  dS )z
        This checks for a valid global pip. Returns None if pip is missing, False
        if pip is too old, and True if it can be used.
        r
   z22.3Fignorezpip._vendorNT)r2   warningscatch_warningssimplefilterr(   util	find_specr   r   r   r   rh      s   



z _PipBackend._has_valid_outer_pipboolc                   sF   ddl m  dtjduo"t fddtd dD  S )	z
        virtualenv might be incompatible if it was installed separately
        from build. This verifies that virtualenv and all of its
        dependencies are installed as required by build.
        r   )Requirement
virtualenvNc                 3  s.    | ]}t |d kr |d  jkV  qdS )r   N)lenr    )r\   drr   r    r   r   r^      s    $z._PipBackend._has_virtualenv.<locals>.<genexpr>zbuild[])packaging.requirementsrr   r(   ro   rp   anyr	   r   r   rv   r   ri      s
   
z_PipBackend._has_virtualenvr   c                  C  sL   t  dkr$t  \} }}t| d | d dkr$|dk}|r"dS dS dS )NDarwin.   x86_64z21.0.1z20.3.0z19.1.0)platformsystemmac_verintfind)release_machineis_apple_silicon_pythonr   r   r   _get_minimum_pip_version_str   s   z(_PipBackend._get_minimum_pip_version_strr?   c              
   C  s`  | j rFdd l}dd l}ddlm} |j|jd}|ddddg}||jd	k r/|d
 |j	|dd}t
|jj| _t
|jj| _d S dd l}| j }	z|jt |	d| W n tjys }
 zt|
 t|
dd d }
~
ww t|\| _| _}|	r|  }td||gdst| jdddd| g td|gdrt| jdddddg d S d S d S )Nr   r   r'   rs   z--activators z--no-setuptoolsz--no-periodic-updatez20.31.0z
--no-wheelF)setup_loggingsymlinkswith_pipz7Failed to create venv. Maybe try installing virtualenv.r
   )r?   -Imrb   zpip>=
setuptools	uninstallz-y)rj   r)   rs   r*   r(   r0   r&   r-   appendcli_runr   creatorexer   
script_dirrX   venvrh   
EnvBuilder_fs_supports_symlinkrG   
subprocessCalledProcessErrorr   log_subprocess_errorr   _find_executable_and_scriptsr   r2   r   )r   r?   	packagingrs   r(   virtualenv_veroptsresultr   r   excpurelibminimum_pip_version_strr   r   r   rG      sR   

z_PipBackend.createrY   rZ   c              	   C  s   t jdddddd}|tj| W d    n1 sw   Y  zA| jr1tjddd	| j	g}n| j	d
dg}t
jdkrI|ddt
jd   g7 }|dddddtj|jg7 }t| W t|j d S t|j w )Nwzbuild-reqs-z.txtFzutf-8)r;   suffixdeleteencodingz-mr
   z--pythonr   r   -vrb   z--use-pep517z--no-warn-script-locationz--no-compilez-r)r<   NamedTemporaryFilewriter>   lineseprW   rh   rJ   
executabler   r   	verbosityr?   abspathr    r   unlink)r   rY   req_filecmdr   r   r   r`     s&   

z _PipBackend.install_requirementsc                 C  s   | j rdS dS )Nzvirtualenv+pipzvenv+pip)rj   r   r   r   r   rF   #  s   z_PipBackend.display_nameN)r   r7   )r   r%   r   rq   r   rf   rc   )r   r   r   r9   	functoolscached_propertyrh   ri   staticmethodr   rG   r`   r   rF   r   r   r   r   rD      s    


8rD   c                   @  s.   e Zd ZdddZdd	d
ZedddZdS )rB   r?   r   r   r7   c              	   C  s   dd l }|| _zdd l}| | _W n, ttfy>   tt	j
dp$d}|d u r1d}t|d td|  || _Y nw |jt dd| j t| j\| _| _}d S )Nr   UVr   zuv executable not foundzUsing external uv from Fr   )r   	_env_pathr   find_uv_bin_uv_binModuleNotFoundErrorFileNotFoundErrorrP   whichr>   rT   rU   RuntimeErrorr   rE   r   r   rG   r   r   rX   )r   r?   r   r   uv_binmsgr   r   r   r   rG   )  s   

	z_UvBackend.createrY   rZ   c                 C  s`   | j dg}tjdkr|ddtdtjd   g7 }tg |d|i tjd| jid d S )	Nr
   r   r   r      rb   VIRTUAL_ENV)env)r   r   r   minr   r>   rT   r   )r   rY   r   r   r   r   r`   >  s   

 ,z_UvBackend.install_requirementsc                 C  r   )Nzvenv+uvr   r   r   r   r   rF   D  s   z_UvBackend.display_nameNrf   rc   r   )r   r   r   rG   r`   r   rF   r   r   r   r   rB   (  s
    

rB   rq   c                  C  s   t jdkrdS tjdd1} |  d}zt | j| t | W n tttfy4   Y W d   dS w 	 W d   dS 1 sAw   Y  dS )z%Return True if symlinks are supportedntTzbuild-symlink-r:   z-bNF)	r>   r    r<   r   symlinkr   OSErrorNotImplementedErrorAttributeError)tmp_filedestr   r   r   r   I  s   

$r   r?   tuple[str, str, str]c                 C  s   t   }| |d< t  }d|v rt jd|d}nd|v r&t jd|d}nd|v r2t jd|d}nt j|d}tj|d tjd	krEd
nd}tj	|sXd| d}t
|||d |d fS )z
    Detect the Python executable and script folder of a virtual environment.

    :param path: The location of the virtual environment
    :return: The Python executable, script folder, and purelib folder
    baser   )schemevarsposix_localposix_prefixosx_framework_library)r   scriptsr   z
python.exepythonz0Virtual environment creation failed, executable z missingr   )	sysconfigget_config_varscopyget_scheme_names	get_pathsr>   r?   rW   r    rO   r   )r?   config_varsscheme_namespathsr   r   r   r   r   r   [  s    r   r8   )r    r   r!   r"   r#   r$   r   r%   r   )r?   r   r   r   )(
__future__r   r   r   importlib.utilr(   r>   r~   rP   r   rJ   r   r<   typingrl   collections.abcr   r   r   r   r   _exceptionsr   _utilr	   Literalr6   get_args
INSTALLERSProtocolr   r2   r3   rd   rD   rB   cacher   r   __all__r   r   r   r   <module>   sB    

N !
,