a
    hbòfÔ  ã                   @   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 s40    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ÚfZpyproject_dataZbuildsys© r   úX/home/httpd/docs/test/DocsMgr/lib/python3.9/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rHdnd}t
|| j| jdœd	�}|d
 }| jrˆ|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rì|tj | j tjd< n
|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   Zinstall_schemeZinstall_dirsr#   Úlib_dirsr   r   r   Ú	__enter__@   s0    þ

ÿÿ
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 rHtj dd ¡ n| jtjd< | j	d u rntj dd ¡ n| j	tjd< d S )Nr   r   )
r   r   r   ÚisdirÚshutilÚrmtreer)   r(   Úpopr*   )r   Úexc_typeÚexc_valÚexc_tbZneeds_cleanupr   r   r   Ú__exit__n   s    ÿý

zBuildEnvironment.__exit__)T)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r/   r<   rD   r   r   r   r   r   !   s   
 r   c           	      C   sz   |du ri }t | ƒ\}}}t| ||ƒ}tƒ �:}| |¡ | |¡}| |¡ | ||¡W  d  ƒ S 1 sl0    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   r<   Úget_requires_for_build_wheelÚbuild_wheel)	r   Ú	wheel_dirÚconfig_settingsr
   ÚbackendÚbackend_pathÚhooksÚenvr:   r   r   r   rJ   ‚   s    



rJ   c           	      C   sz   |du ri }t | ƒ\}}}t| ||ƒ}tƒ �:}| |¡ | |¡}| |¡ | ||¡W  d  ƒ S 1 sl0    Y  dS )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   r<   Úget_requires_for_build_sdistÚbuild_sdist)	r   Z	sdist_dirrL   r
   rM   rN   rO   rP   r:   r   r   r   rR   ˜   s    



rR   )N)N)rH   r   r   r7   r>   Ú
subprocessr   r4   Ú	sysconfigr   Útempfiler   Úcompatr   Úwrappersr   r   Ú	getLoggerrE   r&   r   Úobjectr   rJ   rR   r   r   r   r   Ú<module>   s   
a
