o
    UhX:                  
   @   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   i/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/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 )zNormalise 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   )zGet 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 )zBuild 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rt|	dp||	d W  d    S 1 sw   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     	

