o
    Vh4                     @  s(  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dZ#ddgdZ$d+ddZ%d,ddZ&d-dd Z'd.d"d#Z(d/d(d)Z)G d*d dZ*dS )0    )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requires
dictionaryMapping[str, str]expectedstrreturnNonec                 C  sB   | D ]}t d || dkrtjd| d| dtdd qd S )Ng?zFound 'z#' in pyproject.toml, did you mean 'z'?   )
stacklevel)difflibSequenceMatcherratiowarningswarnr   )r   r   obj r)   b/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/build/_builder.py
_find_typo'   s   r+   
source_dirr   c                 C  sp   t j| sd|  d}t|t j| d}t j| d}t j|s4t j|s6d|  d}t|d S d S )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)r,   msgpyproject_tomlsetup_pyr)   r)   r*   _validate_source_directory1   s   r6   r/   Mapping[str, Any]c              
   C  s   z"t | d}t|  W  d    W S 1 sw   Y  W d S  ty-   i  Y S  tyG } z|j d|j d}t	|d d }~w tj
ya } zd|  d| d}t	|d d }~ww )Nrbz: 'z' zFailed to parse z:  )openr   loadsreaddecodeFileNotFoundErrorPermissionErrorstrerrorfilenamer   TOMLDecodeError)r/   fer3   r)   r)   r*   _read_pyproject_toml<   s   (

rE   r4   c                 C  s  d| vrt | d tS t| d }d|vr t |d d}t|t|d tr2tdd |d D s8d}t|d|vrHt |d td |d< nt|d tsUd}t|d	|v rqt|d	 trktd
d |d	 D sqd}t|| h d }|rdd	| }t||S )Nzbuild-systemr   z!`requires` is a required propertyc                 s      | ]}t |tV  qd S N
isinstancer   .0ir)   r)   r*   	<genexpr>X   s    

z,_parse_build_system_table.<locals>.<genexpr>z&`requires` must be an array of stringsr   z `build-backend` must be a stringbackend-pathc                 s  rF   rG   rH   rJ   r)   r)   r*   rM   i   s    z*`backend-path` must be an array of strings>   r   rN   r   zUnknown properties: z, )
r+   _DEFAULT_BACKENDdictr   rI   listallr   keysr1   )r4   build_system_tabler3   unknown_propsr)   r)   r*   _parse_build_system_tableJ   s>   


