U ��.ep�@s0dZddlmZddlmZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z Gdd�de �ZGdd �d e �ZGd d �d e �Zd d �Zdd�Zdd�Zdd�ZdZdd�Zdd�Zdd�Zd(dd�Zdd�ZGdd �d e �ZGd!d"�d"e �Zd#d$�Zddddd$hZd%d&�Ze d'k�r,e�dS))agThis is invoked in a subprocess to call the build backend hooks. It expects: - Command line args: hook_name, control_dir - Environment variables: PEP517_BUILD_BACKEND=entry.point:spec PEP517_BACKEND_PATH=paths (separated with os.pathsep) - control_dir/input.json: - {"kwargs": {...}} Results: - control_dir/output.json - {"return_val": ...} �)�glob)� import_moduleN)�joinc@seZdZdZdd�ZdS)�BackendUnavailablez&Raised if we cannot import the backendcCs ||_dS�N�� traceback��selfr�r �B/usr/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py�__init__szBackendUnavailable.__init__N��__name__� __module__� __qualname__�__doc__r r r r r rsrc@seZdZdZdd�ZdS)�BackendInvalidz Raised if the backend is invalidcCs ||_dSr)�message)r rr r r r %szBackendInvalid.__init__Nrr r r r r#src@seZdZdZdS)� HookMissingzARaised if a hook is missing and we are not executing the fallbackN�rrrrr r r r r)srcCs<tj�tj�|��}tj�tj�|��}tj�||g�|kS)z5Test if a file is located within the given directory.)�os�path�normcase�abspath� commonprefix)�filenameZ directoryr r r � contained_in-srcs�tj�d�}|r*|�tj�}|tjdd�<tjd}|�d�\}}}z t|��Wn t k rpt t � ���YnX|r�t �fdd�|D��s�td��|r�|�d �D]}t�|��q��S) zFind and load the build backendZPEP517_BACKEND_PATHNrZPEP517_BUILD_BACKEND�:c3s|]}t�j|�VqdSr)r�__file__)�.0r��objr r � Ds�z!_build_backend..z(Backend was not loaded from backend-path�.)r�environ�get�split�pathsep�sysr� partitionr� ImportErrorrr� format_exc�anyr�getattr)Z backend_pathZextra_pathitemsZepZmod_path�_Zobj_pathZ path_partr r!r �_build_backend4s&     � r0cCs6t�}z |j}Wntk r(gYSX||�SdS�zfInvoke the optional get_requires_for_build_wheel hook Returns [] if the hook is not defined. N)r0�get_requires_for_build_wheel�AttributeError��config_settings�backend�hookr r r r2Ps   r2cCsJt�}z |j}Wn*tk r:|s*t��t|||�YSX|||�SdS)z�Invoke optional prepare_metadata_for_build_wheel Implements a fallback by building a wheel if the hook isn't defined, unless _allow_fallback is False in which case HookMissing is raised. N)r0� prepare_metadata_for_build_wheelr3r�_get_wheel_metadata_from_wheel)�metadata_directoryr5Z_allow_fallbackr6r7r r r r8^s � r8ZPEP517_ALREADY_BUILT_WHEELcCs@g}|��D]}t�d|�}|r |�|�q |r4|Std��dS)z6Identify the .dist-info folder inside a wheel ZipFile.z[^/\\]+-[^/\\]+\.dist-info/z#No .dist-info folder found in wheelN)Znamelist�re�match�append� Exception)Zwhl_zip�resr�mr r r �_dist_info_filests   rAc Cs�ddlm}|�||�}ttj�|t�d��W5QRXtj�||�}||��}t|�}|j ||d�W5QRX|d� d�dS)z�Build a wheel and extract the metadata from it. Fallback for when the build backend does not define the 'get_wheel_metadata' hook. r)�ZipFile�wb)r�members�/) ZzipfilerB� build_wheel�openrrr�WHEEL_BUILT_MARKERrAZ extractallr')r6r:r5rBZ whl_basenameZwhl_fileZzipfZ dist_infor r r r9�s    r9cCsl|sdStj�|�}tj�t|t��s*dSttj�|d��}|sLtd�dSt |�dkrdtd�dS|dS)zHCheck for a wheel already built during the get_wheel_metadata hook. Nz*.whlz+Found wheel built marker, but no .whl files�zHFound multiple .whl files; unspecified behaviour. Will call build_wheel.r) rr�dirname�isfile�pjoinrHrr�print�len)r:Zmetadata_parentZ whl_filesr r r �_find_already_built_wheel�s  rOcCs4t|�}|r$t�||�tj�|�St��|||�S)z�Invoke the mandatory build_wheel hook. If a wheel was already built in the prepare_metadata_for_build_wheel fallback, this will copy it rather than rebuilding the wheel. )rO�shutilZcopy2rr�basenamer0rF)Zwheel_directoryr5r:Z prebuilt_whlr r r rF�s   �rFcCs6t�}z |j}Wntk r(gYSX||�SdSr1)r0�get_requires_for_build_sdistr3r4r r r rR�s   rRc@seZdZdZdS)�_DummyExceptionz(Nothing should ever raise this exceptionNrr r r r rS�srSc@seZdZdZdd�ZdS)�GotUnsupportedOperationz9For internal use when backend raises UnsupportedOperationcCs ||_dSrrr r r r r �sz GotUnsupportedOperation.__init__Nrr r r r rT�srTc CsBt�}z|�||�WSt|dt�k r<tt����YnXdS)z&Invoke the mandatory build_sdist hook.�UnsupportedOperationN)r0� build_sdistr.rSrTrr,)Zsdist_directoryr5r6r r r rV�s rVc CsNttj�dkrt�d�tjd}tjd}|tkrBt�d|�t�|}t�t|d��}ddd�}z|f|d �|d <Wn�t k r�}zd |d <|j |d <W5d}~XYn�t k r�}zd |d<|j |d<W5d}~XYnRt k �r}zd |d<|j |d <W5d}~XYntk �r2d |d<YnXtj|t|d�dd�dS)N�z"Needs args: hook_name, control_dirrI�zUnknown hook: %sz input.jsonF)� unsupported� return_val�kwargsrZTZ no_backendrZbackend_invalidZ backend_errorrYZ hook_missingz output.json)�indent)rNr)�argv�exit� HOOK_NAMES�globals�compatZ read_jsonrLrrrrrTrZ write_json)Z hook_nameZ control_dirr7Z hook_inputZjson_out�er r r �main�s.     rc�__main__)N)!rr� importlibrrZos.pathrrLr;rPr)rrar>rrrrr0r2r8rHrAr9rOrFrRrSrTrVr_rcrr r r r �sF      