o
    Vh                     @  s:  d dl m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
 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ e
rpd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm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e			d(d)d&d'Z#dS )*    )annotationsN)contextmanager)redirect_stdout)StringIO)TYPE_CHECKING)BuildBackendException)IsolatedEnv)decode)Env)
EnvManager)ephemeral_environment)
Collection)Iterator)Path)DistributionTypeProjectBuilderRepositoryPoolc                   @  s   e Zd ZdS )IsolatedBuildBaseErrorN)__name__
__module____qualname__ r   r   o/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/utils/isolated_build.pyr      s    r   c                      s6   e Zd Zd fddZ		ddddZdddZ  ZS )IsolatedBuildBackendErrorsourcer   	exceptionr   returnNonec                   s   t    || _|| _d S N)super__init__r   r   )selfr   r   	__class__r   r   r"   #   s   

z"IsolatedBuildBackendError.__init__Nsource_string
str | Nonebuild_commandstrc                 C  s   | j j }|p
| j }|pd| j  d}dt| j g}t|tjrKt|jp,|j	p,|j
 }ddt|dg|dd}|d| d |d	| d
| d d|S )Nz'pip wheel --no-cache-dir --use-pep517 ""z#PEP517 build of a dependency failedz
    |  
z	<warning>z
</warning>z<info><options=bold>Note:</> This error originates from the build backend, and is likely not a problem with poetry but one of the following issues with a9  

  - not supporting PEP 517 builds
  - not specifying PEP 517 build requirements correctly
  - the build requirements are incompatible with your operating system or Python version
  - the build requirements are missing system dependencies (eg: compilers, libraries, headers).

You can verify this by running <c1>z</c1>.</info>

)r   r   as_posixr)   
isinstance
subprocessCalledProcessErrorr	   stderrstdoutoutputstripjoinsplitlstripappend)r#   r&   r(   ereasonsinner_tracebackinner_reasonr   r   r   generate_message(   s,   
z*IsolatedBuildBackendError.generate_messagec                 C  s   |   S r    )r>   r#   r   r   r   __str__I   s   z!IsolatedBuildBackendError.__str__)r   r   r   r   r   r   )NN)r&   r'   r(   r'   r   r)   r   r)   )r   r   r   r"   r>   r@   __classcell__r   r   r$   r   r   "   s
    !r   c                      s,   e Zd Zd fdd	Zedd
dZ  ZS )IsolatedBuildInstallErrorrequirementsCollection[str]r4   r)   errorr   r   c                   s@   d dd | dd| d| f}t | || _d S )Nr-   zFailed to install z, .zOutput:
zError:
)r6   r!   r"   _requirements)r#   rD   r4   rF   messager$   r   r   r"   N   s   
z"IsolatedBuildInstallError.__init__c                 C  s   | j S r    )rH   r?   r   r   r   rD   Y   s   z&IsolatedBuildInstallError.requirements)rD   rE   r4   r)   rF   r)   r   r   )r   rE   )r   r   r   r"   propertyrD   rB   r   r   r$   r   rC   M   s    rC   c                   @  s8   e Zd ZdddZedd
dZdddZdddZdS )r   envr
   poolr   r   r   c                 C  s   || _ || _d S r    )_env_pool)r#   rK   rL   r   r   r   r"   _   s   
zIsolatedEnv.__init__r)   c                 C  s   t | jjS r    )r)   rM   pythonr?   r   r   r   python_executablec   s   zIsolatedEnv.python_executabledict[str, str]c                 C  s:   t jd}t| jj}d|d urt j||giS |iS )NPATH)osenvirongetr)   rM   _bin_dirpathsepr6   )r#   pathscripts_dirr   r   r   make_extra_environg   s   zIsolatedEnv.make_extra_environrD   rE   c              
   C  s&  ddl m} ddlm} ddlm} ddlm} ddlm	} ddl
m} ddlm} |d	d
}	ddd | jjd d D |	_| j }
|D ]}||}|j sY|j|
r^|	| qG| }||| j|	|| jjdi | j| || j}|d | dkrt||  |! d S )Nr   )
BufferedIO)
Dependency)ProjectPackage)Config)	Installer)Locker)InstalledRepository__root__z0.0.0rG   c                 s  s    | ]}t |V  qd S r    )r)   ).0vr   r   r   	<genexpr>~   s    z&IsolatedEnv.install.<locals>.<genexpr>   zpoetry.lockT)"cleo.io.buffered_ior[   poetry.core.packages.dependencyr\   $poetry.core.packages.project_packager]   poetry.config.configr^   poetry.installation.installerr_   poetry.packages.lockerr`   (poetry.repositories.installed_repositoryra   r6   rM   version_infopython_versionsget_marker_envcreate_from_pep_508markeris_emptyvalidateadd_dependencyrX   joinpathrN   createloadupdaterunrC   fetch_outputfetch_error)r#   rD   r[   r\   r]   r^   r_   r`   ra   packageenv_markersrequirement
dependencyio	installerr   r   r   installr   s>   
"




	zIsolatedEnv.installN)rK   r
   rL   r   r   r   rA   )r   rQ   )rD   rE   r   r   )r   r   r   r"   rJ   rP   rZ   r   r   r   r   r   r   ^   s    

r   wheelr   r   distributionr   rP   Path | NonerL   RepositoryPool | Noner   Iterator[ProjectBuilder]c                 c  sV   ddl m} ddlm} ddlm} z
|p|  j}W n ty9   ddl	m
} ddlm} || gd}Y nw |pBtjdd	j}t|d
didV}	t|	|}
t }z2|j|
| |d}t| |
|j |
|j||B  |V  W d    n1 sw   Y  W n ty } zt| |d d }~ww W d    d S 1 sw   Y  d S )Nr   r   )quiet_subprocess_runner)Factoryr   )PyPiRepository)repositoriesT)naivezno-pip)
executableflags)runner)buildr   pyproject_hooksr   poetry.factoryr   create_poetryrL   RuntimeErrorpoetry.repositoriesr   #poetry.repositories.pypi_repositoryr   r   get_system_envrO   r   r   r   from_isolated_envr   r   build_system_requiresget_requires_for_buildr   r   )r   r   rP   rL   r   r   r   r   r   venvrK   r3   builderr:   r   r   r   isolated_builder   sP   



"r   )r   NN)
r   r   r   r   rP   r   rL   r   r   r   )$
__future__r   rS   r0   
contextlibr   r   r   r   typingr   r   r   	build.envr   BaseIsolatedEnvpoetry.utils._compatr	   poetry.utils.envr
   r   r   collections.abcr   r   pathlibr   r   r   r   r   	Exceptionr   r   rC   r   r   r   r   r   <module>   s:    +@