
    ?gX:              
          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rd d	lmZ  G d
 de      Zdeeef   deddfdZdedeeef   fdZ G d de      Z G d de      Z G d de      Z	 	 d!dee   dee   deeeef      ddfdZ 	 	 d!dee   dee   deeeef      ddfdZ!dededefdZ" G d d       Z#y)"    N)contextmanager)abspath)join)STDOUT
check_callcheck_output)TYPE_CHECKINGAnyIteratorMappingOptionalSequence   )_in_proc_script_path)Protocolc            
       J    e Zd ZdZ	 	 ddee   dee   deeeef      ddfdZy)	SubprocessRunnerz%A protocol for the subprocess runner.Ncmdcwdextra_environreturnc                      y N )selfr   r   r   s       J/var/www/openai/venv/lib/python3.12/site-packages/pyproject_hooks/_impl.py__call__zSubprocessRunner.__call__   s         NN)	__name__
__module____qualname____doc__r   strr   r   r   r   r   r   r   r      sN    3
 "&9=		#	 #	 $GCH$56		
 	r   r   objpathr   c                 x    t        |dd      5 }t        j                  | |fi | d d d        y # 1 sw Y   y xY w)Nwutf-8encoding)openjsondump)r%   r&   kwargsfs       r   
write_jsonr1      s/    	dC'	*a		#q#F# 
+	*	*s   09c                 r    t        | d      5 }t        j                  |      cd d d        S # 1 sw Y   y xY w)Nr)   r*   )r,   r-   load)r&   r0   s     r   	read_jsonr4   !   s%    	dW	%yy| 
&	%	%s   -6c                   X     e Zd ZdZ	 	 	 d	dedee   dee   deee      ddf
 fdZ xZS )
BackendUnavailablezEWill be raised if the backend cannot be imported in the hook process.N	tracebackmessagebackend_namebackend_pathr   c                 V    || _         || _        || _        t        |   |xs d       y )NzError while importing backend)r9   r:   r7   super__init__)r   r7   r8   r9   r:   	__class__s        r   r=   zBackendUnavailable.__init__)   s/     )("C$CDr   NNN)	r    r!   r"   r#   r$   r   r   r=   __classcell__r>   s   @r   r6   r6   &   sc    O
 "&&*04EE #E sm	E
 x}-E 
E Er   r6   c                   ,     e Zd ZdZdeddf fdZ xZS )HookMissingz>Will be raised on missing hooks (if a fallback can't be used).	hook_namer   Nc                 2    t         |   |       || _        y r   )r<   r=   rD   )r   rD   r>   s     r   r=   zHookMissing.__init__:   s    #"r   )r    r!   r"   r#   r$   r=   r@   rA   s   @r   rC   rC   7   s    H## #$ # #r   rC   c                        e Zd ZdZdeddfdZy)UnsupportedOperationzDMay be raised by build_sdist if the backend indicates that it can't.r7   r   Nc                     || _         y r   )r7   )r   r7   s     r   r=   zUnsupportedOperation.__init__B   s	    "r   )r    r!   r"   r#   r$   r=   r   r   r   rG   rG   ?   s    N## #$ #r   rG   r   r   r   c                     t         j                  j                         }|r|j                  |       t	        | ||       y)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   rJ   s       r   default_subprocess_runnerrP   F   s/     **//
C

=!s%r   c                     t         j                  j                         }|r|j                  |       t	        | ||t
               y)zqCall the subprocess while suppressing output.

    This uses :func:`subprocess.check_output` under the hood.
    )r   rJ   stderrN)rK   rL   rM   rN   r   r   rO   s       r   quiet_subprocess_runnerrS   V   s1     **//
C

=!#3v6r   source_tree	requestedc                    t         j                  j                  |      rt        d      t         j                  j	                  |       }t         j                  j                  t         j                  j                  ||            }t         j                  j                  |      }t         j                  j                  |      }t         j                  j                  ||g      |k7  rt        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)	rK   r&   isabs
ValueErrorr   normpathr   normcasecommonprefix)rT   rU   
abs_sourceabs_requestednorm_sourcenorm_requesteds         r   norm_and_checkr`   f   s     
ww}}Y122-JGG$$RWW\\*i%HIM ''"":.KWW%%m4N	ww[.9:kI;<<r   c                      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
Zeddd	e	d   fd       Z
d	ee   fdZ	 ddeeeef      d	ee   fdZ	 	 ddedeeeef      ded	efdZ	 	 d dedeeeef      dee   d	efdZ	 ddeeeef      d	ee   fdZ	 	 ddedeeeef      ded	ee   fdZ	 	 d dedeeeef      dee   d	efdZ	 ddeeeef      d	ee   fdZ	 ddedeeeef      d	efdZdedeeef   d	efdZy)!BuildBackendHookCallerzAA wrapper to call the build backend hooks for a source directory.N
source_dirbuild_backendr:   runnerr   python_executabler   c                     |t         }t        |      | _        || _        |r#|D cg c]  }t	        | j                  |       }}|| _        || _        |st        j                  }|| _	        yc c}w )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
        N)
rP   r   rc   rd   r`   r:   _subprocess_runnersys
executablerf   )r   rc   rd   r:   re   rf   ps          r   r=   zBuildBackendHookCaller.__init__   so      >.F!*-*HTU1N4??A>LU("(  #!2 Vs   A-c              #   b   K   | j                   }|| _         	 d || _         y# || _         w xY w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)rh   )r   re   prevs      r   subprocess_runnerz(BuildBackendHookCaller.subprocess_runner   s3      &&"(	+&*D#dD#s   /# /	,/c                 &    | j                  di       S )z>Return the list of optional features supported by the backend._supported_features
_call_hook)r   s    r   rp   z*BuildBackendHookCaller._supported_features   s    4b99r   config_settingsc                 *    | j                  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_wheelrs   rq   r   rs   s     r   ru   z3BuildBackendHookCaller.get_requires_for_build_wheel   s      *->,P
 	
r   metadata_directory_allow_fallbackc                 @    | j                  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rw   rs   rx   rr   r   r   rw   rs   rx   s       r   rz   z7BuildBackendHookCaller.prepare_metadata_for_build_wheel   s,    0 .&-.@&A#2#2
 	
r   wheel_directoryc                 Z    |t        |      }| j                  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.
        build_wheelr~   rs   rw   r   rr   r   r~   rs   rw   s       r   r   z"BuildBackendHookCaller.build_wheel   s=    * )!();!<#*?#;#2&8
 	
