U
    ±§fM  ã                   @   sê   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m	Z	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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S )é    N)ÚPathé   )ÚcontextsÚenvironmentc                 c   s^   t  ¡ L}|  d|¡ t  ¡ ,}|  d|¡ t  ¡  dV  W 5 Q R X W 5 Q R X W 5 Q R X 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   ZtempdirÚsetattrZsave_user_site_setting)ZmonkeypatchÚ	user_baseÚ	user_site© r	   ú8lib/python3.8/site-packages/setuptools/tests/fixtures.pyÚuser_override   s    


r   c              	   c   s   |   ¡ }|V  W 5 Q R X d S )N)Zas_cwd)ZtmpdirZorigr	   r	   r
   Ú
tmpdir_cwd   s    
r   TZsession)ZautouseÚscopec              	   C   s8   | j j d¡sdS t t¡ tj d¡ W 5 Q R X 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.
    ZxdistNÚ )	ÚconfigZpluginmanagerZ
has_pluginÚ
contextlibÚsuppressÚ
ValueErrorÚsysÚpathÚremove)Úrequestr	   r	   r
   Úworkaround_xdist_376!   s    
r   c                 C   sH   dddg}zt j|t| ƒd W n tk
r>   t d¡ Y nX | d S )z<
    Clone the 'sampleproject' and return a path to it.
    ZgitZclonez%https://github.com/pypa/sampleproject)ÚcwdzUnable to clone sampleprojectZsampleproject)Ú
subprocessZ
check_callÚstrÚ	ExceptionÚpytestÚskip)Útmp_pathÚcmdr	   r	   r
   Úsample_project2   s    
r    c              
   C   sÎ   t  || d¡¶}t| d¡d ƒ}t| d¡d ƒ}|rL|rL||fW  5 Q R £ S t|jjdƒ ¡ rbt‚t	 
tjdddt|ƒt|jjƒg¡ t|jjdƒ ¡ rœt‚t| d¡ƒt| d¡ƒfW  5 Q R £ S Q R X d S )NZ
dist_buildz*.tar.gzz*.whlzbuild/lib/buildz-mZbuildz--outdir)r   Zsession_locked_tmp_dirÚnextZglobr   r   ZrootdirÚexistsÚAssertionErrorr   Zcheck_outputr   Ú
executabler   )Útmp_path_factoryr   ZtmpÚsdistÚwheelr	   r	   r
   Ú_build_distributionsG   s*      ÿ
ú
r(   )r   c                 C   s8   t  d¡}|r&t j |¡r&t|ƒ ¡ S t| |ƒ\}}|S )NZPRE_BUILT_SETUPTOOLS_SDIST©ÚosÚgetenvr   r"   r   Zresolver(   )r%   r   Úprebuiltr&   Ú_r	   r	   r
   Úsetuptools_sdistb   s
    
r.   c                 C   s8   t  d¡}|r&t j |¡r&t|ƒ ¡ S t| |ƒ\}}|S )NZPRE_BUILT_SETUPTOOLS_WHEELr)   )r%   r   r,   r-   r'   r	   r	   r
   Úsetuptools_wheell   s
    
r/   c              
   C   sX   t  ¡ }t | d ¡|_ddg|_t|ƒ|_tj dd | 	¡ W  5 Q R £ S Q R X dS )z?Virtual env with the version of setuptools under test installedÚvenvú--no-setuptoolsz--wheel=bundleN)Z
PYTHONPATH)
r   Ú
VirtualEnvr   r   ÚrootÚcreate_optsr   Zreqr   Zcreate)r   r/   Úenvr	   r	   r
   r0   v   s    

r0   c                 C   s.   t  ¡ }t | d ¡|_ddg|_| ¡  |S )z7Virtual env without any version of setuptools installedÚvenv_without_setuptoolsr1   ú
--no-wheel©r   r2   r   r   r3   r4   Z
ensure_env©r   r5   r	   r	   r
   r6   Œ   s
    
r6   c                 C   s2   t  ¡ }t | d ¡|_ddddg|_| ¡  |S )z1Virtual env without any common packages installedÚ	bare_venvr1   z--no-pipr7   z	--no-seedr8   r9   r	   r	   r
   r:   –   s
    r:   )r*   r   r   r   Úpathlibr   r   r   r   r   r   Zfixturer   r   r   r    r(   r.   r/   r0   r6   r:   r	   r	   r	   r
   Ú<module>   s4   





	

	

	