U
    uiM                     @   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-9osl9suo/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 rt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   





	

	

	