U
    K÷†iM  ã                   @   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   ÚtempdirÚsetattrZsave_user_site_setting)ZmonkeypatchÚ	user_baseÚ	user_site© r
   ú=/tmp/pip-unpacked-wheel-ffidw15h/setuptools/tests/fixtures.pyÚuser_override   s    


r   c              	   c   s   |   ¡ }|V  W 5 Q R X d S )N)Zas_cwd)ZtmpdirÚorigr
   r
   r   Ú
tmpdir_cwd   s    
r   TÚ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.
    ÚgitÚclonez%https://github.com/pypa/sampleproject)ÚcwdzUnable to clone sampleprojectZsampleproject)Ú
subprocessÚ
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-mÚbuildz--outdir)r   Zsession_locked_tmp_dirÚnextÚglobr   r   ÚrootdirÚexistsÚAssertionErrorr   Úcheck_outputr   Ú
executabler    )Útmp_path_factoryr   ÚtmpÚsdistÚwheelr
   r
   r   Ú_build_distributionsG   s*      ÿ
ú
r3   )r   c                 C   s8   t  d¡}|r&t j |¡r&t|ƒ ¡ S t| |ƒ\}}|S )NZPRE_BUILT_SETUPTOOLS_SDIST©ÚosÚgetenvr   r+   r   Úresolver3   )r/   r   Úprebuiltr1   Ú_r
   r
   r   Úsetuptools_sdistb   s
    
r:   c                 C   s8   t  d¡}|r&t j |¡r&t|ƒ ¡ S t| |ƒ\}}|S )NZPRE_BUILT_SETUPTOOLS_WHEELr4   )r/   r   r8   r9   r2   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)Ú
PYTHONPATH)
r   Ú
VirtualEnvr   r   ÚrootÚcreate_optsr    Úreqr   Úcreate)r$   r;   Úenvr
   r
   r   r<   v   s    

r<   c                 C   s.   t  ¡ }t | d ¡|_ddg|_| ¡  |S )z7Virtual env without any version of setuptools installedÚvenv_without_setuptoolsr=   ú
--no-wheel©r   r?   r   r   r@   rA   Z
ensure_env©r$   rD   r
   r
   r   rE   Œ   s
    
rE   c                 C   s2   t  ¡ }t | d ¡|_ddddg|_| ¡  |S )z1Virtual env without any common packages installedÚ	bare_venvr=   z--no-piprF   z	--no-seedrG   rH   r
   r
   r   rI   –   s
    rI   )r   r5   r   r   Úpathlibr   r   r"   r   r   r   Zfixturer   r   r   r&   r3   r:   r;   r<   rE   rI   r
   r
   r
   r   Ú<module>   s4   





	

	

	