
    g4                    ,   d dl mZ d dlZd dlZ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mZmZmZ d dlZddlmZmZ ddlmZ ddlmZmZmZmZ dd	lmZmZmZmZ dd
l m!Z!m"Z"  edd      Z#ddgdZ$ddZ%ddZ&ddZ'ddZ(ddZ) G d d      Z*y)    )annotationsN)Iterator)AnyMappingSequenceTypeVar   )_ctxenv)tomllib)BuildBackendExceptionBuildExceptionBuildSystemTableValidationErrorTypoWarning)ConfigSettingsDistributionStrPathSubprocessRunner)check_dependencyparse_wheel_filename_TProjectBuilderProjectBuilder)boundz setuptools.build_meta:__legacy__zsetuptools >= 40.8.0)build-backendrequiresc                    | D ]N  }t        j                  d ||      j                         dk\  s,t        j                  d| d| dt
        d       P y )Ng?zFound 'z#' in pyproject.toml, did you mean 'z'?   )
stacklevel)difflibSequenceMatcherratiowarningswarnr   )
dictionaryexpectedobjs      C/var/www/openai/venv/lib/python3.12/site-packages/build/_builder.py
_find_typor(   '   sQ    ""437==?3FMM#A(2N     c                   t         j                  j                  |       sd|  d}t        |      t         j                  j	                  | d      }t         j                  j	                  | d      }t         j                  j                  |      s1t         j                  j                  |      sd|  d}t        |      y y )NzSource z is not a directorypyproject.tomlzsetup.pyzF does not appear to be a Python project: no pyproject.toml or setup.py)ospathisdirr   joinexists)
source_dirmsgpyproject_tomlsetup_pys       r'   _validate_source_directoryr5   1   s    77==$
|#67S!!WW\\*.>?Nww||J
3H77>>.)"''..2J
|#ijS!! 3K)r)   c                   	 t        | d      5 }t        j                  |j                         j	                               cd d d        S # 1 sw Y   y xY w# t
        $ r i cY S t        $ r-}|j                   d|j                   d}t        |      d d }~wt        j                  $ r}d|  d| d}t        |      d d }~ww xY w)Nrbz: 'z' zFailed to parse z:  )openr   loadsreaddecodeFileNotFoundErrorPermissionErrorstrerrorfilenamer   TOMLDecodeError)r-   fer2   s       r'   _read_pyproject_tomlrD   <   s    
,$==!23  	 ,C

|2.S!t+"" , b1-S!t+,sE   A 1A		A 	AA A C"C*(BC(B==Cc                J   d| vrt        | d       t        S t        | d         }d|vrt        |d       d}t        |      t	        |d   t
              rt        d |d   D              sd}t        |      d|vrt        |d       t        d   |d<   n t	        |d   t              sd}t        |      d|v r5t	        |d   t
              rt        d	 |d   D              sd
}t        |      |j                         h dz
  }|rddj                  |       }t        |      |S )Nzbuild-systemr   z!`requires` is a required propertyc              3  <   K   | ]  }t        |t                y wN
isinstancestr.0is     r'   	<genexpr>z,_parse_build_system_table.<locals>.<genexpr>X   s      I$Bq
1c$B   z&`requires` must be an array of stringsr   z `build-backend` must be a stringbackend-pathc              3  <   K   | ]  }t        |t                y wrG   rH   rK   s     r'   rN   z,_parse_build_system_table.<locals>.<genexpr>i   s     R/Q!:a%/QrO   z*`backend-path` must be an array of strings>   r   rP   r   zUnknown properties: z, )
r(   _DEFAULT_BACKENDdictr   rI   listallrJ   keysr/   )r3   build_system_tabler2   unknown_propss       r'   _parse_build_system_tablerY   J   sQ    ^+>>2n^<= ++%z21-c22*:6=S I$6z$BI F 7-c2200%7 /?.O?+*?;SA0-c22++).94@R/A./QRR:-c22&++-0]]M$TYY}%=$>?-c22r)   c                *     	 d	 	 	 	 	 	 	 d fd}|S )Nc                P     | |i  j                          xs i |xs i        y rG   )make_extra_environ)cmdcwdextra_environr   runners      r'   _invoke_wrapped_runnerz7_wrap_subprocess_runner.<locals>._invoke_wrapped_runnerw   s3     	sCV3S335;VATRTVWr)   NN)r]   zSequence[str]r^   
str | Noner_   zMapping[str, str] | NonereturnNone )r`   r   ra   s   `` r'   _wrap_subprocess_runnerrg   v   s8    ^bXX!+XC[X	X
 "!r)   c                  x   e Zd ZdZej
                  ej                  f	 	 	 	 	 	 	 ddZe	ej                  f	 	 	 	 	 	 	 	 	 dd       Z
edd       Zedd       Zedd       Z	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 dd	Z	 d	 	 	 	 	 	 	 dd
Z	 	 d	 	 	 	 	 	 	 	 	 ddZddZ	 d	 	 	 	 	 	 	 	 	 ddZej,                  dd       Zy)r   z#
    The PEP 517 consumer API.
    c                   t         j                  j                  |      | _        t	        |       || _        || _        t         j                  j                  |d      }t        t        |            | _
        | j                  d   | _        t        j                  | j                  | j                  | j                  j                  d      | j
                  | j                        | _        y)aA  
        :param source_dir: The source directory
        :param python_executable: The python executable where the backend lives
        :param runner: Runner for backend subprocesses

        The ``runner``, if provided, must accept the following arguments:

        - ``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.

        The default runner simply calls the backend hooks in a subprocess, writing backend output
        to stdout/stderr.
        r+   r   rP   )backend_pathpython_executabler`   N)r,   r-   abspath_source_dirr5   _python_executable_runnerr/   rY   rD   _build_system_backendpyproject_hooksBuildBackendHookCallerget_hook)selfr1   rk   r`   pyproject_toml_paths        r'   __init__zProjectBuilder.__init__   s    . !#
 ;":."3 ggll:7GH67KL_7`a**?;$;;MM++//?"55<<

