U
    ٲg                     @   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mZ d dlZd dl	m
Z
 d dlmZ d dlmZ ddlmZ d	d
 Zdd Zdd Zdd ZdS )    N)log)DistutilsError)easy_install)six)Wheel   )TemporaryDirectoryc                 C   s*   t | tjr|  S t | ttfs&t| S )z8Ensure find-links option end-up being a list of strings.)
isinstancer   string_typessplittuplelistAssertionError)
find_links r   8/tmp/pip-unpacked-wheel-aqb5epr1/setuptools/installer.py_fixup_find_links   s    r   c                 C   s   |  ddgi}|d}|  |dd | d D  | jr|| jdd }d|krpt|d d | }d|f|d< |  }t|d	g|d
ddddd
d
dd}|	  ||S )zJFetch an egg needed for building.

    Legacy path using EasyInstall.
    script_argsr   c                 s   s"   | ]\}}|d kr||fV  qdS ))r   	site_dirs	index_urloptimizer   allow_hostsNr   ).0kvr   r   r   	<genexpr>    s   z*_legacy_fetch_build_egg.<locals>.<genexpr>Nr   r   setupxTF)
argsinstall_dirZexclude_scriptsZalways_copyZbuild_directoryeditableupgradeZmulti_versionZ	no_reportuser)
	__class__get_option_dictclearupdateitemsdependency_linksr   get_egg_cache_dirr   ensure_finalized)distreqZtmp_distoptslinksr   cmdr   r   r   _legacy_fetch_build_egg   s6    

       r0   c                 C   s  zt d W n. t jk
r<   | dtj t| | Y S X zt d W n$ t jk
rp   | dtj Y nX t|}| d}d|krt	ddt
jksd	t
jkrd
}nd}dt
jkrd}nd|kr|d d }nd}d|kr t|d d dd }ng }| jr|| j t
j|  }t  }t |D ]$}||kr:||r:|  S q:t 8}	tjdddddd|	g}
|r|
d |dk	r|
d|f |dk	r|D ]}|
d|f q|jr|
|j n|
t| zt|
 W n2 tjk
r0 } zt	t|W 5 d}~X Y nX ttt
j |	dd }t
j ||! }|"| t #|t
j |d}t j$j%||d} | W  5 Q R  S Q R X dS )zLFetch an egg needed for building.

    Use pip/wheel to fetch/build a wheel.pipzWARNING: The pip package is not available, falling back to EasyInstall for handling setup_requires/test_requires; this is deprecated and will be removed in a future version.wheelz,WARNING: The wheel package is not available.r   r   zQthe `allow-hosts` option is not supported when using pip to install requirements.Z	PIP_QUIETZPIP_VERBOSEFTZPIP_INDEX_URLNr   r   r   z-mz--disable-pip-version-checkz	--no-depsz-wz--quietz--index-urlz--find-linksz*.whlr   zEGG-INFO)metadata)&pkg_resourcesget_distributionDistributionNotFoundannouncer   WARNr0   strip_markerr$   r   osenvironr   r(   extendpathrealpathr)   Environmentfind_distributionscan_addr   sys
executableappendurlstr
subprocess
check_callCalledProcessErrorr   globjoinegg_nameZinstall_as_eggPathMetadataDistributionfrom_filename)r+   r,   r-   quietr   r   Zeggs_direnvironmentZegg_distZtmpdirr/   linker2   dist_locationZdist_metadatar   r   r   fetch_build_egg8   s    



    



  rU   c                 C   s   t jt| } d| _| S )z
    Return a new requirement without the environment marker to avoid
    calling pip with something like `babel; extra == "i18n"`, which
    would always be ignored.
    N)r4   RequirementparserF   marker)r,   r   r   r   r9      s    r9   )rJ   r:   rG   rB   	distutilsr   distutils.errorsr   r4   Zsetuptools.command.easy_installr   Zsetuptools.externr   Zsetuptools.wheelr   
py31compatr   r   r0   rU   r9   r   r   r   r   <module>   s    U