o
    Vh	>                     @  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 erfd dlmZ d dlmZ d dlmZ d dl
mZ G dd deeZdS )    )annotationsN)TYPE_CHECKING)Any)ClassVar)argument)option)canonicalize_name)
Dependency)
MAIN_GROUP)TOMLDocument)InitCommand)InstallerCommand)
Collection)Argument)Option)NormalizedNamec                   @  s(  e Zd ZU dZdZeddddgZded< ed	d
dde	dedddedddeddddddedddddedddddeddddded dd!dded"dd#dded$dd%ed&dd'ed(dd)gZ
d*ed+< d,Zd-e d.Zd/d0gZd1ed2< dLd5d6ZdMd=d>ZedNd@dAZdOdDdEZdPdJdKZdS )Q
AddCommandaddzDAdds a new dependency to <comment>pyproject.toml</> and installs it.namezThe packages to add.T)multiplezClassVar[list[Argument]]	argumentsgroupz-Gz#The group to add the dependency to.F)flagdefaultdevDz8Add as a development dependency. (shortcut for '-G dev')editableez&Add vcs/path dependencies as editable.extrasEz&Extras to activate for the dependency.)r   r   optionalNz*Add as an optional dependency to an extra.)r   pythonz:Python version for which the dependency must be installed.platformz5Platforms for which the dependency must be installed.markerszKEnvironment markers which describe when the dependency should be installed.sourcez1Name of the source to use to install the package.allow-prereleaseszAccept prereleases.dry-runzQOutput the operations but do not execute anything (implicitly enables --verbose).lockz5Do not perform operations (only update the lockfile).zClassVar[list[Option]]optionsa  If you do not specify a version constraint, poetry will choose a suitable one based on the available package versions.

You can specify a package in the following forms:
  - A single name (<b>requests</b>)
  - A name and a constraint (<b>requests@^2.23.0</b>)
  - A git url (<b>git+https://github.com/python-poetry/poetry.git</b>)
  - A git url with a revision (<b>git+https://github.com/python-poetry/poetry.git#develop</b>)
  - A subdirectory of a git repository (<b>git+https://github.com/python-poetry/poetry.git#subdirectory=tests/fixtures/sample_project</b>)
  - A git SSH url (<b>git+ssh://git@github.com/python-poetry/poetry.git</b>)
  - A git SSH url with a revision (<b>git+ssh://git@github.com/python-poetry/poetry.git#develop</b>)
  - A file path (<b>../my-package/my-package.whl</b>)
  - A directory (<b>../my-package/</b>)
  - A url (<b>https://example.com/packages/my-package-0.1.0.tar.gz</b>)
z^The add command adds required packages to your <comment>pyproject.toml</> and installs them.


z#poetry.repositories.pypi_repositoryzpoetry.inspection.infozClassVar[list[str]]loggersreturnintc           $   	     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	r1d	}n	| 
d
| jp8t}| 
drIt|dkrItd| 
d}	|	rX|tkrXtd| jj }
|
d| }|
di d| }|d|d }rt|nd }d}g }|tkrd|v sd|v rd}|	r|di |	| }n|d| }dd |D }n| }|d| }n1d
|vr|dd|d
< |d
 }||vr| ||< ||  || }d|vr| |d< |d }g }| |||  r|    fdd|D }|s| d dS |	r|s| d | j|| 
dp"d | 
dd}|D ]}|d }|d urDt|ts@J || | }| D ]\}}|dkrVqK|||< qK|	rcd|d< | 
drmd|d< | 
drg }| 
dD ]	}|| 7 }qz||d< | 
d!rd"|v sd#|v rd|d$< n| d%|d  d& | d'  dS | 
d(r| 
d(|d(< | 
d)r| 
d)|d)< | 
d*r| 
d*|d*< | 
dr| 
d|d< t|dkrd |v r|d  }|d }t|ts J t|}||kr| d+| d, | d'  dS tt | jj !|"| W d    n	1 s5w   Y  |j#|||g| jjj$j%d-}| jj &| |rz|'|} W n tyj   |(|)  Y nw |) || < | }!t|tsd.D ]}|| }r||!|< q||!rd/D ]}|| }r||!|< qn|}!|!r|D ]}t||kr|!||<  nq|!||< |	rt|	}"|"g|_*| +||" q+|r|tksJ |	rd|vr| |d< |	|d vr||d |	< n	d|vr||d< |r'd|
vr| |
d< d|
d vr||
d d< |tkr'd|vr'||d< | jj,-|
 | j./| jj, | d0 | j.0| jj  | j.1| 
