o
    Ëý°jÔ  ã                   @   s¦   d Z ddlZddlZddlZddlZddlm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mZ e e¡Zd	d
„ ZG dd„ deƒZddd„Zddd„ZdS )zIBuild wheels/sdists by installing build deps to a temporary environment.
é    N)Ú
check_call)Ú	get_paths)Úmkdtempé   )Ú	toml_load)ÚPep517HookCallerÚLoggerWrapperc                 C   s^   t  tj | d¡d¡�}t|ƒ}W d   ƒ n1 sw   Y  |d }|d |d | d¡fS )Nzpyproject.tomlÚrbzbuild-systemÚrequireszbuild-backendzbackend-path)ÚioÚopenÚosÚpathÚjoinr   Úget)Ú
source_dirÚfÚpyproject_dataÚbuildsys© r   úŽ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_vendor/pep517/envbuild.pyÚ_load_pyproject   s   þ
üýr   c                   @   s6   e Zd ZdZdZddd„Zdd„ Zdd	„ Zd
d„ ZdS )ÚBuildEnvironmentz‡Context manager to install build deps in a simple temporary environment

    Based on code I wrote for pip, which is MIT licensed.
    NTc                 C   s
   || _ d S ©N)Ú_cleanup)ÚselfÚcleanupr   r   r   Ú__init__=   s   
zBuildEnvironment.__init__c                 C   sü   t dd�| _t d| j¡ tj dd ¡| _tj dd ¡| _tj	dkr$dnd}t
|| j| jdœd	�}|d
 }| jrD|tj | j tjd< n|tj tj tjd< |d |d kr\|d }n|d tj |d  }| jrw|tj | j tjd< | S |tjd< | S )Nzpep517-build-env-)ÚprefixzTemporary build environment: %sÚPATHÚ
PYTHONPATHÚntÚposix_prefix)ÚbaseÚplatbase)ÚvarsÚscriptsÚpurelibÚplatlib)r   r   ÚlogÚinfor   Úenvironr   Ú	save_pathÚsave_pythonpathÚnamer   ÚpathsepÚdefpath)r   Úinstall_schemeÚinstall_dirsr&   Úlib_dirsr   r   r   Ú	__enter__@   s2   
þ
ÿ
ÿ
þzBuildEnvironment.__enter__c                 C   sT   |sdS t  d|¡ tjddddd| jgt|ƒ }t|tt tj	ƒtt tj
ƒd� dS )	zAInstall dependencies into this env by calling pip in a subprocessNzCalling pip to install %sz-mÚpipÚinstallz--ignore-installedz--prefix)ÚstdoutÚstderr)r)   r*   ÚsysÚ
executabler   Úlistr   r   ÚloggingÚINFOÚERROR)r   ÚreqsÚcmdr   r   r   Úpip_install`   s   þþ


ýzBuildEnvironment.pip_installc                 C   s€   | j o| jd uotj | j¡}|rt | j¡ | jd u r$tj dd ¡ n| jtjd< | j	d u r8tj dd ¡ d S | j	tjd< d S )Nr   r    )
r   r   r   ÚisdirÚshutilÚrmtreer,   r+   Úpopr-   )r   Úexc_typeÚexc_valÚexc_tbÚneeds_cleanupr   r   r   Ú__exit__n   s   ÿý

zBuildEnvironment.__exit__)T)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r4   rA   rJ   r   r   r   r   r   !   s    
 r   c           	      C   óz   |du ri }t | ƒ\}}}t| ||ƒ}tƒ �}| |¡ | |¡}| |¡ | ||¡W  d  ƒ S 1 s6w   Y  dS )am  Build a wheel from a source directory using PEP 517 hooks.

    :param str source_dir: Source directory containing pyproject.toml
    :param str wheel_dir: Target directory to create wheel in
    :param dict config_settings: Options to pass to build backend

    This is a blocking function which will run pip in a subprocess to install
    build requirements.
    N)r   r   r   rA   Úget_requires_for_build_wheelÚbuild_wheel)	r   Ú	wheel_dirÚconfig_settingsr
   ÚbackendÚbackend_pathÚhooksÚenvr?   r   r   r   rQ   ‚   ó   




$ürQ   c           	      C   rO   )am  Build an sdist from a source directory using PEP 517 hooks.

    :param str source_dir: Source directory containing pyproject.toml
    :param str sdist_dir: Target directory to place sdist in
    :param dict config_settings: Options to pass to build backend

    This is a blocking function which will run pip in a subprocess to install
    build requirements.
    N)r   r   r   rA   Úget_requires_for_build_sdistÚbuild_sdist)	r   Ú	sdist_dirrS   r
   rT   rU   rV   rW   r?   r   r   r   rZ   ˜   rX   rZ   r   )rN   r   r   r<   rC   Ú
subprocessr   r9   Ú	sysconfigr   Útempfiler   Úcompatr   Úwrappersr   r   Ú	getLoggerrK   r)   r   Úobjectr   rQ   rZ   r   r   r   r   Ú<module>   s     

a