o
    5‘ðiÀ/  ã                   @   sv  d dl Z d dlZd dl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	Z
d dlZd dlZd dlmZ ddlmZmZ ddlmZ ejdd„ ƒZejd	d
„ ƒZejddd�dd„ ƒZejdd„ ƒZejdd„ ƒZdd„ Zejdd�dd„ ƒZejdd�dd„ ƒZejdd„ ƒZejdd„ ƒZejdd „ ƒZd!d"„ Z d0d#d$„Z!d%d&„ Z"d'd(„ Z#d)d*e!ddd+fd,d-„Z$ejd.d/„ ƒZ%dS )1é    N)ÚPath)Ú
safer_nameé   )ÚcontextsÚenvironment)ÚDALSc              
   c   s®   � t  ¡ �H}|  d|¡ t  ¡ �%}|  d|¡ t  ¡ � dV  W d  ƒ n1 s)w   Y  W d  ƒ n1 s8w   Y  W d  ƒ dS W d  ƒ dS 1 sPw   Y  dS )za
    Override site.USER_BASE and site.USER_SITE with temporary directories in
    a context.
    zsite.USER_BASEzsite.USER_SITEN)r   ÚtempdirÚsetattrÚsave_user_site_setting)ÚmonkeypatchÚ	user_baseÚ	user_site© r   úX/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/tests/fixtures.pyÚuser_override   s   €


ÿ€þþ"þr   c                 c   s6   � |   ¡ �}|V  W d   ƒ d S 1 sw   Y  d S ©N)Úas_cwd)ÚtmpdirÚorigr   r   r   Ú
tmpdir_cwd"   s   €
"ÿr   TÚsession)ÚautouseÚscopec                 C   sN   | j j d¡s	dS t t¡� tj d¡ W d  ƒ dS 1 s w   Y  dS )zù
    Workaround pytest-dev/pytest-xdist#376

    ``pytest-xdist`` tends to inject '' into ``sys.path``,
    which may break certain isolation expectations.
    Remove the entry so the import
    machinery behaves the same irrespective of xdist.
    ÚxdistNÚ )	ÚconfigÚpluginmanagerÚ
has_pluginÚ
contextlibÚsuppressÚ
ValueErrorÚsysÚpathÚremove)Úrequestr   r   r   Úworkaround_xdist_376(   s
   
"ÿr%   c                 C   sH   g d¢}zt j|t| ƒd� W | d S  ty#   t d¡ Y | d S w )z<
    Clone the 'sampleproject' and return a path to it.
    )ÚgitÚclonez%https://github.com/pypa/sampleproject)ÚcwdzUnable to clone sampleprojectÚsampleproject)Ú
subprocessÚ
check_callÚstrÚ	ExceptionÚpytestÚskip)Útmp_pathÚcmdr   r   r   Úsample_project9   s   þþr2   c                 c   s8   � t  | ¡� d V  W d   ƒ d S 1 sw   Y  d S r   )r"   r   )r2   r   r   r   Úsample_project_cwdF   s   €"ÿr3   c              
   C   sÜ   t  || d¡�]}t| d¡d ƒ}t| d¡d ƒ}|r'|r'||fW  d   ƒ S t|jjdƒ ¡ r2J ‚t 	t
jdddt|ƒt|jjƒg¡ t|jjdƒ ¡ rOJ ‚t| d¡ƒt| d¡ƒfW  d   ƒ S 1 sgw   Y  d S )NÚ
dist_buildz*.tar.gzz*.whlzbuild/lib/buildú-mÚbuildz--outdir)r   Úsession_locked_tmp_dirÚnextÚglobr   r   ÚrootdirÚexistsr*   Úcheck_outputr!   Ú
executabler,   )Útmp_path_factoryr$   ÚtmpÚsdistÚwheelr   r   r   Ú_build_distributionsT   s*   ÿú	
ú
$érB   )r   c                 C   s8   t  d¡}|rt j |¡rt|ƒ ¡ S t| |ƒ\}}|S )NÚPRE_BUILT_SETUPTOOLS_SDIST©ÚosÚgetenvr"   r;   r   ÚresolverB   )r>   r$   Úprebuiltr@   Ú_r   r   r   Úsetuptools_sdisto   ó
   
