o
    Vh+                     @  sx   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r2d dl
mZ d dlmZ G d	d
 d
e	ZdS )    )annotations)TYPE_CHECKING)Any)ClassVar)option)Command)Path)Optionc                   @  s^   e Zd ZU dZdZedddedddgZded	< dddZdddZ	d ddZ
d!ddZdS )"CheckCommandcheckzkValidates the content of the <comment>pyproject.toml</> file and its consistency with the poetry.lock file.lockNzaChecks that <comment>poetry.lock</> exists for the current version of <comment>pyproject.toml</>.strictzFail if check reports warnings.zClassVar[list[Option]]optionsproject_classifiersset[str]returntuple[list[str], list[str]]c                 C  s   ddl m} ddl m} g }g }t|t| t| }dd |D }|r.|d|d t|t|}|rY|D ]}|| }	|	rMd|d	|	d}
nd|d
}
||
 q;||fS )ao  Identify unrecognized and deprecated trove classifiers.

        A fully-qualified classifier is a string delimited by `` :: `` separators. To
        make the error message more readable we need to have visual clues to
        materialize the start and end of a classifier string. That way the user can
        easily copy and paste it from the messages while reducing mistakes because of
        extra spaces.

        We use ``!r`` (``repr()``) for classifiers and list of classifiers for
        consistency. That way all strings will be rendered with the same kind of quotes
        (i.e. simple tick: ``'``).
        r   )classifiers)deprecated_classifiersc                 S  s   g | ]	}| d s|qS )z
Private ::)
startswith).0u r   q/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/console/commands/check.py
<listcomp>B   s    z6CheckCommand._validate_classifiers.<locals>.<listcomp>zUnrecognized classifiers: .zDeprecated classifier z. Must be replaced by z. Must be removed.)trove_classifiersr   r   sortedsetappendintersection)selfr   r   r   errorswarningsunrecognized
deprecatedold_classifiernew_classifiersmessager   r   r   _validate_classifiers'   s2   
z"CheckCommand._validate_classifiersreadmestr | list[str]poetry_filer   	list[str]c                 C  sD   t |tr|gn|}g }|D ]}|j|  s|d|  q|S )z*Check existence of referenced readme filesz%Declared README file does not exist: )
isinstancestrparentexistsr   )r!   r*   r,   readmesr"   namer   r   r   _validate_readmeY   s   zCheckCommand._validate_readmeconfigdict[str, Any]c           	      C  s   dd | j jjD }g }d|v r||d  |di  D ]}d|v r,||d  qt }|D ]/}| D ](}t|trP|D ]}d|v rN|	|d  qAq8t|t
r`d|v r`|	|d  q8q2dd t|| D S )z%Check dependencies's source are validc                 S  s   h | ]}|j qS r   )r3   )r   
repositoryr   r   r   	<setcomp>f   s    z=CheckCommand._validate_dependencies_source.<locals>.<setcomp>dependenciesgroupsourcec                 S  s   g | ]}d | dqS )zInvalid source "z" referenced in dependencies.r   )r   r;   r   r   r   r   ~   s    
z>CheckCommand._validate_dependencies_source.<locals>.<listcomp>)poetrypoolall_repositoriesr   getvaluesr   r.   listadddictr   )	r!   r5   sourcesdependency_declarationsr:   all_referenced_sourcesdependency_declarationdeclarationitemr   r   r   _validate_dependencies_sourced   s2   

z*CheckCommand._validate_dependencies_sourceintc                 C  s  ddl m} ddlm} | jjj}||j}|j|dd}|	di }|d d }t
|	d	p4|	d	g }| |\}	}
|d
 |	 |d |
 d|v r^| |d |}	|d
 |	 |d
  | |7  < | dr}| jj s}|d
  dg7  < | jj r| jj s|d
  dg7  < d}|d
 s|d r| drd}|d
 s|d s| d |d
 D ]}| d| d q|d D ]}| d| d q|S )Nr   )PyProjectTOML)FactoryT)r   projecttoolr<   r   r"   r#   r*   r   zpoetry.lock was not found.zrpyproject.toml changed significantly since poetry.lock was last generated. Run `poetry lock` to fix the lock file.r      zAll set!z<error>Error: z</error>z<warning>Warning: z
</warning>)poetry.core.pyproject.tomlrL   poetry.factoryrM   r<   filepathdatavalidater?   r   r)   extendr4   rJ   r   locker	is_lockedis_freshinfo
line_error)r!   rL   rM   r,   	toml_datacheck_resultrN   poetry_configr   r"   r#   return_codeerrorr   r   r   handle   sJ   


zCheckCommand.handle)r   r   r   r   )r*   r+   r,   r   r   r-   )r5   r6   r   r-   )r   rK   )__name__
__module____qualname__r3   descriptionr   r   __annotations__r)   r4   rJ   rb   r   r   r   r   r
      s&   
 

2
r
   N)
__future__r   typingr   r   r   cleo.helpersr   poetry.console.commands.commandr   pathlibr   cleo.io.inputs.optionr	   r
   r   r   r   r   <module>   s    