o
    5‘ði@   ã                   @   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    úr/root/parts/websockify/install/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 )	z¡Find 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   ôþþþ

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