r)   c                @     | ||j                   t        ||            S )N)r1   rk   r`   )rk   rg   )clsr   r1   r`   s       r'   from_isolated_envz ProjectBuilder.from_isolated_env   s'     !!33*637
 	
r)   c                    | j                   S )zProject source directory.)rm   rv   s    r'   r1   zProjectBuilder.source_dir   s     r)   c                    | j                   S )zC
        The Python executable used to invoke the backend.
        )rn   r}   s    r'   rk   z ProjectBuilder.python_executable   s    
 &&&r)   c                2    t        | j                  d         S )z
        The dependencies defined in the ``pyproject.toml``'s
        ``build-system.requires`` field or the default build dependencies
        if ``pyproject.toml`` is missing or ``build-system`` is undefined.
        r   )setrp   r}   s    r'   build_system_requiresz$ProjectBuilder.build_system_requires   s     4%%j122r)   Nc                    t        j                  d| d       d| }t        | j                  |      }| j	                  |      5  t         ||            cddd       S # 1 sw Y   yxY w)a@  
        Return the dependencies defined by the backend in addition to
        :attr:`build_system_requires` for a given distribution.

        :param distribution: Distribution to get the dependencies of
            (``sdist`` or ``wheel``)
        :param config_settings: Config settings for the build backend
        zGetting build dependencies for ...get_requires_for_build_N)r
   loggetattrru   _handle_backendr   )rv   distributionconfig_settings	hook_nameget_requiress        r'   get_requires_for_buildz%ProjectBuilder.get_requires_for_build   s]     	2<.DE-l^<	tzz95!!),|O45 -,,s   A!!A*c                    | j                  ||      j                  | j                        }|D ch c]  }t        |      D ]  }|  c}}S c c}}w )a  
        Return the dependencies which are not satisfied from the combined set of
        :attr:`build_system_requires` and :meth:`get_requires_for_build` for a given
        distribution.

        :param distribution: Distribution to check (``sdist`` or ``wheel``)
        :param config_settings: Config settings for the build backend
        :returns: Set of variable-length unmet dependency tuples
        )r   unionr   r   )rv   r   r   dependenciesdus         r'   check_dependenciesz!ProjectBuilder.check_dependencies   sO     22<QWWX\XrXrs'E<a1A!1DA1D<EEEs   Ac                    t        j                  d| d       	 | j                  d| ||d      S # t        $ r/}t	        |j
                  t        j                        rY d}~y d}~ww xY w)aR  
        Prepare metadata for a distribution.

        :param distribution: Distribution to build (must be ``wheel``)
        :param output_directory: Directory to put the prepared metadata in
        :param config_settings: Config settings for the build backend
        :returns: The full path to the prepared metadata directory
        zGetting metadata for r   prepare_metadata_for_build_F)_allow_fallbackN)r
   r   _call_backendr   rI   	exceptionrr   HookMissing)rv   r   output_directoryr   r   s        r'   preparezProjectBuilder.prepare   sx     	(c:;
	%%-l^<  %	 &   % 	)--/J/JK	s   3 	A+$A&%A&&A+c                t    t        j                  d| d       |i nd|i} | j                  d| ||fi |S )a  
        Build a distribution.

        :param distribution: Distribution to build (``sdist`` or ``wheel``)
        :param output_directory: Directory to put the built distribution in
        :param config_settings: Config settings for the build backend
        :param metadata_directory: If provided, should be the return value of a
            previous ``prepare`` call on the same ``distribution`` kind
        :returns: The full path to the built distribution
        z	Building r   metadata_directorybuild_)r
   r   r   )rv   r   r   r   r   kwargss         r'   buildzProjectBuilder.build  sQ    " 	9\N#./)18LN`7a!t!!F<."9;K_g`fggr)   c                   | j                  d|      }||S | j                  d|      }t        t        j                  j                  |            }|sd}t        |      |d    d|d    d}| dt        j                  |      5 }|j                  |fd	|j                         D               ddd       t        j                  j                  ||      S # 1 sw Y   )xY w)