d1 | j.2| j34  | j.5d | j.6| 
d2  | j.7d3d |D  | j.8 }#|#dkr| 
d1st|
t9sJ | jj:|
 |#S )4Nr   )parse_constraint)array)inline_table)nl)table)Factoryr   r   r   r      z?You can only specify one package when using the --extras optionr    z8You can only add optional dependencies to the main groupprojecttoolpoetryFdependencieszoptional-dependenciesTc                 S  s   g | ]}t |jqS  )r	   create_from_pep_508r   ).0depr8   r8   o/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/console/commands/add.py
<listcomp>   s    z%AddCommand.handle.<locals>.<listcomp>)is_super_tablec                   s   g | ]}| vr|qS r8   r8   )r:   r   existing_packagesr8   r<   r=      s    zNothing to add.z<warning>Optional dependencies will not be added to extras in legacy mode. Consider converting your project to use the [project] section.</warning>r%   r$   )allow_prereleasesr$   versionr   gitpathdevelopzZ
<error>Failed to add packages. Only vcs/path dependencies support editable installs. <c1>z</c1> is neither.z
No changes were applied.r!   r"   r#   z$<error>Cannot add dependency on <c1>z$</c1> to project with the same name.)groupsroot_dir)r%   rE   r$   )r!   r"    r&   r'   c                 S  s   g | ]}|d  qS )r   r8   )r:   rr8   r8   r<   r=   v  s    );poetry.core.constraints.versionr-   tomlkitr.   r/   r0   r1   poetry.factoryr2   r   r   default_groupr
   len
ValueErrorr6   filereadgetr   r    get_existing_packages_from_inputnotify_about_existing_packagesline
line_error_determine_requirements
isinstancestritemssplit
contextlibsuppresspackagedependency_groupremove_dependencycreate_dependencyrD   parentadd_dependencyindexappend
to_pep_508
_in_extras_add_dependency_to_extraslockerset_pyproject_data	installer
set_lockerset_packagedry_runverboseio
is_verboseupdateexecute_operations	whitelistrunr   write)$selfr-   r.   r/   r0   r1   r2   packagesr   r    contentproject_contentpoetry_contentr   project_nameuse_project_sectionproject_dependency_namesproject_sectionpoetry_sectionrF   
this_grouprequirements_constraintrB   
constraintkeyvaluer   extraconstraint_namecanonical_constraint_name
dependencyrd   poetry_constraint
extra_namestatusr8   r?   r<   handle~   s  

























zAddCommand.handlerx   	list[str]sectiondict[str, Any]project_dependenciesCollection[NormalizedName]c                 C  sN   g }|D ] }t |}||v r|| q|D ]}|t |kr#|| qq|S )N)r   re   )rw   rx   r   r   r@   r   normalized_namer   r8   r8   r<   rS     s   

z+AddCommand.get_existing_packages_from_inputrY   c                 C  s   	 dS )Nz
If you want to update it to the latest compatible version, you can use `poetry update package`.
If you prefer to upgrade it to the latest available version, you can use `poetry add package@latest`.
r8   )rw   r8   r8   r<   _hint_update_packages  s   z AddCommand._hint_update_packagesr@   Nonec                 C  s6   |  d |D ]}|  d| d q|  | j d S )NzVThe following packages are already present in the pyproject.toml and will be skipped:
z  - <c1>z</c1>)rU   r   )rw   r@   r   r8   r8   r<   rT     s   z)AddCommand.notify_about_existing_packagesr   r	   r   r   c                 C  sr   t | jjj}g }d}||dD ]}|j|jkr!|| d}q|| q|s.|| |||< || jj_d S )NFr8   T)dictr6   r^   r   rR   r   re   )rw   r   r   r   
extra_depsreplacedr;   r8   r8   r<   rh     s   

z$AddCommand._add_dependency_to_extras)r+   r,   )rx   r   r   r   r   r   r+   r   )r+   rY   )r@   r   r+   r   )r   r	   r   r   r+   r   )__name__
__module____qualname__r   descriptionr   r   __annotations__r   r
   r(   exampleshelpr*   r   rS   propertyr   rT   rh   r8   r8   r8   r<   r      s   
 


<
  

	r   )
__future__r   r\   typingr   r   r   cleo.helpersr   r   packaging.utilsr   poetry.core.packages.dependencyr	   %poetry.core.packages.dependency_groupr
   tomlkit.toml_documentr   poetry.console.commands.initr   )poetry.console.commands.installer_commandr   collections.abcr   cleo.io.inputs.argumentr   cleo.io.inputs.optionr   r   r   r8   r8   r8   r<   <module>   s&    