U
    +|j™  ã                   @   sž   d 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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)Útoml)Ú
check_call)Ú	get_paths)Úmkdtempé   )ÚPep517HookCallerÚLoggerWrapperc              	   C   sH   t tj | d¡ƒ�}t |¡}W 5 Q R X |d }|d |d | d¡fS )Nzpyproject.tomlzbuild-systemÚrequireszbuild-backendzbackend-path)ÚopenÚosÚpathÚjoinr   ÚloadÚget)Ú
source_dirÚfZpyproject_dataZbuildsys© r   úcC:\Users\snmko\Desktop\web_content\django_cbt\venv\Lib\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__9   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 k	otj | j¡}|r.t | j¡ | jd krHtj dd ¡ n| jtjd< | j	d k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__j   s    ÿý

zBuildEnvironment.__exit__)T)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r.   r;   rC   r   r   r   r   r      s   
 r   c           	   
   C   sn   |dkri }t | ƒ\}}}t| ||ƒ}tƒ �8}| |¡ | |¡}| |¡ | ||¡W  5 Q R £ S Q R X 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Úenvr9   r   r   r   rI   ~   s    



rI   c           	   
   C   sn   |dkri }t | ƒ\}}}t| ||ƒ}tƒ �8}| |¡ | |¡}| |¡ | ||¡W  5 Q R £ S Q R X 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_dirrK   r	   rL   rM   rN   rO   r9   r   r   r   rQ   ”   s    



rQ   )N)N)rG   r   r6   Úpip._vendorr   r=   Ú
subprocessr   r3   Ú	sysconfigr   Útempfiler   Úwrappersr   r   Ú	getLoggerrD   r%   r   Úobjectr   rI   rQ   r   r   r   r   Ú<module>   s   
a