rJ   c                 C   s8   t  d¡}|rt j |¡rt|ƒ ¡ S t| |ƒ\}}|S )NÚPRE_BUILT_SETUPTOOLS_WHEELrD   )r>   r$   rH   rI   rA   r   r   r   Úsetuptools_wheely   rK   rM   c                 C   sd   t  ¡ }t | d ¡|_ddg|_t|ƒ|_tj dd�� | 	¡ W  d  ƒ S 1 s+w   Y  dS )z?Virtual env with the version of setuptools under test installedÚvenvú--no-setuptoolsz--wheel=bundleN)Ú
PYTHONPATH)
r   Ú
VirtualEnvr"   r   ÚrootÚcreate_optsr,   Úreqr   Úcreate)r0   rM   Úenvr   r   r   rN   ƒ   s   

$ÿrN   c                 C   s.   t  ¡ }t | d ¡|_ddg|_| ¡  |S )z7Virtual env without any version of setuptools installedÚvenv_without_setuptoolsrO   ú
--no-wheel©r   rQ   r"   r   rR   rS   Ú
ensure_env©r0   rV   r   r   r   rW   ™   ó
   
rW   c                 C   s.   t  ¡ }t | d ¡|_g d¢|_| ¡  |S )z1Virtual env without any common packages installedÚ	bare_venv)rO   z--no-piprX   z	--no-seedrY   r[   r   r   r   r]   £   r\   r]   c                 C   s–   t |ƒdksJ ‚t | d¡�3}|D ]'\}}t | d¡¡}tj|d�}t | ¡ ƒ|_t	t
 
¡ ƒ|_|j||d� qW d  ƒ dS 1 sDw   Y  dS )z…
    Create a simple sdist tarball at dist_path, containing the files
    listed in ``files`` as ``(filename, content)`` tuples.
    r   zw:gzúutf-8)Úname)ÚfileobjN)ÚlenÚtarfileÚopenÚioÚBytesIOÚencodeÚTarInfoÚgetvalueÚsizeÚintÚtimeÚmtimeÚaddfile)Ú	dist_pathÚfilesÚdistÚfilenameÚcontentÚ