a  
        Generate the metadata directory of a distribution and return its path.

        If the backend does not support the ``prepare_metadata_for_build_wheel``
        hook, a wheel will be built and the metadata will be extracted from it.

        :param output_directory: Directory to put the metadata distribution in
        :returns: The path of the metadata directory
        wheelNzInvalid wheelr   -versionz
.dist-info/c              3  F   K   | ]  }|j                        s|  y wrG   )
startswith)rL   membermember_prefixs     r'   rN   z/ProjectBuilder.metadata_path.<locals>.<genexpr>?  s     WlFf6G6G6Vls   !!)r   r   r   r,   r-   basename
ValueErrorzipfileZipFile
extractallnamelistr/   )	rv   r   metadatar   matchr2   distinfowr   s	           @r'   metadata_pathzProjectBuilder.metadata_path%  s     <<)9:O 

7$45$RWW%5%5e%<=!CS/!N+,AeI.>-?zJ#*A__U#qLL WajjlW $
 ww||,h77 $#s   	*CC$c                   t         j                  j                  |      }t        | j                  |      }t         j                  j                  |      r0t         j                  j                  |      s&d| d}t        |      t        j                  |       | j                  |      5   |||fi |}d d d        t         j                  j                  |      S # 1 sw Y   )xY w)NzBuild path 'z' exists and is not a directory)r,   r-   rl   r   ru   r0   r.   r   makedirsr   r/   )rv   r   outdirr   r   callbackr2   r   s           r'   r   zProjectBuilder._call_backendC  s     (4::y177>>&!77==($VH,KL$S))KK!!),$V_GGH - ww||FH-- -,s   +CC'c              #  L  K   	 d  y # t         j                  $ r3}t        |d| j                   dt	        j
                               d d }~wt        j                  $ r}t        |d|       d d }~wt        $ r%}t        |t	        j
                               d d }~ww xY ww)Nz	Backend 'z' is not available.z0Backend subprocess exited when trying to invoke )exc_info)	rr   BackendUnavailabler   rq   sysr   
subprocessCalledProcessError	Exception)rv   hookr   s      r'   r   zProjectBuilder._handle_backendV  s     	V11 	'DMM?*=> 	
 ,, 	x'	5efjek3lmsww 	V'	CLLNKQUU	Vs<   B$	 B$B!.A

B! A00B!< BB!!B$)r1   r   rk   rJ   r`   r   rd   re   )
rz   ztype[_TProjectBuilder]r   env.IsolatedEnvr1   r   r`   r   rd   r   )rd   rJ   )rd   set[str]rG   )r   r   r   ConfigSettings | Nonerd   r   )r   r   r   r   rd   zset[tuple[str, ...]])r   r   r   r   r   r   rd   rc   rb   )
r   r   r   r   r   r   r   rc   rd   rJ   )r   r   rd   rJ   )
r   rJ   r   r   r   r   r   r   rd   rJ   )r   rJ   rd   zIterator[None])__name__
__module____qualname____doc__r   
executablerr   default_subprocess_runnerrx   classmethodr{   propertyr1   rk   r   r   r   r   r   r   r   
contextlibcontextmanagerr   rf   r)   r'   r   r      s    "%#2#L#L	(
(
 (
 !	(

 
(
T 
 $3#L#L	

#



 

 !	


 


 

     ' ' 3 3 266"6 /6 
	6. 26F"F /F 
	F* 26	" " /	
 
> 26)-h"h "h /	h
 'h 
h*8> Y]..&-.@U.hk.	.& V Vr)   )r$   zMapping[str, str]r%   rJ   rd   re   )r1   r   rd   re   )r-   r   rd   Mapping[str, Any])r3   r   rd   r   )r`   r   r   r   rd   r   )+
__future__r   r   r   r,   r   r   r"   r   collections.abcr   typingr   r   r   r   rr    r
   r   _compatr   _exceptionsr   r   r   r   _typesr   r   r   r   _utilr   r   r   rR   r(   r5   rD   rY   rg   r   rf   r)   r'   <module>r      s    #   	  
   $ 2 2     L K 9 -5EF  8'( ",)X"dV dVr)   