o
    NZh@                      @   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pytestZmypyZbotocoreZ
kiwisolverbrotlipyyamlcharset-normalizerprotobufZcelery)z
Cython<3.0)zmypy>=1.4.1)r   r   ZPYYAML_FORCE_CYTHON1Z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   b/var/www/auris/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_pathZpossible_pathr   r   r   venv_pythonc   s   r&   T)Z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_okZ	USE_MYPYCr   <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~zTemporary directory:*zVirtual environment:r   r   freeze)	r"   getenvr   makedirsZsetenvprintmapr   r	   )r%   r&   Zmonkeypatchdownload_pathr   r   r   _preparej   s   r1   )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   r)   zDependencies:installz--force-reinstall-_zimport z; print(getattr(z, '__version__', 0))z-c)	retrieve_sdist
build_depsr.   r	   EXTRA_ENV_VARSgetINSTALL_OPTIONSIMPORT_NAMEreplace)r2   r3   r%   r&   Zsetuptools_wheelZvenv_pipsdistdepsenvpkgscriptr   r   r   test_install_sdist}   s   


rC   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'   r*   filenameurl
md5_digest)
r"   r,   r   retrieve_pypi_sdist_metadatar   r   r$   unlinkexistsdownload)r2   r3   r%   r0   distfileZ	dist_filer   r   r   r7      s   

r7   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 yankedr3   Zreleasesurlsc                 S   s   | d dkS )NZpackagetyper>   r   )dr   r   r   <lambda>   s    z.retrieve_pypi_sdist_metadata.<locals>.<lambda>)r   r   jsonload
ValueErrorfilter)r2   r3   Zid_fmetadatareleaser>   r   r   r   rG      s   rG   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   rI   )rE   destrF   rX   datar   r   r   rJ      s   

rJ   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   rR   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>)Zsetuptools.compat.py310rb   r   loads_read_pyprojectr:   EXTRA_BUILD_DEPSitems)r2   Z
sdist_filerb   archiverN   r?   requirementsr   r   r   r8      s   r8   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rm   r   r   r      s    z"_read_pyproject.<locals>.<genexpr> )next)rm   contentsr   rs   r   rj      s   

rj   )(__doc__rT   r"   r    sysenumr   r   hashlibr   urllib.requestr   r   Zpackaging.requirementsr   helpersr   r	   markZintegrationZ
pytestmarkr   ZEXAMPLESrk   r9   r<   
executabler   r;   Zfixturer&   r1   ZparametrizeZuses_networkrC   r7   rG   rJ   r8   rj   r   r   r   r   <module>   sb   

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