r   c                 *    | j                  dd|i      S )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_editablers   rq   rv   s     r   r   z6BuildBackendHookCaller.get_requires_for_build_editable	  s      -0A?/S
 	
r   c                 @    | j                  dt        |      ||d      S )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_editabler{   r|   r}   s       r   r   z:BuildBackendHookCaller.prepare_metadata_for_build_editable  s,    . 1&-.@&A#2#2
 	
r   c                 Z    |t        |      }| j                  dt        |      ||d      S )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.
        build_editabler   r   r   s       r   r   z%BuildBackendHookCaller.build_editable;  s=    , )!();!<#*?#;#2&8
 	
r   c                 *    | j                  dd|i      S )zGet additional dependencies required for building an sdist.

        :returns: A list of :pep:`dependency specifiers <508>`.
        get_requires_for_build_sdistrs   rq   rv   s     r   r   z3BuildBackendHookCaller.get_requires_for_build_sdist\  s      *->,P
 	
r   sdist_directoryc                 >    | j                  dt        |      |d      S )zBuild an sdist from this project.

        :returns:
            The name of the newly created sdist within ``wheel_directory``.
        build_sdist)r   rs   r|   )r   r   rs   s      r   r   z"BuildBackendHookCaller.build_sdisth  s(     #*?#;#2
 	
r   rD   r/   c           
      n   d| j                   i}| j                  r.t        j                  j	                  | j                        }||d<   t        j                         5 }d|i}t        |t        |d      d       t               5 }| j                  }| j                  |t        t        |            ||g| j                  |       d d d        t        t        |d            }	|	j!                  d	      rt#        |	j!                  d
d            |	j!                  d      rCt%        |	j!                  d
d      |	j!                  dd      | j                   | j                        |	j!                  d      rt'        |	j!                  d      xs |      |	d   cd d d        S # 1 sw Y   xY w# 1 sw Y   y xY w)N_PYPROJECT_HOOKS_BUILD_BACKEND_PYPROJECT_HOOKS_BACKEND_PATHr/   z
input.json   )indent)r   r   zoutput.jsonunsupportedr7    
no_backendbackend_error)r8   r9   r:   hook_missingmissing_hook_name
return_val)rd   r:   rK   pathsepr   tempfileTemporaryDirectoryr1   pjoinr   rf   rh   r   r$   rc   r4   getrG   r6   rC   )
r   rD   r/   r   r:   td
hook_inputscriptpythondatas
             r   rr   z!BuildBackendHookCaller._call_hookz  s{   94;M;MN::??4+<+<=L=IM9:((*b"F+Jz5\#:1E &'6//''WS[19bA"/ (  ( U2}56Dxx&*488K+DEExx%(HH["- HH_b9!%!3!3!%!2!2	  xx'!$((+>"?"L9MM%3 +*
 (' +*s&   'F+AFCF+F(	$F++F4r?   r   )NTr   )r    r!   r"   r#   r$   r   r   r=   r   r   rn   rp   r   r
   ru   boolrz   r   r   r   r   r   r   rr   r   r   r   rb   rb   ~   s   K 15/3+/33 3 x}-	3
 +,3 $C=3 
3: +(: +x~ + +&:Xc] : 8<
!'#s("34
 
#
* 8< $	

 "'#s("34
 	

 

H 8<,0	

 "'#s("34
 %SM	

 

D 8<
!'#s("34
 
#
* 8< $	

 "'#s("34
 	

 
#
F 8<,0	

 "'#s("34
 %SM	

 

F 8<

!'#s("34

 
#

 8<

 "'#s("34
 
	
$ &C  &c1B  &s  &r   rb   r   )$r-   rK   ri   r   
contextlibr   os.pathr   r   r   
subprocessr   r   r   typingr	   r
   r   r   r   r   _in_processr   r   r   r$   r1   r4   	Exceptionr6   rC   rG   rP   rS   r`   rb   r   r   r   <module>r      sT    	 
  %  ! 7 7 L L -	8 	$GCH% $S $t $
C GCH- 
E E"#) ##9 # 15&	#&	#& GCH-.& 
	&$ 157	#7	#7 GCH-.7 
	7    0\& \&r   