o
    i                     @  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 er<d d
lmZ eeZG dd de
ZdS )    )annotationsN)Iterable)TYPE_CHECKING)BuildEnvironment)AbstractDistribution)InstallationError)BaseDistribution)runner_with_spinner_message)BuildEnvironmentInstallerc                   @  sn   e Zd Z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(ddZd*ddZd+d"d#Zd$S ),SourceDistributionzRepresents a source distribution.

    The preparation step for these needs metadata for the packages to be
    generated.
    return
str | Nonec                 C  s   | j jsJ | j jjS )z/Identify this requirement uniquely by its link.)reqlinkZurl_without_fragmentself r   Alib/python3.10/site-packages/pip/_internal/distributions/sdist.pybuild_tracker_id   s   
z#SourceDistribution.build_tracker_idr   c                 C  s
   | j  S )N)r   Zget_distr   r   r   r   get_metadata_distribution    s   
z,SourceDistribution.get_metadata_distributionbuild_env_installerr
   build_isolationboolcheck_build_depsNonec                 C  s   | j   |r| | | j   | | n| j   |r@| j j}|d us(J | j j|\}}|r9| d| |r@| 	| | j 
  d S )Nthe backend dependencies)r   Zload_pyproject_toml_prepare_build_backendZeditable_sanity_check_install_build_reqspyproject_requires	build_envcheck_requirements_raise_conflicts_raise_missing_reqsZprepare_metadata)r   r   r   r   r   conflictingmissingr   r   r   prepare_distribution_metadata#   s"   




z0SourceDistribution.prepare_distribution_metadatac              	   C  s   | j j}|d us
J t|| j _| j jj|dd| j d | j j| j j\}}|r/| d| |rHt	d| j  t	dd
ttt| d S d S )NZoverlayzbuild dependencieskindZfor_reqz"PEP 517/518 supported requirementsz4Missing build requirements in pyproject.toml for %s.z`The project does not specify a build backend, and pip cannot fall back to setuptools without %s.z and )r   r   r   r   install_requirementsr    Zrequirements_to_checkr!   loggerZwarningjoinmapreprsorted)r   r   r   r#   r$   r   r   r   r   I   s*   
z)SourceDistribution._prepare_build_backendIterable[str]c              	   C     | j j7 td}| j j}|d usJ || | W  d    W  d    S 1 s.w   Y  W d    d S 1 s>w   Y  d S )Nz#Getting requirements to build wheel)r   r   r	   pep517_backendsubprocess_runnerZget_requires_for_build_wheelr   ZrunnerZbackendr   r   r   _get_build_requires_wheele   s   
"z,SourceDistribution._get_build_requires_wheelc              	   C  r/   )Nz&Getting requirements to build editable)r   r   r	   r0   r1   Zget_requires_for_build_editabler2   r   r   r   _get_build_requires_editablem   s   
"z/SourceDistribution._get_build_requires_editablec                 C  sh   | j jr| j jr| j jr|  }n|  }| j j|\}}|r&| d| | j jj	|dd| j d d S )Nr   Znormalzbackend dependenciesr&   )
r   ZeditableZpermit_editable_wheelsZsupports_pyproject_editabler4   r3   r   r    r!   r(   )r   r   Z
build_reqsr#   r$   r   r   r   r   w   s   


z&SourceDistribution._install_build_reqsconflicting_withstrconflicting_reqsset[tuple[str, str]]c                 C  s2   d}|j | j|ddd t|D d}t|)NzZSome build dependencies for {requirement} conflict with {conflicting_with}: {description}., c                 s  s"    | ]\}}| d | V  qdS )z is incompatible with Nr   ).0Z	installedZwantedr   r   r   	<genexpr>   s
    
z6SourceDistribution._raise_conflicts.<locals>.<genexpr>)requirementr5   description)formatr   r*   r-   r   )r   r5   r7   format_stringerror_messager   r   r   r!      s   
z#SourceDistribution._raise_conflictsr$   set[str]c                 C  s,   d}|j | jdttt|d}t|)NzASome build dependencies for {requirement} are missing: {missing}.r9   )r<   r$   )r>   r   r*   r+   r,   r-   r   )r   r$   r?   r@   r   r   r   r"      s   z&SourceDistribution._raise_missing_reqsN)r   r   )r   r   )r   r
   r   r   r   r   r   r   )r   r
   r   r   )r   r.   )r5   r6   r7   r8   r   r   )r$   rA   r   r   )__name__
__module____qualname____doc__propertyr   r   r%   r   r3   r4   r   r!   r"   r   r   r   r   r      s    


&




r   )Z
__future__r   ZloggingZcollections.abcr   typingr   Zpip._internal.build_envr   Z pip._internal.distributions.baser   Zpip._internal.exceptionsr   Zpip._internal.metadatar   Zpip._internal.utils.subprocessr	   r
   Z	getLoggerrB   r)   r   r   r   r   r   <module>   s    
