U
    @{?^Ø  ã                   @   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   Zstring_typesÚsplitÚtupleÚlistÚAssertionError)Ú
find_links© r   ú6/usr/lib/python3/dist-packages/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.
    Z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   ZsetupÚxTF)
ÚargsÚinstall_dirZexclude_scriptsZalways_copyZbuild_directoryZeditableZupgradeZmulti_versionZ	no_reportÚuser)
Ú	__class__Úget_option_dictÚclearÚupdateÚitemsÚdependency_linksr   Úget_egg_cache_dirr   Zensure_finalized)ÚdistÚreqZtmp_distÚoptsZlinksr   Úcmdr   r   r   Ú_legacy_fetch_build_egg   s6    

þ       ür)   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r”t	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  ¡ }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.Z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)Zmetadata)&Úpkg_resourcesZget_distributionZDistributionNotFoundZannouncer   ZWARNr)   Ústrip_markerr   r   ÚosÚenvironr   r#   ÚextendÚpathÚrealpathr$   ZEnvironmentÚfind_distributionsZcan_addr   ÚsysÚ
executableÚappendZurlÚstrÚ
subprocessZ
check_callZCalledProcessErrorr   ÚglobÚjoinZegg_nameZinstall_as_eggZPathMetadataZDistributionZfrom_filename)r%   r&   r'   Úquietr   r   Zeggs_dirZenvironmentZegg_distZtmpdirr(   ÚlinkÚer*   Zdist_locationZdist_metadatar   r   r   Úfetch_build_egg8   sŒ    ü



    ü



 ÿ ÿr=   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)r+   ZRequirementÚparser6   Zmarker)r&   r   r   r   r,      s    r,   )r8   r-   r7   r3   Z	distutilsr   Zdistutils.errorsr   r+   Zsetuptools.command.easy_installr   Zsetuptools.externr   Zsetuptools.wheelr   Z
py31compatr   r   r)   r=   r,   r   r   r   r   Ú<module>   s    U