o
    Vh                     @  s   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rJd d
lmZ d dlmZ d dlmZ G dd deZdS )    )annotations)TYPE_CHECKING)Any)ClassVar)argument)option)InvalidVersionError)TOMLDocument)Command)Argument)OptionVersionc                   @  st   e Zd ZU dZdZeddddgZded< edd	d
edddedddgZ	ded< dZ
dddZ	d d!ddZdS )"VersionCommandversionzPShows the version of the project or bumps it when a valid bump rule is provided.z5The version number or the rule to update the version.T)optionalzClassVar[list[Argument]]	argumentsshortszOutput the version number onlydry-runNz!Do not update pyproject.toml file
next-phasez*Increment the phase of the current versionzClassVar[list[Option]]optionsaO  The version command shows the current version of the project or bumps the version of
the project and writes the new version back to <comment>pyproject.toml</> if a valid
bump rule is provided.

The new version should ideally be a valid semver string or a valid bump rule:
patch, minor, major, prepatch, preminor, premajor, prerelease.
returnintc                 C  s   |  d}|rm| | jjj|| d}| dr!| |  n| d| jjj d| d | dsk| jj	 }|
di }d|v rJ|j|d< |
d	i 
d
i }d|v r]|j|d< t|tsdJ | jj| dS | dr|| | jjj dS | d| jjj d| jjj d dS )Nr   r   r   zBumping version from <b>z</> to <fg=green>z</>r   projecttoolpoetryz	<comment>z
</> <info>r   )r   increment_versionr   packagepretty_versionr   line	to_stringfilereadgettext
isinstancer	   writepretty_name)selfr   contentproject_contentpoetry_content r-   s/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/console/commands/version.pyhandle6   s@   






zVersionCommand.handleFstrrule
next_phaseboolr   c                 C  s  ddl m} z||}W n ty   tdw |dv r+| }|dkr)| }|S |dv r=| }|dkr;| }|S |dv rO| }|d	krM| }|S |d
kr||	 rt|j
}|d us`J |rf| n| }||j|j|}|S |  }|S ||}|S )Nr   r   z3The project's version doesn't seem to follow semver>   majorpremajorr5   >   minorpreminorr7   >   patchprepatchr9   
prerelease)poetry.core.constraints.versionr   parser   
ValueError
next_majorfirst_prerelease
next_minor
next_patchis_unstableprer2   nextepochrelease)r)   r   r1   r2   r   parsednewrC   r-   r-   r.   r   \   s@   
z VersionCommand.increment_version)r   r   )F)r   r0   r1   r0   r2   r3   r   r   )__name__
__module____qualname__namedescriptionr   r   __annotations__r   r   helpr/   r   r-   r-   r-   r.   r      s,   
 



	'r   N)
__future__r   typingr   r   r   cleo.helpersr   r   poetry.core.version.exceptionsr   tomlkit.toml_documentr	   poetry.console.commands.commandr
   cleo.io.inputs.argumentr   cleo.io.inputs.optionr   r;   r   r   r-   r-   r-   r.   <module>   s    