o
    ˍ>e1                     @   s  d dl Z 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 g d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G dd dejZdS )     N)contextmanager)abspath)join)STDOUT
check_callcheck_output   )_in_proc_script_path)BackendUnavailableBackendInvalidHookMissingUnsupportedOperationdefault_subprocess_runnerquiet_subprocess_runnerPep517HookCallerc                 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   \/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/pip/_vendor/pep517/wrappers.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 )r
   zEWill 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                   @   r!   )r   z)Will be raised if the backend is invalid.c                 C   s   || _ || _|| _d S r#   backend_namebackend_pathmessage)r'   r1   r2   r3   r   r   r   r(   *   s   
zBackendInvalid.__init__Nr*   r   r   r   r   r   (   r/   r   c                       s    e Zd ZdZ fddZ  ZS )r   z Will be raised on missing hooks.c                    s   t  | || _d S r#   )superr(   	hook_name)r'   r5   	__class__r   r   r(   2   s   
zHookMissing.__init__)r+   r,   r-   r.   r(   __classcell__r   r   r6   r   r   0   s    r   c                   @   r!   )r   zDMay be raised by build_sdist if the backend indicates that it can't.c                 C   r"   r#   r$   r&   r   r   r   r(   9   r)   zUnsupportedOperation.__init__Nr*   r   r   r   r   r   7   r/   r   c                 C   s*   t j }|r|| t| ||d dS )z5The default method of calling the wrapper subprocess.)cwdenvN)osenvironcopyupdater   cmdr9   extra_environr:   r   r   r   r   =   s   

r   c                 C   s,   t j }|r|| t| ||td dS )zDA method of calling the wrapper subprocess while suppressing output.)r9   r:   stderrN)r;   r<   r=   r>   r   r   r?   r   r   r   r   F   s   

r   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)Zsource_treeZ	requestedZ
abs_sourceZabs_requestedZnorm_sourceZnorm_requestedr   r   r   norm_and_checkO   s   rH   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 ) r   a  A wrapper around a source directory to be built with a PEP 517 backend.

    :param source_dir: The path to the source directory, containing
        pyproject.toml.
    :param build_backend: The build backend spec, as per PEP 517, from
        pyproject.toml.
    :param backend_path: The backend path, as per PEP 517, from pyproject.toml.
    :param runner: A callable that invokes the wrapper subprocess.
    :param python_executable: The Python executable used to invoke the backend

    The 'runner', if provided, must expect the following:

    - cmd: a list of strings representing the command and arguments to
      execute, as would be passed to e.g. 'subprocess.check_call'.
    - cwd: a string representing the working directory that must be
      used for the subprocess. Corresponds to the provided source_dir.
    - extra_environ: a dict mapping environment variable names to values
      which must be set for the subprocess execution.
    Nc                    sR   |d u rt }t| _| _|r fdd|D }| _| _|s$tj}| _d S )Nc                    s   g | ]}t  j|qS r   )rH   
source_dir).0pr'   r   r   
<listcomp>   s    z-Pep517HookCaller.__init__.<locals>.<listcomp>)	r   r   rI   build_backendr2   _subprocess_runnersys
executablepython_executable)r'   rI   rN   r2   runnerrR   r   rL   r   r(   {   s   


zPep517HookCaller.__init__c                 c   s*    | j }|| _ z	dV  W || _ dS || _ w )z\A context manager for temporarily overriding the default subprocess
        runner.
        N)rO   )r'   rS   prevr   r   r   subprocess_runner   s   z"Pep517HookCaller.subprocess_runnerc                 C   s   |  di S )z>Return the list of optional features supported by the backend._supported_features
