o
    Vhe+                     @  sf  d dl mZ d dlZd dlZd dl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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rd 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/e0Z1G dd dZ2G dd dZ3dS )    )annotationsN)cached_property)Path)TYPE_CHECKING)ProjectPackage)__version__)	Installer)Locker)ApplicationPlugin)Plugin)InstalledRepository)TOMLFile)metadata)tomllib)Env)
EnvManager)Sequence)Any)IO)
Dependency)Package)Poetryc                   @  sh   e Zd ZdZd%ddZed&d
dZe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 )-PluginManagerz5
    This class registers and activates plugins.
    groupstrreturnNonec                 C  s   || _ g | _d S N)_group_plugins)selfr    r!   q/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/plugins/plugin_manager.py__init__1   s   
zPluginManager.__init__	directoryr   c                 C  sf   ddl m} z|| }W n
 ty   Y d S w |jtj }| r1tj	ddj
dt| d S d S )Nr   FactoryTnaive)poetry.factoryr&   locateRuntimeErrorparentProjectPluginCachePATHexistsr   get_system_envsys_pathinsertr   )r$   r&   pyproject_tomlplugin_pathr!   r!   r"   add_project_plugin_path5   s   z%PluginManager.add_project_plugin_pathpoetryr   ior   c                 C  s   t ||  d S r   )r-   ensure_plugins)clsr6   r7   r!   r!   r"   ensure_project_pluginsC   s   z$PluginManager.ensure_project_pluginsc                 C  s    |   }|D ]}| | qd S r   )get_plugin_entry_points_load_plugin_entry_point)r    plugin_entrypointsepr!   r!   r"   load_pluginsG   s   zPluginManager.load_pluginslist[metadata.EntryPoint]c                 C  s   t tj| jdS )N)r   )listr   entry_pointsr   r    r!   r!   r"   r;   M   s   z%PluginManager.get_plugin_entry_pointsargsr   kwargsc                 O  s    | j D ]
}|j|i | qd S r   )r   activate)r    rD   rE   pluginr!   r!   r"   rF   P   s   
zPluginManager.activaterG   r   c                 C  s&   t |ttfstd| j| d S )NDThe Poetry plugin must be an instance of Plugin or ApplicationPlugin)
isinstancer   r
   
ValueErrorr   append)r    rG   r!   r!   r"   _add_pluginT   s
   zPluginManager._add_pluginr>   metadata.EntryPointc                 C  s<   t d|j | }t|ttfstd| |  d S )NzLoading the %s pluginrH   )	loggerdebugnameload
issubclassr   r
   rJ   rL   )r    r>   rG   r!   r!   r"   r<   \   s   z&PluginManager._load_plugin_entry_pointN)r   r   r   r   )r$   r   r   r   r6   r   r7   r   r   r   r   r   )r   r@   )rD   r   rE   r   r   r   )rG   r   r   r   )r>   rM   r   r   )__name__
__module____qualname____doc__r#   staticmethodr5   classmethodr:   r?   r;   rF   rL   r<   r!   r!   r!   r"   r   ,   s    




r   c                   @  sp   e Zd Zedd Zd!d	d
Zed"ddZe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 )&r-   z.poetrypluginsr6   r   r7   r   r   r   c                 C  s:   || _ || _|jj| j | _| jd | _| jjd | _d S )Nzconfig.tomlz
.gitignore)_poetry_iopyproject_pathr,   r.   _path_config_file_gitignore_file)r    r6   r7   r!   r!   r"   r#   l   s
   zProjectPluginCache.__init__dict[str, Any]c                 C  s"   | j jdi }t|tsJ |S )Nzrequires-plugins)r\   local_configgetrI   dict)r    r[   r!   r!   r"   _plugin_sections   s   z"ProjectPluginCache._plugin_sectionc                 C  s(   t jtttj| jdd 	 dS )NT)	sort_keys)pythonr6   zplugins-hash)
sysversionr   hashlibsha256jsondumpsrf   encode	hexdigestrC   r!   r!   r"   _configy   s   zProjectPluginCache._configc                   s  ddl m} g }| j D ]\}}t|tr|n|g}|D ]}|||| qq|sE| j	 rC| j
d | j
d t| j d S |  r\| j
 rZ| j
d | j
d d S | j	 rm| j
d t| j tjdd  fd	d
|D }|s| j
 r| j
d | j
d |   d S | j
d t|}t g }	g }
t }|jD ]2}||j }r||rɈ|j |
| n|	||f |d8 }|dkr nq|
| q|dkr|	s|   | j
d | j
d d S |	r| j
 rddd |	D }| j
