B
    `’»dØ  ã               @   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-k1jh9j23/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   s&    
r0   c             C   sœ  yt  d¡ W n* t jk
r8   |  dtj¡ t| |ƒS X yt  d¡ W n$ t jk
rl   |  dtj¡ Y nX t|ƒ}|  d¡}d|krt	dƒ‚dt
jks¤d	t
jkrªd
}nd}dt
jkr¾d}nd|krÔ|d d }nd}d|krút|d d ƒdd… }ng }| jr| | j¡ t
j |  ¡ ¡}t  ¡ }x.t  |¡D ] }||kr6| |¡r6|S q6W tƒ 0}	tjdddddd|	g}
|rŠ|
 d¡ |dk	r¢|
 d|f¡ |dk	rÊx|D ]}|
 d|f¡ q²W |jrà|
 |j¡ n|
 t|ƒ¡ yt |
¡ W n2 tjk
r. } zt	t|ƒƒ‚W dd}~X Y nX tt t
j  |	d¡¡d ƒ}t
j  || !¡ ¡}| "|¡ t  #|t
j  |d¡¡}t j$j%||d} | S Q R X dS )zLFetch an egg needed for building.

    Use pip/wheel to fetch/build a wheel.Úpipz­WARNING: 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_distÚtmpdirr/   ÚlinkÚer2   Údist_locationZdist_metadatar   r   r   Úfetch_build_egg8   sx    









rV   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   rV   r9   r   r   r   r   Ú<module>   s    U