_call_hookrL   r   r   r   rV      s   z$Pep517HookCaller._supported_featuresc                 C      |  dd|iS )aI  Identify packages required for building a wheel

        Returns a list of dependency specifications, e.g.::

            ["wheel >= 0.25", "setuptools"]

        This does not include requirements specified in pyproject.toml.
        It returns the result of calling the equivalently named hook in a
        subprocess.
        get_requires_for_build_wheelconfig_settingsrW   r'   r[   r   r   r   rZ         z-Pep517HookCaller.get_requires_for_build_wheelTc                 C      |  dt|||dS )au  Prepare a ``*.dist-info`` folder with metadata for this project.

        Returns the name of the newly created folder.

        If the build backend defines a hook with this name, it will be called
        in a subprocess. If not, the backend will be asked to build a wheel,
        and the dist-info extracted from that (unless _allow_fallback is
        False).
         prepare_metadata_for_build_wheelmetadata_directoryr[   _allow_fallbackrX   r   r'   ra   r[   rb   r   r   r   r_      
   z1Pep517HookCaller.prepare_metadata_for_build_wheelc                 C   (   |durt |}| dt |||dS )av  Build a wheel from this project.

        Returns the name of the newly created file.

        In general, this will call the 'build_wheel' hook in the backend.
        However, if that was previously called by
        'prepare_metadata_for_build_wheel', and the same metadata_directory is
        used, the previously built wheel will be copied to wheel_directory.
        Nbuild_wheelwheel_directoryr[   ra   r   rX   r'   ri   r[   ra   r   r   r   rg         zPep517HookCaller.build_wheelc                 C   rY   )aS  Identify packages required for building an editable wheel

        Returns a list of dependency specifications, e.g.::

            ["wheel >= 0.25", "setuptools"]

        This does not include requirements specified in pyproject.toml.
        It returns the result of calling the equivalently named hook in a
        subprocess.
        get_requires_for_build_editabler[   rW   r\   r   r   r   rm      r]   z0Pep517HookCaller.get_requires_for_build_editablec                 C   r^   )a  Prepare a ``*.dist-info`` folder with metadata for this project.

        Returns the name of the newly created folder.

        If the build backend defines a hook with this name, it will be called
        in a subprocess. If not, the backend will be asked to build an editable
        wheel, and the dist-info extracted from that (unless _allow_fallback is
        False).
        #prepare_metadata_for_build_editabler`   rc   rd   r   r   r   rn      re   z4Pep517HookCaller.prepare_metadata_for_build_editablec                 C   rf   )a  Build an editable wheel from this project.

        Returns the name of the newly created file.

        In general, this will call the 'build_editable' hook in the backend.
        However, if that was previously called by
        'prepare_metadata_for_build_editable', and the same metadata_directory
        is used, the previously built wheel will be copied to wheel_directory.
        Nbuild_editablerh   rj   rk   r   r   r   ro      rl   zPep517HookCaller.build_editablec                 C   rY   )a>  Identify packages required for building a wheel

        Returns a list of dependency specifications, e.g.::

            ["setuptools >= 26"]

        This does not include requirements specified in pyproject.toml.
        It returns the result of calling the equivalently named hook in a
        subprocess.
        get_requires_for_build_sdistr[   rW   r\   r   r   r   rp     r]   z-Pep517HookCaller.get_requires_for_build_sdistc                 C   s   |  dt||dS )zBuild an sdist from this project.

        Returns the name of the newly created file.

        This calls the 'build_sdist' backend hook in a subprocess.
        build_sdist)sdist_directoryr[   rc   )r'   rr   r[   r   r   r   rq     s   zPep517HookCaller.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 )NZPEP517_BUILD_BACKENDZPEP517_BACKEND_PATHr   z
input.json   )indent)r9   rA   zoutput.jsonZunsupportedr%    Z
no_backendZbackend_invalidZbackend_errorr0   Zhook_missingZmissing_hook_nameZ
return_val)rN   r2   r;   pathsepr   tempfileTemporaryDirectoryr   pjoinr	   rR   rO   r   strrI   r    getr   r
   r   r   )
r'   r5   r   rA   r2   ZtdZ
hook_inputZscriptpythondatar   r   r   rX   '  s<   






$zPep517HookCaller._call_hook)NNNr#   NTNN)r+   r,   r-   r.   r(   r   rU   rV   rZ   r_   rg   rm   rn   ro   rp   rq   rX   r   r   r   r   r   g   s4    









r   c                   @   s<   e Zd ZdZdd Zdd Zedd Zdd	 Zd
d Z	dS )LoggerWrapperzd
    Read messages from a pipe and redirect them
    to a logger (see python's logging module).
    c                 C   sH   t j|  d| _|| _|| _t \| _| _	t
| j| _|   d S r~   )	threadingThreadr(   daemonloggerlevelr;   pipeZfd_readfd_writefdopenreaderstart)r'   r   r   r   r   r   r(   Q  s   zLoggerWrapper.__init__c                 C   s   | j S r#   )r   rL   r   r   r   fileno^  s   zLoggerWrapper.filenoc                 C   s   |  tjr| d d S | S )N)endswithr;   linesep)msgr   r   r   remove_newlinea  s   zLoggerWrapper.remove_newlinec                 C   s    | j D ]
}| | | qd S r#   )r   _writer   )r'   liner   r   r   rune  s   
zLoggerWrapper.runc                 C   s   | j | j| d S r#   )r   logr   )r'   r3   r   r   r   r   i  s   zLoggerWrapper._writeN)
r+   r,   r-   r.   r(   r   staticmethodr   r   r   r   r   r   r   r   K  s    
r   r   )r   r;   rP   rw   r   
contextlibr   Zos.pathr   r   ry   
subprocessr   r   r   Z
in_processr	   __all__r   r    	Exceptionr
   r   r   r   r   r   rH   r   r   r   r   r   r   r   <module>   s.    

		 e