o
    6‘ðiX:  ã                
   @   sœ  d dl Z d dlZd dl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mZ d dlmZmZmZmZmZmZ ddlmZ erRd d	lmZ G d
d„ deƒZdeeef deddfdd„Zdedeeef fdd„ZG dd„ deƒZG dd„ deƒZG dd„ deƒZ		d&dee dee deeeef  ddfdd„Z 		d&dee dee deeeef  ddfdd„Z!d ed!edefd"d#„Z"G d$d%„ d%ƒZ#dS )'é    N)Úcontextmanager)Úabspath)Újoin)ÚSTDOUTÚ
check_callÚcheck_output)ÚTYPE_CHECKINGÚAnyÚIteratorÚMappingÚOptionalÚSequenceé   )Ú_in_proc_script_path)ÚProtocolc                
   @   sD   e Zd ZdZ		d	dee dee deeeef  ddfdd„ZdS )
ÚSubprocessRunnerz%A protocol for the subprocess runner.NÚcmdÚcwdÚextra_environÚreturnc                 C   s   d S ©N© )Úselfr   r   r   r   r   ú`/root/parts/websockify/install/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_impl.pyÚ__call__   s   zSubprocessRunner.__call__©NN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r   r   r   r   r   r   r      s    üþýüûr   ÚobjÚpathr   c                 K   sH   t |ddd��}tj| |fi |¤Ž W d   ƒ d S 1 sw   Y  d S )NÚwúutf-8©Úencoding)ÚopenÚjsonÚdump)r!   r"   ÚkwargsÚfr   r   r   Ú
write_json   s   "ÿr,   c                 C   s:   t | dd��}t |¡W  d   ƒ S 1 sw   Y  d S )Nr$   r%   )r'   r(   Úload)r"   r+   r   r   r   Ú	read_json!   s   $ÿr.   c                       sN   e Zd ZdZ			d
dedee dee deee  ddf
‡ fdd	„Z‡  ZS )ÚBackendUnavailablezEWill be raised if the backend cannot be imported in the hook process.NÚ	tracebackÚmessageÚbackend_nameÚbackend_pathr   c                    s&   || _ || _|| _tƒ  |pd¡ d S )NzError while importing backend)r2   r3   r0   ÚsuperÚ__init__)r   r0   r1   r2   r3   ©Ú	__class__r   r   r5   )   s   zBackendUnavailable.__init__©NNN)	r   r   r   r   r    r   r   r5   Ú__classcell__r   r   r6   r   r/   &   s     ûþýü
ûúr/   c                       s*   e Zd ZdZdeddf‡ fdd„Z‡  ZS )ÚHookMissingz>Will be raised on missing hooks (if a fallback can't be used).Ú	hook_namer   Nc                    s   t ƒ  |¡ || _d S r   )r4   r5   r;   )r   r;   r6   r   r   r5   :   s   
zHookMissing.__init__)r   r   r   r   r    r5   r9   r   r   r6   r   r:   7   s    r:   c                   @   s"   e Zd ZdZdeddfdd„ZdS )ÚUnsupportedOperationzDMay be raised by build_sdist if the backend indicates that it can't.r0   r   Nc                 C   s
   || _ d S r   )r0   )r   r0   r   r   r   r5   B   s   
zUnsupportedOperation.__init__)r   r   r   r   r    r5   r   r   r   r   r<   ?   s    r<   r   r   r   c                 C   s*   t j ¡ }|r| |¡ t| ||d� dS )zwThe default method of calling the wrapper subprocess.

    This uses :func:`subprocess.check_call` under the hood.
    )r   ÚenvN)ÚosÚenvironÚcopyÚupdater   ©r   r   r   r=   r   r   r   Údefault_subprocess_runnerF   s   
	
rC   c                 C   s,   t j ¡ }|r| |¡ t| ||td� dS )zqCall the subprocess while suppressing output.

    This uses :func:`subprocess.check_output` under the hood.
    )r   r=   ÚstderrN)r>   r?   r@   rA   r   r   rB   r   r   r   Úquiet_subprocess_runnerV   s   
	
rE   Úsource_treeÚ	requestedc                 C   sn   t j |¡r
tdƒ‚t j | ¡}t j t j ||¡¡}t j |¡}t j |¡}t j ||g¡|kr5tdƒ‚|S )zèNormalise and check a backend path.

    Ensure that the requested backend path is specified as a relative path,
    and resolves to a location under the given source tree.

    Return an absolute version of the requested path.
    zpaths must be relativez paths must be inside source tree)	r>   r"   ÚisabsÚ
ValueErrorr   Únormpathr   ÚnormcaseÚcommonprefix)rF   rG   Ú
abs_sourceÚabs_requestedÚnorm_sourceÚnorm_requestedr   r   r   Únorm_and_checkf   s   rQ   c                   @   sè  e Zd ZdZ			d*dededeee  ded dee d	dfd
d„Zeddd	e	d fdd„ƒZ
d	ee fdd„Z	d+deeeef  d	ee fdd„Z		d,dedeeeef  ded	efdd„Z		d-dedeeeef  dee d	efdd„Z	d+deeeef  d	ee fdd„Z		d,dedeeeef  ded	ee fdd„Z		d-dedeeeef  dee d	efdd „Z	d+deeeef  d	ee fd!d"„Z	d+d#edeeeef  d	efd$d%„Zd&ed'eeef d	efd(d)„ZdS ).ÚBuildBackendHookCallerzAA wrapper to call the build backend hooks for a source directory.NÚ
source_dirÚbuild_backendr3   Úrunnerr   Úpython_executabler   c                    sR   |du rt }t|ƒˆ _|ˆ _|r‡ fdd„|D ƒ}|ˆ _|ˆ _|s$tj}|ˆ _dS )a“  
        :param source_dir: The source directory to invoke the build backend for
        :param build_backend: The build backend spec
        :param backend_path: Additional path entries for the build backend spec
        :param runner: The :ref:`subprocess runner <Subprocess Runners>` to use
        :param python_executable:
            The Python executable used to invoke the build backend
        Nc                    s   g | ]}t ˆ j|ƒ‘qS r   )rQ   rS   )Ú.0Úp©r   r   r   Ú
<listcomp>—   s    z3BuildBackendHookCaller.__init__.<locals>.<listcomp>)	rC   r   rS   rT   r3   Ú_subprocess_runnerÚsysÚ
executablerV   )r   rS   rT   r3   rU   rV   r   rY   r   r5   �   s   

zBuildBackendHookCaller.__init__c                 c   s*   � | j }|| _ z	dV  W || _ dS || _ w )ay  A context manager for temporarily overriding the default
        :ref:`subprocess runner <Subprocess Runners>`.

        :param runner: The new subprocess runner to use within the context.

        .. code-block:: python

            hook_caller = BuildBackendHookCaller(...)
            with hook_caller.subprocess_runner(quiet_subprocess_runner):
                ...
        N)r[   )r   rU   Úprevr   r   r   Úsubprocess_runnerž   s   €z(BuildBackendHookCaller.subprocess_runnerc                 C   s   |   di ¡S )z>Return the list of optional features supported by the backend.Ú_supported_features©Ú
_call_hookrY   r   r   r   r`   ²   s   z*BuildBackendHookCaller._supported_featuresÚconfig_settingsc                 C   ó   |   dd|i¡S )am  Get additional dependencies required for building a wheel.

        :param config_settings: The configuration settings for the build backend
        :returns: A list of :pep:`dependency specifiers <508>`.

        .. admonition:: Fallback

            If the build backend does not defined a hook with this name, an
            empty list will be returned.
        Úget_requires_for_build_wheelrc   ra   ©r   rc   r   r   r   re   ¶   ó   ÿz3BuildBackendHookCaller.get_requires_for_build_wheelTÚmetadata_directoryÚ_allow_fallbackc                 C   ó   |   dt|ƒ||dœ¡S )aS  Prepare a ``*.dist-info`` folder with metadata for this project.

        :param metadata_directory: The directory to write the metadata to
        :param config_settings: The configuration settings for the build backend
        :param _allow_fallback:
            Whether to allow the fallback to building a wheel and extracting
            the metadata from it. Should be passed as a keyword argument only.

        :returns: Name of the newly created subfolder within
                  ``metadata_directory``, containing the metadata.

        .. admonition:: Fallback

            If the build backend does not define a hook with this name and
            ``_allow_fallback`` is truthy, the backend will be asked to build a
            wheel via the ``build_wheel`` hook and the dist-info extracted from
            that will be returned.
        Ú prepare_metadata_for_build_wheel©rh   rc   ri   ©rb   r   ©r   rh   rc   ri   r   r   r   rk   È   s   ýþz7BuildBackendHookCaller.prepare_metadata_for_build_wheelÚwheel_directoryc                 C   ó(   |durt |ƒ}|  dt |ƒ||dœ¡S )aÕ  Build a wheel from this project.

        :param wheel_directory: The directory to write the wheel to
        :param config_settings: The configuration settings for the build backend
        :param metadata_directory: The directory to reuse existing metadata from
        :returns:
            The name of the newly created wheel within ``wheel_directory``.

        .. admonition:: Interaction with fallback

            If the ``build_wheel`` hook was called in the fallback for
            :meth:`prepare_metadata_for_build_wheel`, the build backend would
            not be invoked. Instead, the previously built wheel will be copied
            to ``wheel_directory`` and the name of that file will be returned.
        NÚbuild_wheel©ro   rc   rh   ©r   rb   ©r   ro   rc   rh   r   r   r   rq   é   s   ýþz"BuildBackendHookCaller.build_wheelc                 C   rd   )aw  Get additional dependencies required for building an editable wheel.

        :param config_settings: The configuration settings for the build backend
        :returns: A list of :pep:`dependency specifiers <508>`.

        .. admonition:: Fallback

            If the build backend does not defined a hook with this name, an
            empty list will be returned.
        Úget_requires_for_build_editablerc   ra   rf   r   r   r   ru   	  rg   z6BuildBackendHookCaller.get_requires_for_build_editablec                 C   rj   )aU  Prepare a ``*.dist-info`` folder with metadata for this project.

        :param metadata_directory: The directory to write the metadata to
        :param config_settings: The configuration settings for the build backend
        :param _allow_fallback:
            Whether to allow the fallback to building a wheel and extracting
            the metadata from it. Should be passed as a keyword argument only.
        :returns: Name of the newly created subfolder within
                  ``metadata_directory``, containing the metadata.

        .. admonition:: Fallback

            If the build backend does not define a hook with this name and
            ``_allow_fallback`` is truthy, the backend will be asked to build a
            wheel via the ``build_editable`` hook and the dist-info
            extracted from that will be returned.
        Ú#prepare_metadata_for_build_editablerl   rm   rn   r   r   r   rv     s   ýþz:BuildBackendHookCaller.prepare_metadata_for_build_editablec                 C   rp   )añ  Build an editable wheel from this project.

        :param wheel_directory: The directory to write the wheel to
        :param config_settings: The configuration settings for the build backend
        :param metadata_directory: The directory to reuse existing metadata from
        :returns:
            The name of the newly created wheel within ``wheel_directory``.

        .. admonition:: Interaction with fallback

            If the ``build_editable`` hook was called in the fallback for
            :meth:`prepare_metadata_for_build_editable`, the build backend
            would not be invoked. Instead, the previously built wheel will be
            copied to ``wheel_directory`` and the name of that file will be
            returned.
        NÚbuild_editablerr   rs   rt   r   r   r   rw   ;  s   ýþz%BuildBackendHookCaller.build_editablec                 C   rd   )z…Get additional dependencies required for building an sdist.

        :returns: A list of :pep:`dependency specifiers <508>`.
        Úget_requires_for_build_sdistrc   ra   rf   r   r   r   rx   \  s   ÿz3BuildBackendHookCaller.get_requires_for_build_sdistÚsdist_directoryc                 C   s   |   dt|ƒ|dœ¡S )z‰Build an sdist from this project.

        :returns:
            The name of the newly created sdist within ``wheel_directory``.
        Úbuild_sdist)ry   rc   rm   )r   ry   rc   r   r   r   rz   h  s   
