o
    LK&h@                      @   sp  d 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
mZ ddlZddlmZ dd	lmZmZ ejjZed
d\Z	 defdefdefdefdefdefdefdefdefdefg
ZdddZddiddidZdddZejdd fZd!Zejd"d# Zejd$d%d&d' Zej d(eejj!d)d* Z"d+d, Z#d-d. Z$d/d0 Z%d1d2 Z&d3d4 Z'dS )5a  Integration tests for setuptools that focus on building packages via pip.

The idea behind these tests is not to exhaustively check all the possible
combinations of packages, operating systems, supporting libraries, etc, but
rather check a limited number of popular packages and how they interact with
the exposed public API. This way if any change in API is introduced, we hope to
identify backward compatibility problems before publishing a release.

The number of tested packages is purposefully kept small, to minimise duration
and the associated maintenance cost (changes in the way these packages define
their build process may require changes in the tests).
    N)Enum)glob)md5)urlopen)Requirement   )ArchiverunvLATESTpippytestmypybotocore
kiwisolverbrotlipyyamlcharset-normalizerprotobufcelery)z
Cython<3.0)zmypy>=1.4.1)r   r   PYYAML_FORCE_CYTHON1CHARSET_NORMALIZER_USE_MYPYCyamlzgoogle.protobuf)r   r   -m
virtualenv)z--ignore-installedz--no-build-isolationc                 C   sB   t g tt| d  dd | dD }tjdtj|dS )Nz.venvc                 s   s    | ]}t |jV  qd S )N)strparent).0p r    f/var/www/html/venv/lib/python3.10/site-packages/setuptools/tests/integration/test_pip_install_sdist.py	<genexpr>f   s    zvenv_python.<locals>.<genexpr>z.venv/*/python*python)path)	r	   
VIRTUALENVr   r   shutilwhichospathsepjoin)tmp_pathpossible_pathr    r    r!   venv_pythonc   s   r-   T)autousec                 c   sn    t dt| }t j|dd |dd d V  td td tt| d td	 t|d
ddg d S )NDOWNLOAD_PATHT)exist_ok	USE_MYPYCr   <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~zTemporary directory:*zVirtual environment:r   r   freeze)	r(   getenvr   makedirssetenvprintmapr   r	   )r+   r-   monkeypatchdownload_pathr    r    r!   _preparej   s   r<   )packageversionc                 C   s   |ddf}t | ||}t| |}|r%td td| tg |d| t| i }tg |dd| tg |dt|| t| | dd}	d	|	 d
|	 d}
t|d|
g d S )Nr   r   r2   zDependencies:installz--force-reinstall-_zimport z; print(getattr(z, '__version__', 0))z-c)	retrieve_sdist
build_depsr8   r	   EXTRA_ENV_VARSgetINSTALL_OPTIONSIMPORT_NAMEreplace)r=   r>   r+   r-   setuptools_wheelvenv_pipsdistdepsenvpkgscriptr    r    r!   test_install_sdist}   s   


rP   c                 C   s   t dt|}t| |}tt j||  dD ]}|d |kr&t | qt j||d }t j|s@t	|d ||d  |S )z5Either use cached sdist file or download it from PyPIr/   r3   filenameurl
md5_digest)
r(   r5   r   retrieve_pypi_sdist_metadatar   r$   r*   unlinkexistsdownload)r=   r>   r+   r;   distfile	dist_filer    r    r!   rB      s   

rB   c                 C   s   |t u r| n|  d| }td| d}t|}W d    n1 s%w   Y  |d d r;td|  d| d|d d	 }|t u rK|d
 | n|d }tdd |\}|S )N/zhttps://pypi.org/pypi/z/jsoninfoyankedzRelease for  z was yankedr>   releasesurlsc                 S   s   | d dkS )NpackagetyperK   r    )dr    r    r!   <lambda>   s    z.retrieve_pypi_sdist_metadata.<locals>.<lambda>)r   r   jsonload
ValueErrorfilter)r=   r>   id_fmetadatareleaserK   r    r    r!   rT      s   rT   c                 C   s   t | }| }W d    n1 sw   Y  t| |ks"J t|d}|| W d    n1 s7w   Y  tj|sDJ d S )Nwb)	r   readr   	hexdigestopenwriter(   r$   rV   )rR   destrS   ri   datar    r    r!   rW      s   

rW   c                 C   sf   ddl m} t|}|t|}|di dg }|t| g 7 }dd |D }dd | D S )	zFind out what are the build dependencies for a package.

    "Manually" install them, since pip will not install build
    deps with `--no-build-isolation`.
    r   )tomllibzbuild-systemrequiresc                 S   s   i | ]}t |j|qS r    )r   name)r   rb   r    r    r!   
<dictcomp>   s    zbuild_deps.<locals>.<dictcomp>c                 S   s   g | ]
\}}|d kr|qS )
setuptoolsr    )r   kr
   r    r    r!   
<listcomp>   s    zbuild_deps.<locals>.<listcomp>)setuptools.compat.py310rs   r   loads_read_pyprojectrE   EXTRA_BUILD_DEPSitems)r=   
sdist_filers   archiver\   rL   requirementsr    r    r!   rC      s   rC   c                    s    fdd D }t |dS )Nc                 3   s0    | ]}t j |d kr |V  qdS )zpyproject.tomlN)r(   r$   basenameget_nameget_content)r   memberr   r    r!   r"      s    z"_read_pyproject.<locals>.<genexpr> )next)r   contentsr    r   r!   r|      s   

r|   )(__doc__rd   r(   r&   sysenumr   r   hashlibr   urllib.requestr   r   packaging.requirementsr   helpersr   r	   markintegration
pytestmarkr   EXAMPLESr}   rD   rG   
executabler%   rF   fixturer-   r<   parametrizeuses_networkrP   rB   rT   rW   rC   r|   r    r    r    r!   <module>   sb   



