U ��.e��@s�dZddlZddlZddlZddlZddlmZddlZddlm Z ddl m Z ddl m Z mZe�e�Zdd �ZGd d �d e�Zdd d �Zddd�ZdS)zIBuild wheels/sdists by installing build deps to a temporary environment. �N)� check_call)� get_paths)�mkdtemp�)�Pep517HookCaller� LoggerWrapperc CsHttj�|d���}t�|�}W5QRX|d}|d|d|�d�fS)Nzpyproject.tomlz build-system�requiresz build-backendz backend-path)�open�os�path�join�toml�load�get)� source_dir�fZpyproject_dataZbuildsys�r�?/usr/lib/python3.8/site-packages/pip/_vendor/pep517/envbuild.py�_load_pyprojects�rc@s6eZdZdZdZd dd�Zdd�Zdd �Zd d �ZdS) �BuildEnvironmentz�Context manager to install build deps in a simple temporary environment Based on code I wrote for pip, which is MIT licensed. NTcCs ||_dS)N)�_cleanup)�selfZcleanuprrr�__init__9szBuildEnvironment.__init__cCs�tdd�|_t�d|j�tj�dd�|_tj�dd�|_tj dkrHdnd}t ||j|jd�d �}|d }|jr�|tj |jtjd<n|tj tj tjd<|d |d kr�|d }n|d tj |d }|jr�|tj |jtjd<n |tjd<|S) Nzpep517-build-env-)�prefixzTemporary build environment: %s�PATH� PYTHONPATH�ntZ posix_prefix)�baseZplatbase)�vars�scriptsZpurelibZplatlib) rr �log�infor �environr� save_path�save_pythonpath�namer�pathsep�defpath)rZinstall_schemeZ install_dirsrZlib_dirsrrr� __enter__<s0 �   ��  zBuildEnvironment.__enter__cCsT|sdSt�d|�tjddddd|jgt|�}t|tttj �tttj �d�dS) zAInstall dependencies into this env by calling pip in a subprocessNzCalling pip to install %sz-mZpipZinstallz--ignore-installedz--prefix)�stdout�stderr) r r!�sys� executabler �listrr�logging�INFOZERROR)r�reqs�cmdrrr� pip_install\s$ ��  �zBuildEnvironment.pip_installcCs~|jo|jdk otj�|j�}|r.t�|j�|jdkrHtj�dd�n |jtjd<|j dkrntj�dd�n |j tjd<dS)Nrr) rr r �isdir�shutilZrmtreer#r"�popr$)r�exc_typeZexc_valZexc_tbZ needs_cleanuprrr�__exit__js� �    zBuildEnvironment.__exit__)T) �__name__� __module__� __qualname__�__doc__r rr(r2r7rrrrrs   rc Csn|dkr i}t|�\}}}t|||�}t��8}|�|�|�|�}|�|�|�||�W5QR�SQRXdS)amBuild 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)rrrr2Zget_requires_for_build_wheel� build_wheel) rZ wheel_dir�config_settingsr�backend� backend_path�hooks�envr0rrrr<~s     r<c Csn|dkr i}t|�\}}}t|||�}t��8}|�|�|�|�}|�|�|�||�W5QR�SQRXdS)amBuild 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)rrrr2Zget_requires_for_build_sdist� build_sdist) rZ sdist_dirr=rr>r?r@rAr0rrrrB�s     rB)N)N)r;r r.r r4� subprocessrr+Z sysconfigrZtempfilerZwrappersrrZ getLoggerr8r r�objectrr<rBrrrr�s     a