þþz"BuildBackendHookCaller.build_sdistr;   r*   c           
   	   C   s6  d| j i}| jrtj | j¡}||d< t ¡ �z}d|i}t|t|dƒdd� t	ƒ �}| j
}| j|tt|ƒƒ||g| j|d� W d   ƒ n1 sHw   Y  tt|dƒƒ}	|	 d	¡rat|	 d
d¡ƒ‚|	 d¡rxt|	 d
d¡|	 dd¡| j | jd�‚|	 d¡r†t|	 d¡p„|ƒ‚|	d W  d   ƒ S 1 s”w   Y  d S )NÚ_PYPROJECT_HOOKS_BUILD_BACKENDÚ_PYPROJECT_HOOKS_BACKEND_PATHr*   z
input.jsoné   )Úindent)r   r   zoutput.jsonÚunsupportedr0   Ú Ú
no_backendÚbackend_error)r1   r2   r3   Úhook_missingÚmissing_hook_nameÚ
return_val)rT   r3   r>   Úpathsepr   ÚtempfileÚTemporaryDirectoryr,   Úpjoinr   rV   r[   r   r    rS   r.   Úgetr<   r/   r:   )
r   r;   r*   r   r3   ÚtdÚ
hook_inputÚscriptÚpythonÚdatar   r   r   rb   z  s:   

ýþ



ü
$çz!BuildBackendHookCaller._call_hookr8   r   )NTr   )r   r   r   r   r    r   r   r5   r   r
   r_   r`   r   r	   re   Úboolrk   rq   ru   rv   rw   rx   rz   rb   r   r   r   r   rR   ~   s¸    úþý
üûú
ùþþ
ýüþýü
û$üþýü
û"þþ
ýüþýü
û#üþýü
û#þþ
ýýþý
ü"rR   r   )$r(   r>   r\   r‡   Ú
contextlibr   Úos.pathr   r   r‰   Ú
subprocessr   r   r   Útypingr   r	   r
   r   r   r   Ú_in_processr   r   r   r    r,   r.   Ú	Exceptionr/   r:   r<   rC   rE   rQ   rR   r   r   r   r   Ú<module>   sT     	ýÿþý
üýÿþý
ü