o
    a+)h.                     @   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 dd	 Zd
d ZG dd deZG dd deZG dd deZG dd deZdddZdddZdd ZG dd dZdS )    N)contextmanager)abspath)join)STDOUT
check_callcheck_output   )_in_proc_script_pathc                 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)objpathkwargsf r   `C:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\pip/_vendor/pyproject_hooks/_impl.py
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                   @      e Zd ZdZdd ZdS )BackendUnavailablezEWill be raised if the backend cannot be imported in the hook process.c                 C   
   || _ d S N	tracebackselfr   r   r   r   __init__      
zBackendUnavailable.__init__N__name__
__module____qualname____doc__r"   r   r   r   r   r          r   c                           e Zd ZdZ fddZ  ZS )BackendInvalidz)Will be raised if the backend is invalid.c                    s   t  | || _|| _d S r   )superr"   backend_namebackend_path)r!   r-   r.   message	__class__r   r   r"      s   
zBackendInvalid.__init__r%   r&   r'   r(   r"   __classcell__r   r   r0   r   r+          r+   c                       r*   )HookMissingz>Will be raised on missing hooks (if a fallback can't be used).c                    s   t  | || _d S r   )r,   r"   	hook_name)r!   r6   r0   r   r   r"   '   s   
zHookMissing.__init__r2   r   r   r0   r   r5   %   r4   r5   c                   @   r   )UnsupportedOperationzDMay be raised by build_sdist if the backend indicates that it can't.c                 C   r   r   r   r    r   r   r   r"   .   r#   zUnsupportedOperation.__init__Nr$   r   r   r   r   r7   ,   r)   r7   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.
    )cwdenvN)osenvironcopyupdater   cmdr8   extra_environr9   r   r   r   default_subprocess_runner2   s   

rA   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.
    )r8   r9   stderrN)r:   r;   r<   r=   r   r   r>   r   r   r   quiet_subprocess_runner>   s   

rC   c                 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)source_tree	requested
abs_sourceabs_requestednorm_sourcenorm_requestedr   r   r   norm_and_checkJ   s   rO   c                   @   s   e Zd ZdZ			dddZedd Zdd Zdd	d
Z		dddZ			dddZ
dddZ		dddZ		dddZdddZdddZdd ZdS ) BuildBackendHookCallerzFA wrapper to call the build backend hooks for a source directory.
    Nc                    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   )rO   
source_dir).0pr!   r   r   
<listcomp>|   s    z3BuildBackendHookCaller.__init__.<locals>.<listcomp>)	rA   r   rQ   build_backendr.   _subprocess_runnersys
executablepython_executable)r!   rQ   rV   r.   runnerrZ   r   rT   r   r"   f   s   


zBuildBackendHookCaller.__init__c                 c   s*    | j }|| _ z	dV  W || _ dS || _ w )a,  A context manager for temporarily overriding the default
        :ref:`subprocess runner <Subprocess Runners>`.

        .. code-block:: python

            hook_caller = BuildBackendHookCaller(...)
            with hook_caller.subprocess_runner(quiet_subprocess_runner):
                ...
        N)rW   )r!   r[   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_hookrT   r   r   r   r^      s   z*BuildBackendHookCaller._supported_featuresc                 C      |  dd|iS )a6  Get additional dependencies required for building a wheel.

        :returns: A list of :pep:`dependency specifiers <508>`.
        :rtype: list[str]

        .. admonition:: Fallback

            If the build backend does not defined a hook with this name, an
            empty list will be returned.
        get_requires_for_build_wheelconfig_settingsr_   r!   rc   r   r   r   rb         z3BuildBackendHookCaller.get_requires_for_build_wheelTc                 C      |  dt|||dS )a  Prepare a ``*.dist-info`` folder with metadata for this project.

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

        .. 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metadata_directoryrc   _allow_fallbackr`   r   r!   ri   rc   rj   r   r   r   rg      
   z7BuildBackendHookCaller.prepare_metadata_for_build_wheelc                 C   (   |durt |}| dt |||dS )a  Build a wheel from this project.

        :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wheel_directoryrc   ri   r   r`   r!   rq   rc   ri   r   r   r   ro      s   z"BuildBackendHookCaller.build_wheelc                 C   ra   )a@  Get additional dependencies required for building an editable wheel.

        :returns: A list of :pep:`dependency specifiers <508>`.
        :rtype: list[str]

        .. 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   r_   rd   r   r   r   rt      re   z6BuildBackendHookCaller.get_requires_for_build_editablec                 C   rf   )a  Prepare a ``*.dist-info`` folder with metadata for this project.

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

        .. 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_editablerh   rk   rl   r   r   r   ru      rm   z:BuildBackendHookCaller.prepare_metadata_for_build_editablec                 C   rn   )a  Build an editable wheel from this project.

        :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_editablerp   rr   rs   r   r   r   rv      s   z%BuildBackendHookCaller.build_editablec                 C   ra   )zGet additional dependencies required for building an sdist.

        :returns: A list of :pep:`dependency specifiers <508>`.
        :rtype: list[str]
        get_requires_for_build_sdistrc   r_   rd   r   r   r   rw     s   z3BuildBackendHookCaller.get_requires_for_build_sdistc                 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)sdist_directoryrc   rk   )r!   ry   rc   r   r   r   rx     s   z"BuildBackendHookCaller.build_sdistc           
   	   C   sF  d| j i}| jrtj| j}||d< t }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rnt|	d
d|	drt| j | j|	ddd|	drt|	dp||	d W  d    S 1 sw   Y  d S )NPEP517_BUILD_BACKENDPEP517_BACKEND_PATHr   z
input.json   )indent)r8   r@   zoutput.jsonunsupportedr    
no_backendbackend_invalidbackend_error)r-   r.   r/   hook_missingmissing_hook_name
return_val)rV   r.   r:   pathsepr   tempfileTemporaryDirectoryr   pjoinr	   rZ   rW   r   strrQ   r   getr7   r   r+   r5   )
r!   r6   r   r@   r.   td
hook_inputscriptpythondatar   r   r   r`   )  s<   






$z!BuildBackendHookCaller._call_hook)NNNr   )NTNN)r%   r&   r'   r(   r"   r   r]   r^   rb   rg   ro   rt   ru   rv   rw   rx   r`   r   r   r   r   rP   b   s4    










rP   r   )r   r:   rX   r   
contextlibr   Zos.pathr   r   r   
subprocessr   r   r   _in_processr	   r   r   	Exceptionr   r+   r5   r7   rA   rC   rO   rP   r   r   r   r   <module>   s&    