file_bytesÚ	file_infor   r   r   Ú
make_sdist­   s   û"ÿru   c                 C   sN   dt d|›d|›d�ƒfdg}|r | dt d| ¡ › d�ƒf¡ t| |ƒ d	S )
a  
    Create a simple sdist tarball at dist_path, containing just a simple
    setup.py.

    If ``setuptools_wheel`` is passed, a ``pyproject.toml`` file will also
    be generated and the passed value will be used as location for
    setuptools (as build dependency).
    úsetup.pyz`                 import setuptools
                 setuptools.setup(
                     name=z,
                     version=z%
                 )
                 ©ú	setup.cfgr   úpyproject.tomlzI                [build-system]
                requires = ["setuptools @ zK"]
                build-backend = "setuptools.build_meta"
                N)r   ÚappendÚas_uriru   )rn   ÚdistnameÚversionrM   ro   r   r   r   Úmake_trivial_sdist¾   s*   ýüÿþóþÿþr~   c           
   
      sÄ   d|v sJ ‚|  d¡‰ ˆ d }‡ fdd„tdtˆ ƒd ƒD ƒ}td|›d|›d|›d	|›d
�	ƒ}d}d|ftj |d¡|fg}|dd… D ]}tjj|  d¡dg Ž }	| |	df¡ qEt| |ƒ dS )z¼
    Make an sdist tarball with distname and version which also contains one
    package with the same name as distname.  The top-level package is
    designated a namespace package).
    Ú.r   c                    s   g | ]}d   ˆ d|… ¡‘qS )r   N)Újoin)Ú.0Úidx©Úpartsr   r   Ú
<listcomp>ò   s    z$make_nspkg_sdist.<locals>.<listcomp>r   zE        import setuptools
        setuptools.setup(
            name=z,
            version=z,
            packages=z",
            namespace_packages=[z]
        )
    z7__import__('pkg_resources').declare_namespace(__name__)rv   ú__init__.pyNr   )	ÚsplitÚrangera   r   rE   r"   r€   rz   ru   )
rn   r|   r}   Ú	nspackageÚpackagesÚsetup_pyÚinitro   Úpackagerq   r   rƒ   r   Úmake_nspkg_sdistæ   s*   
 ýüûúÿrŽ   c                 C   s&   t | dtdƒj|||d�fdgƒ d S )Nrv   zå                import setuptools
                setuptools.setup(
                  name={name!r},
                  version={version!r},
                  python_requires={python_requires!r},
                )
                )r_   r}   Úpython_requiresrw   )ru   r   Úformat)rn   r|   r}   r�   r   r   r   Úmake_python_requires_sdist
  s   ÿ	öþðþr‘   Úfoobarz0.1r   c                 C   sš  t |ƒ}dd|› d|› �gtj | ¡gdœ}|r| |¡ tj | d¡}	t |	¡ |rjg }
g }|D ](}| |¡}|d ¡ v rA|}n|
}t	|t
tfƒrOd |¡}| |› d|› �¡ q1tdƒjd	 |
¡d	 |¡d
�}nd}ttj |	d¡ddd��}| |¡ W d  ƒ n1 sˆw   Y  |du r•tdƒ}ttj |	d¡ddd��}| || ¡ W d  ƒ n1 s³w   Y  tj | |› d|› d�¡}||||ƒ |	S )a—  Creates a source tree under path for a trivial test package that has a
    single requirement in setup_requires--a tarball for that requirement is
    also created and added to the dependency_links argument.

    ``distname`` and ``version`` refer to the name/version of the package that
    the test package requires via ``setup_requires``.  The name of the test
    package itself is just 'test_pkg'.
    Útest_pkgz0.0z==)r_   r}   Úsetup_requiresÚdependency_linkszname versionú;z: zg
            [metadata]
            {metadata}
            [options]
            {options}
            Ú
)ÚoptionsÚmetadatar   rx   Úwr^   )ÚencodingNzI            import setuptools
            setuptools.setup(**%r)
        rv   ú-z.tar.gz)r   rE   r"   ÚabspathÚupdater€   ÚmkdirÚpopr‡   Ú
isinstanceÚtupleÚlistrz   r   r�   rc   Úwrite)r"   r|   r}   Úmake_packageÚsetup_py_templateÚsetup_attrsÚuse_setup_cfgÚnormalized_distnameÚtest_setup_attrsr“   r˜   r™   r_   ÚvalueÚsectionÚtest_setup_cfg_contentsÚfÚfoobar_pathr   r   r   Úcreate_setup_requires_package"  sT   ü



ÿ÷ÿÿÿr°   c                 C   sd   t dƒt dƒt dƒdddœddid	œ}| g d
¢¡ | d }| ¡  tjj||d� | dd¡ |S )Nz‚
            [build-system]
            requires = ["setuptools"]
            build-backend = "setuptools.build_meta"
            z‰
            __import__('setuptools').setup(
                pbr=True,
                setup_requires=["pbr"],
            )
            z
            [metadata]
            name = mypkg

            [files]
            packages =
                mypkg
            r   zprint('Hello world!'))r†   zhello.pyztest.txtzAnother file in here.)ry   rv   rx   ÚmypkgÚother)Úpythonr5   ÚpipÚinstallÚpbrr±   )ÚprefixÚPBR_VERSIONz0.42)r   ÚrunrŸ   Újaracor"   r6   Úsetenv)r0   r   rN   ro   r·   r   r   r   Úpbr_packageo  s(   ÿÿÿþâ r¼   r   )&r   rd   rE   r*   r!   rb   rk   Úpathlibr   Újaraco.pathrº   r"   r.   Úsetuptools._normalizationr   r   r   r   Útextwrapr   Úfixturer   r   r%   r2   r3   rB   rJ   rM   rN   rW   r]   ru   r~   rŽ   r‘   r°   r¼   r   r   r   r   Ú<module>   s`    







	
	

	
	
($
ùM