d|  fdd| D }ddd |D }| j
d| d | | |
 | j
d |   d S )Nr   r%   zL<info>No project plugins defined. Removing the project's plugin cache</info> z)The project's plugin cache is up to date.z:Removing the project's plugin cache because it is outdatedTr'   c                   s"   i | ]}|j  jr|j|qS r!   )markervalidate
marker_envrP   ).0rG   )
poetry_envr!   r"   
<dictcomp>   s    z5ProjectPluginCache.ensure_plugins.<locals>.<dictcomp>z=No relevant project plugins for Poetry's environment defined.zV<info>Ensuring that the Poetry plugins required by the project are available...</info>   zIAll required plugins have already been installed in Poetry's environment.
c                 s  s$    | ]\}}d | d| V  qdS )  - z
    installed: Nr!   )rv   preqr!   r!   r"   	<genexpr>   s    
z4ProjectPluginCache.ensure_plugins.<locals>.<genexpr>zjThe following Poetry plugins are required by the project but are not satisfied by the installed versions:
c                   s   g | ]
\}}| vr|qS r!   r!   )rv   rP   rG   )satisfied_pluginsr!   r"   
<listcomp>   s
    z5ProjectPluginCache.ensure_plugins.<locals>.<listcomp>c                 s  s    | ]}d | V  qdS )r{   Nr!   )rv   r|   r!   r!   r"   r~      s    zhThe following Poetry plugins are required by the project but are not installed in Poetry's environment:
z:
Installing Poetry plugins only for the current project...)r)   r&   rf   itemsrI   rA   rK   create_dependencyr_   r/   r]   
write_lineshutilrmtree	_is_freshis_debugr   r0   _write_configlensetr   rQ   packagesrd   rP   	satisfiesaddjoin_install)r    r&   r[   rP   constraints_constraints_constraintrelevant_pluginsmissing_plugin_countinsufficient_pluginsinstalled_packagesinstalled_repopackagerequired_pluginplugins_strmissing_pluginsr!   )rw   r   r"   r8      s   









z!ProjectPluginCache.ensure_pluginsboolc                 C  sN   | j  sdS | j d}t|}W d    n1 sw   Y  || jkS )NFrb)r`   r/   openr   rQ   rq   )r    fstored_configr!   r!   r"   r      s   

zProjectPluginCache._is_freshSequence[Dependency]rw   r   locked_packagesSequence[Package]c              	   C  s   t ddd}ddd |jd d D |_|D ]	}||  q|D ]}|| q$|j| j| jd |   t	| j
||t| jd	 i | jj| jjt|}|d
 | dkr_tdd S )Nzpoetry-project-instance0)rP   rj   .c                 s  s    | ]}t |V  qd S r   )r   )rv   vr!   r!   r"   r~     s    z.ProjectPluginCache._install.<locals>.<genexpr>   )purelibplatlibzpoetry.lockTr   z)Failed to install required Poetry plugins)r   r   version_infopython_versionsadd_dependencyto_dependency	set_pathsr_   _ensure_cache_directoryr   r]   r	   r\   poolconfigr   updaterunr+   )r    r[   rw   r   projectr   
dependency	installerr!   r!   r"   r     s*    
zProjectPluginCache._installc                 C  sB   |    t }| j D ]\}}|||< qt| jj|d d S )N)data)r   tomlkitdocumentrq   r   r   r`   write)r    r   keyvaluer!   r!   r"   r   (  s
   
z ProjectPluginCache._write_configc                 C  s2   | j  rd S | j jddd | jjddd d S )NT)parentsexist_ok*zutf-8)encoding)r_   r/   mkdirra   
write_textrC   r!   r!   r"   r   2  s   
z*ProjectPluginCache._ensure_cache_directoryNrS   )r   rb   rT   )r   r   )r[   r   rw   r   r   r   r   r   )rU   rV   rW   r   r.   r#   propertyrf   r   rq   r8   r   r   r   r   r!   r!   r!   r"   r-   i   s    

	
x
	
$
r-   )4
__future__r   rk   rm   loggingr   ri   	functoolsr   pathlibr   typingr   r   $poetry.core.packages.project_packager   poetry.__version__r   poetry.installationr   poetry.packagesr	   !poetry.plugins.application_pluginr
   poetry.plugins.pluginr   (poetry.repositories.installed_repositoryr   poetry.tomlr   poetry.utils._compatr   r   poetry.utils.envr   r   collections.abcr   r   
cleo.io.ior   poetry.core.packages.dependencyr   poetry.core.packages.packager   poetry.poetryr   	getLoggerrU   rN   r   r-   r!   r!   r!   r"   <module>   s@    
=