o
    5‘ðic  ã                   @   sn  d dl Z d dlZd dlZd dlZd dlZdejv ZdddœZdd„ Zd3d	d
„Z	d4dd„Z
ejjejdkdd�Zedd„ ƒZdd„ Zejjddd�dd„ ƒZdd„ Zdd„ ZdZej d¡ej dejdd ed!�ejdd"ed!�ejdd#ed!�d$d%d&g¡d'd(„ ƒƒZd)Zej d¡ej d*d+ejded!�g¡d,d-„ ƒƒZd.Zej d¡ej dd/ejdd0ed!�g¡d1d2„ ƒƒZdS )5é    NÚ__pypy__Tzutf-8)ÚtextÚencodingc                 C   s"   | rt  ¡ dkrtjd | d< | S )z¨
    On Windows, SYSTEMROOT must be present to avoid

    > Fatal Python error: _Py_HashRandomization_Init: failed to
    > get random numbers to initialize Python
    ÚWindowsÚ
SYSTEMROOT)ÚplatformÚsystemÚosÚenviron©Úenv© r   úg/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/tests/test_distutils_adoption.pyÚwin_sr   s   r   Ú	distutilsc                 K   s:   dj di tƒ ¤Ž}dd|g}| j|fdt|ƒit¤|¤ŽS )Nz+import {imports}; print(distutils.__file__)Úpythonú-cr   r   )ÚformatÚlocalsÚrunr   Ú_TEXT_KWARGS)ÚvenvÚimportsr   ÚkwargsÚpy_cmdÚcmdr   r   r   Úfind_distutils   s   
r   c                 C   s2   t  d¡}dd|g}t| j|fdt|ƒit¤ŽƒS )Nz³
        import sys
        is_distutils = lambda finder: finder.__class__.__name__ == "DistutilsMetaFinder"
        print(len(list(filter(is_distutils, sys.meta_path))))
        r   r   r   )ÚtextwrapÚdedentÚintr   r   r   )r   r   r   r   r   r   r   Úcount_meta_path   s
   ÿ
r    )é   é   z-stdlib distutils is removed from Python 3.12+)Úreasonc                 C   s@   t dd�}| jt| |d� tj¡vsJ ‚t| |d�dksJ ‚dS )z;
    Ensure stdlib distutils is used when appropriate.
    Ústdlib©ÚSETUPTOOLS_USE_DISTUTILSr   r   N©ÚdictÚnamer   Úsplitr	   Úsepr    ©r   r   r   r   r   Útest_distutils_stdlib1   s   
r-   c                 C   sF   t dd�}t| d|d�}| j| tj¡v sJ ‚t| |d�dks!J ‚dS )z:
    Ensure local distutils is used when appropriate.
    Úlocalr%   zsetuptools, distutils)r   r   r   é   N)r(   r   r)   r*   r	   r+   r    )r   r   Úlocr   r   r   Ú$test_distutils_local_with_setuptools;   s   
r1   ÚIS_PYPYz!pypy imports distutils on startupc                 C   s@   t dd�}| jt| |d� tj¡v sJ ‚t| |d�dksJ ‚dS )zZ
    Even without importing, the setuptools-local copy of distutils is
    preferred.
    r.   r%   r   r/   Nr'   r,   r   r   r   Útest_distutils_localE   s   
r3   c                 C   s   g d¢}| j |fi t¤Ž dS )zD
    Ensure pip can be imported.
    Regression test for #3002.
    )r   r   z
import pipN)r   r   )r   r   r   r   r   Útest_pip_importP   s   r4   c                   C   s   t dƒjjsJ ‚dS )z=
    Distutils module spec should have an origin. #2990.
    r   N)Ú
__import__Ú__spec__Úoriginr   r   r   r   Útest_distutils_has_originY   s   r8   a8  
# Depending on the importlib machinery and _distutils_hack, some imports are
# duplicated resulting in different module objects being loaded, which prevents
# patches as shown in #3042.
# This script provides a way of verifying if this duplication is happening.

from distutils import cmd
import distutils.command.sdist as sdist

# import last to prevent caching
from distutils import {imported_module}

for mod in (cmd, sdist):
    assert mod.{imported_module} == {imported_module}, (
        f"\n{{mod.dir_util}}\n!=\n{{{imported_module}}}"
    )

print("success")
Ú
tmpdir_cwd)Údistutils_versionÚimported_moduler$   Údir_util)ÚmarksÚ	file_utilÚarchive_util)r.   r<   )r.   r>   )r.   r?   c                 C   sN   t | d�}tj|d�}dd|g}|j|fdt|ƒit¤Ž ¡ }|dks%J ‚d S )Nr%   ©r;   r   r   r   Úsuccess)r(   Ú!ENSURE_IMPORTS_ARE_NOT_DUPLICATEDr   r   r   r   Ústrip)r:   r;   r   r   Úscriptr   Úoutputr   r   r   Ú)test_modules_are_not_duplicated_on_importu   s
   

rF   z¹
import types
import distutils.dist as dist
from distutils import log
if isinstance(dist.log, types.ModuleType):
    assert dist.log == log, f"\n{dist.log}\n!=\n{log}"
print("success")
r:   r.   c                 C   sB   t | d�}ddtg}|j|fdt|ƒit¤Ž ¡ }|dksJ ‚d S )Nr%   r   r   r   rA   )r(   Ú#ENSURE_LOG_IMPORT_IS_NOT_DUPLICATEDr   r   r   rC   )r:   r   r   r   rE   r   r   r   Ú+test_log_module_is_not_duplicated_on_import“   s   
	
rH   zý
from setuptools.modified import newer
from {imported_module}.errors import DistutilsError

# Can't use pytest.raises in this context
try:
    newer("", "")
except DistutilsError:
    print("success")
else:
    raise AssertionError("Expected to raise")
)r.   r   zsetuptools._distutilsc                 C   sJ   t | d�}ddtj|d�g}|j|fdt|ƒit¤Ž ¡ }|dks#J ‚d S )Nr%   r   r   r@   r   rA   )r(   Ú(ENSURE_CONSISTENT_ERROR_FROM_MODIFIED_PYr   r   r   r   rC   )r:   r;   r   r   r   rE   r   r   r   Ú&test_consistent_error_from_modified_py°   s   
ÿýrJ   )r   N)N)r	   r   Úsysr   ÚpytestÚbuiltin_module_namesr2   r   r   r   r    ÚmarkÚskipifÚversion_infoÚskip_without_stdlib_distutilsr-   r1   Úxfailr3   r4   r8   rB   ÚusefixturesÚparametrizeÚparamrF   rG   rH   rI   rJ   r   r   r   r   Ú<module>   sl    



þ
	


	
úþ

þþ
ÿüþ