o
    Vhf                     @  s(  d dl m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 d dlmZ d dlmZ errd 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	d Z"ej#ddG dd dZ$G dd dZ%G dd deZ&dS )    )annotationsN)Path)TYPE_CHECKING)Any)ClassVar)Literal)option)Version)
EnvCommand)BUILD_FORMATS)metadata)remove_directory)isolated_builder)Callable)Option)IO)Poetry)Env)sdistwheelT)frozenc                   @  sD   e Zd ZU ded< ded< ded< ejedZded	< dddZdS )BuildOptionsboolcleanzlist[DistributionType]formatsstroutput)default_factorydict[str, Any]config_settingsreturnNonec                 C  s&   | j D ]}|tvrtd| qd S )NzInvalid format: )r   r   
ValueError)selffmt r%   q/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/console/commands/build.py__post_init__(   s
   
zBuildOptions.__post_init__N)r    r!   )	__name__
__module____qualname____annotations__dataclassesfielddictr   r'   r%   r%   r%   r&   r   !   s   
 r   c                   @  sR   e Z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#S ))BuildHandlerpoetryr   envr   ior   r    r!   c                 C  s   || _ || _|| _d S Nr0   r1   r2   )r#   r0   r1   r2   r%   r%   r&   __init__/   s   
zBuildHandler.__init__r$   DistributionType
executabler   
target_dirr   r   c                 C  s"   t | }|| j||d| d S )N)r7   r   )r   r0   buildr#   r$   r7   r8   r   builderr%   r%   r&   _build4   s   zBuildHandler._buildc                 C  sL   t | jjjj||d}|j|||d W d    d S 1 sw   Y  d S )N)sourcedistributionpython_executable)r   )r   r0   filepathparentr9   r:   r%   r%   r&   _isolated_buildC   s   
"zBuildHandler._isolated_buildr   c                 C  sx   |   s| jd dS | jjjst| jjdkrdS | jjd }|jdkr(dS t	
td}t|j| p:|jS )a  
        Determines if an isolated build is required.

        An isolated build is required if:
        - The package has a build script.
        - There are multiple build system dependencies.
        - The build dependency is not `poetry-core`.
        - The installed `poetry-core` version does not satisfy the build dependency constraints.
        - The build dependency has a source type (e.g. is a VcsDependency).

        :returns: True if an isolated build is required, False otherwise.
        a?  <warning><b>WARNING</>: No build backend defined. Please define one in the <c1>pyproject.toml</>.
Falling back to using the built-in `poetry-core` version.
In a future release Poetry will fallback to `setuptools` as defined by PEP 517.
More details can be found at https://python-poetry.org/docs/libraries/#packaging</>F   Tr   zpoetry-core)_has_build_backend_definedr2   write_error_liner0   packagebuild_scriptlenbuild_system_dependenciesnamer	   parser   versionr   
constraintallowssource_type)r#   build_dependencypoetry_core_versionr%   r%   r&   _requires_isolated_buildQ   s"   
z%BuildHandler._requires_isolated_buildCallable[..., None]c                 C  s   |   r| jS | jS r3   )rS   rC   r<   r#   r%   r%   r&   _get_builderx   s   zBuildHandler._get_builderc                 C  s   d| j jjdi v S )Nzbuild-backendzbuild-system)r0   	pyprojectdatagetrU   r%   r%   r&   rE   ~   s   z'BuildHandler._has_build_backend_definedoptionsr   intc                 C  s   | j js| jd dS t|j}| j j}| jd|j d|j	 d |
 s/| j jj| }|jr8t|dd |  }|jD ]}| jd| d	 ||| jj||jd
 q?dS )Nz7Building a package is not possible in non-package mode.rD   zBuilding <c1>z</c1> (<c2>z</c2>)T)rA   forcezBuilding <info>z</info>)r7   r8   r   r   )r0   is_package_moder2   rF   r   r   rG   
write_linepretty_namerM   is_absolutepyproject_pathrB   r   r   rV   r   r1   pythonr   )r#   rZ   dist_dirrG   r9   r$   r%   r%   r&   r9      s0   

zBuildHandler.buildN)r0   r   r1   r   r2   r   r    r!   )
r$   r6   r7   r   r8   r   r   r   r    r!   )r    r   )r    rT   )rZ   r   r    r[   )
r(   r)   r*   r5   r<   rC   rS   rV   rE   r9   r%   r%   r%   r&   r/   .   s    




'
r/   c                   @  s   e Zd ZU dZdZedddddedd	d
dedddddeddddddeddddd
dgZded< g dZded< e	d/d%d&Z
e	d0d)d*Zd1d,d-Zd.S )2BuildCommandr9   z6Builds a package, as a tarball and a wheel by default.formatfz*Limit the format to either sdist or wheel.F)flagr   z'Clean output directory before building.T)descriptionrg   local-versionlzRAdd or replace a local version label to the build. (<warning>Deprecated</warning>)r   oz<Set output directory for build artifacts. Default is `dist`.dist)defaultrg   config-settingsczQProvide config settings that should be passed to backend in <key>=<value> format.)rh   rg   multiplezClassVar[list[Option]]rZ   )z$poetry.core.masonry.builders.builderz"poetry.core.masonry.builders.sdistz"poetry.core.masonry.builders.wheelzClassVar[list[str]]loggerslocal_version
str | Noner   list[str] | Noner2   r   r    dict[str, str]c                 C  sh   |pg }i }| r| d|  d | |d< |D ]}d|vr%td| d|d\}}}|||< q|S )Nz<warning>`<fg=yellow;options=bold>--local-version</>` is deprecated. Use `<fg=yellow;options=bold>--config-settings local-version=z</>` instead.</warning>ri   =zInvalid config setting format: z3. Config settings must be in the format 'key=value')rF   r"   	partition)rr   r   r2   resultconfig_settingkey_valuer%   r%   r&   _prepare_config_settings   s"   

z%BuildCommand._prepare_config_settingsr$   	list[str]c                 C  s   | pd} | dkrddgS | gS )Nallr   r   r%   )r$   r%   r%   r&   _prepare_formats   s   zBuildCommand._prepare_formatsr[   c              	   C  sb   t | j| j| jd}t| d| | d| d| j| d| d| jdd}|j|d	S )
Nr4   r   re   r   ri   rn   )rr   r   r2   )r   r   r   r   )rZ   )	r/   r0   r1   r2   r   r   r   r}   r9   )r#   build_handlerbuild_optionsr%   r%   r&   handle   s    zBuildCommand.handleN)rr   rs   r   rt   r2   r   r    ru   )r$   rs   r    r~   )r    r[   )r(   r)   r*   rK   rh   r   rZ   r+   rq   staticmethodr}   r   r   r%   r%   r%   r&   rd      sH   
 rd   )'
__future__r   r,   pathlibr   typingr   r   r   r   cleo.helpersr   poetry.core.constraints.versionr	   #poetry.console.commands.env_commandr
   poetry.masonry.buildersr   poetry.utils._compatr   poetry.utils.helpersr   poetry.utils.isolated_buildr   collections.abcr   cleo.io.inputs.optionr   
cleo.io.ior   poetry.poetryr   poetry.utils.envr   r6   	dataclassr   r/   rd   r%   r%   r%   r&   <module>   s2    
t