o
    Vh.                     @  s~  d dl m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	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  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/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 e7e8Z9G dd deZdS )    )annotationsN)TYPE_CHECKING)Any)cast)NullIOcanonicalize_name)Version)parse_constraint)Factory)
MAIN_GROUP)__version__)Config)PoetryError)validate_object)Locker)Plugin)PluginManager)Poetry)TOMLFile)Iterable)Path)IO)Package)TOMLDocumentRepositoryPool)HTTPRepository)DependencySpecc                      sz   e Zd ZdZ					d)d* fddZe			d+d,ddZe	d-d.ddZed/d!d"Ze	d-d0 fd'd(Z	  Z
S )1r   zD
    Factory class to create various elements needed by Poetry.
    NTFcwdPath | Nonewith_groupsboolio	IO | Nonedisable_pluginsdisable_cachereturnr   c                   s~  |d u rt  }t j||d}|jd }r/t|}tt}	|	|	s/t
d| d|	 |j}
t|
jd |jj}t }t|
jd }| r_| rX|d|j  ||  i }|di }|jd	g D ]}|d
}|d}|r|r||vrd|i||< qn|d|i t|
|j|j|||}|| j||jd	g ||d |sttj}|   |!|| |S )N)r   r!   zrequires-poetryzThis project requires Poetry z, but you are using Poetry zpoetry.lockzpoetry.tomlzLoading configuration file repositoriessourcenameurlr&   )"r   supercreate_poetrylocal_configgetr
   r	   parser   allowsr   pyproject_pathr   parent	pyprojectdatar   creater   existsis_debug
write_linepathmergereadr   packageset_poolcreate_poolr   r   groupload_pluginsactivate)selfr   r!   r#   r%   r&   base_poetryversion_strversion_constraintversionpoetry_filelockerconfiglocal_config_filer(   existing_repositoriesr)   r*   r+   poetryplugin_manager	__class__ b/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/factory.pyr.   1   sd   



		
zFactory.create_poetryrR   rK   r   sourcesIterable[dict[str, Any]]r   c              
   C  s  ddl m} ddlm} |d u rt }|rtd ||d}d}|D ]=}	| j|	||d}
||	d|j	j
  }| rP|d	|
j
 d
|
j d|j
   |j|
|d |
j
 dkr`d}q#|s| rq| rp|d n|j| jddi||d|j	d |jstd|S )Nr   r   )PriorityzDisabling source caches)rK   Fr,   priorityzAdding repository z (z) and setting it as )rW   pypiTz Deactivating the PyPI repositoryr*   z9At least one source must not be configured as 'explicit'.)poetry.repositoriesr   #poetry.repositories.repository_poolrV   r   loggerdebugcreate_package_sourcer0   PRIMARYr*   upperr9   r:   r+   loweradd_repositoryhas_primary_repositoriesr(   r   )clsrK   rT   r#   r&   r   rV   poolexplicit_pypir)   
repositoryrW   rR   rR   rS   r@   y   sN   



zFactory.create_poolr)   dict[str, str]r   c                 C  s   ddl m} ddlm} ddlm} ddlm} z|d }W n ty)   |dw |j	}	|
 dkrBd	|v r;|d
||||	dS z|d	 }
W n tyW   |d|dw |}td|
rb|}|||
|||	dS )Nr   )InvalidSourceError)LegacyRepository)PyPiRepository)SinglePageRepositoryr*   zMissing [name] in source.rX   r+   z;The PyPI repository cannot be configured with a custom url.)rK   r&   	pool_sizezMissing [url] in source .z.*\.(htm|html)$)poetry.repositories.exceptionsrh   %poetry.repositories.legacy_repositoryri   #poetry.repositories.pypi_repositoryrj   *poetry.repositories.single_page_repositoryrk   KeyErrorinstaller_max_workersr`   rematch)rc   r)   rK   r&   rh   ri   rj   rk   r*   rl   r+   repository_classrR   rR   rS   r]      sF   zFactory.create_package_sourcer>   r   r   c              	   C  s  dd l }ddlm} | }|jdd|d< | }||d d< |j|d< |jj|d< |j|d	< |j	|d
< |j
r<|j
jnd|d< |jrH|j|d< |jrP|j|d< |jrX|j|d< |jr`|j|d< |jrh|j|d< |jrp|j|d< g }|jD ]+}| }tt |jr||j }W d    n1 sw   Y  || qu|r||d< t }	d }
|jr| }
|jD ]}g }|j| D ]}||j |	|j q||
|< qt|	}	|  }|d< |j|d< |jD ]}||| }t |t!s|j|	v rd|d< t"|dkrd|v rt |d t!sJ |d }n|sd}|j#D ]K}|t$kr0|||j< q"d|vr=|jdd|d< ||d vrN|jdd|d |< d|d | vra| |d | d< ||d | d |j< q"q|
rv|
|d< t%d|}|S )Nr   )dependency_to_specificationT)is_super_tabletoolrN   r*   rH   descriptionauthors licenseclassifiersdocumentationrf   homepagemaintainerskeywordsreadmedependenciespythonoptional   *rA   extrasr   )&tomlkit%poetry.utils.dependency_specificationrw   documenttabler*   rH   textrz   r{   r}   idr~   documentation_urlrepository_urlr   r   r   readmesas_posix
contextlibsuppress
ValueErrorroot_dirrelative_toappendsetr   addpython_versionsall_requiresinline_table
isinstancestrlengroupsr   r   )rc   r>   r   rw   r5   contentr   r   readme_posix_pathoptional_dependenciesextras_sectionextra_dependencies
dependencydependency_sectiondep
constraintrA   rR   rR   rS   create_pyproject_from_package   s   



















z%Factory.create_pyproject_from_package	toml_datadict[str, Any]strictdict[str, list[str]]c           	        s   t  ||}|d d }|d t| t|di  }||di   |di  }|D ]}||di   q5dd |D }|d	i d
pW|d
}|d urmt	||v rm|d 
d| d |S )Nry   rN   errorsr   zdev-dependenciesrA   c                 S  s   h | ]}t |qS rR   r   ).0drR   rR   rS   	<setcomp>Y  s    z#Factory.validate.<locals>.<setcomp>projectr*   zProject name (z$) is same as one of its dependencies)r-   validateextendr   r   r0   keysupdatevaluesr   r   )	rc   r   r   resultspoetry_configr   r   rA   project_namerP   rR   rS   r   H  s"   
zFactory.validate)NTNFF)r   r    r!   r"   r#   r$   r%   r"   r&   r"   r'   r   )rR   NF)
rK   r   rT   rU   r#   r$   r&   r"   r'   r   )F)r)   rg   rK   r   r&   r"   r'   r   )r>   r   r'   r   )r   r   r   r"   r'   r   )__name__
__module____qualname____doc__r.   classmethodr@   r]   r   r   __classcell__rR   rR   rP   rS   r   ,   s*    H7,ir   ):
__future__r   r   loggingrt   typingr   r   r   cleo.io.null_ior   packaging.utilsr   poetry.core.constraints.versionr	   r
   poetry.core.factoryr   BaseFactory%poetry.core.packages.dependency_groupr   poetry.__version__r   poetry.config.configr   poetry.exceptionsr   poetry.jsonr   poetry.packages.lockerr   poetry.plugins.pluginr   poetry.plugins.plugin_managerr   poetry.poetryr   poetry.toml.filer   collections.abcr   pathlibr   
cleo.io.ior   poetry.core.packages.packager   tomlkit.toml_documentr   rY   r   #poetry.repositories.http_repositoryr   r   r   	getLoggerr   r[   rR   rR   rR   rS   <module>   sB    