rV   runnerr   r
   env.IsolatedEnvc                   s   	 dd fd	d
}|S )NcmdSequence[str]cwd
str | Noneextra_environMapping[str, str] | Noner   r    c                   s$   | |i    p	i |pi  d S rG   )make_extra_environ)rY   r[   r]   r
   rW   r)   r*   _invoke_wrapped_runnerw   s   $z7_wrap_subprocess_runner.<locals>._invoke_wrapped_runnerNN)rY   rZ   r[   r\   r]   r^   r   r    r)   )rW   r
   ra   r)   r`   r*   _wrap_subprocess_runnerv   s   rc   c                   @  s   e Zd ZdZejejfd7d
dZe	ejfd8ddZ
ed9ddZed9ddZed:ddZ	d;d<dd Z	d;d=d"d#Z	d;d>d&d'Z		d?d@d)d*ZdAd+d,Z	d;dBd1d2ZejdCd5d6ZdS )Dr   z#
    The PEP 517 consumer API.
    r,   r   python_executabler   rW   r   r   r    c                 C  st   t j|| _t| || _|| _t j|d}tt	|| _
| j
d | _tj| j| j| j
d| j| jd| _dS )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   rN   )backend_pathrd   rW   N)r.   r/   abspath_source_dirr6   _python_executable_runnerr1   rV   rE   _build_system_backendpyproject_hooksBuildBackendHookCallerget_hook)selfr,   rd   rW   pyproject_toml_pathr)   r)   r*   __init__   s   
zProjectBuilder.__init__clstype[_TProjectBuilder]r
   rX   r   c                 C  s   | ||j t||dS )N)r,   rd   rW   )rd   rc   )rs   r
   r,   rW   r)   r)   r*   from_isolated_env   s
   z ProjectBuilder.from_isolated_envc                 C     | j S )zProject source directory.)rg   rp   r)   r)   r*   r,      s   zProjectBuilder.source_dirc                 C  rv   )zC
        The Python executable used to invoke the backend.
        )rh   rw   r)   r)   r*   rd      s   z ProjectBuilder.python_executableset[str]c                 C  s   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   )setrj   rw   r)   r)   r*   build_system_requires   s   z$ProjectBuilder.build_system_requiresNdistributionr   config_settingsConfigSettings | Nonec                 C  sb   t d| d d| }t| j|}| | t||W  d   S 1 s*w   Y  dS )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getattrro   _handle_backendry   )rp   r{   r|   	hook_nameget_requiresr)   r)   r*   get_requires_for_build   s   

$z%ProjectBuilder.get_requires_for_buildset[tuple[str, ...]]c                 C  s"   |  ||| j}dd |D S )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
        c                 S  s   h | ]}t |D ]}|qqS r)   )r   )rK   dur)   r)   r*   	<setcomp>   s    z4ProjectBuilder.check_dependencies.<locals>.<setcomp>)r   unionrz   )rp   r{   r|   dependenciesr)   r)   r*   check_dependencies   s   z!ProjectBuilder.check_dependenciesoutput_directoryr\   c              
   C  sd   t d| d z| jd| ||ddW S  ty1 } zt|jtjr,W Y d}~dS  d}~w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   	exceptionrl   HookMissing)rp   r{   r   r|   r   r)   r)   r*   prepare   s   zProjectBuilder.preparemetadata_directoryc                 C  sB   t d| d |du r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~   Nr   build_)r	   r   r   )rp   r{   r   r|   r   kwargsr)   r)   r*   build  s   zProjectBuilder.buildc                   s   |  d|}|dur|S | d|}ttj|}|s"d}t||d  d|d  d}| d t|}|	| fd	d
|
 D  W d   n1 sRw   Y  tj||S )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  s    | ]
}|  r|V  qd S rG   )
startswith)rK   membermember_prefixr)   r*   rM   ?  s    z/ProjectBuilder.metadata_path.<locals>.<genexpr>)r   r   r   r.   r/   basename
ValueErrorzipfileZipFile
extractallnamelistr1   )rp   r   metadatar   matchr3   distinfowr)   r   r*   metadata_path%  s"   
zProjectBuilder.metadata_pathr   outdirr   r   c                 K  s   t j|}t| j|}t j|r#t j|s"d| d}t|nt | | 	| |||fi |}W d    n1 sAw   Y  t j
||S )NzBuild path 'z' exists and is not a directory)r.   r/   rf   r   ro   r2   r0   r   makedirsr   r1   )rp   r   r   r|   r   callbackr3   r   r)   r)   r*   r   C  s   
zProjectBuilder._call_backendhookIterator[None]c              
   c  s    zd V  W d S  t jy" } zt|d| j dt d d }~w tjy7 } z	t|d| d d }~w tyK } z	t|t dd d }~ww )Nz	Backend 'z' is not available.z0Backend subprocess exited when trying to invoke )exc_info)	rl   BackendUnavailabler   rk   sysr   
subprocessCalledProcessError	Exception)rp   r   r   r)   r)   r*   r   V  s&   zProjectBuilder._handle_backend)r,   r   rd   r   rW   r   r   r    )
rs   rt   r
   rX   r,   r   rW   r   r   r   )r   r   )r   rx   rG   )r{   r   r|   r}   r   rx   )r{   r   r|   r}   r   r   )r{   r   r   r   r|   r}   r   r\   rb   )
r{   r   r   r   r|   r}   r   r\   r   r   )r   r   r   r   )
r   r   r   r   r|   r}   r   r   r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   
executablerl   default_subprocess_runnerrr   classmethodru   propertyr,   rd   rz   r   r   r   r   r   r   
contextlibcontextmanagerr   r)   r)   r)   r*   r      s8    *
)r   r   r   r   r   r    )r,   r   r   r    )r/   r   r   r7   )r4   r7   r   r7   )rW   r   r
   rX   r   r   )+
__future__r   r   r#   r.   r   r   r&   r   collections.abcr   typingr   r   r   r   rl    r	   r
   _compatr   _exceptionsr   r   r   r   _typesr   r   r   r   _utilr   r   r   rO   r+   r6   rE   rV   rc   r   r)   r)   r)   r*   <module>   s4   





,	