3
yYði­Ÿ  ã               @   s  d Z ddlZ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mZ ejƒ dkrpddl	mZ ejZnG d	d
„ d
ƒZeƒ ZeejjfZyddlmZ W n ek
r´   Y nX dd„ Zd dd„Zdd„ Zdd„ Zd!dd„ZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZ dS )"a@  
Improved support for Microsoft Visual C++ compilers.

Known supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
    Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64)
    Microsoft Windows SDK 6.1 (x86, x64, ia64)
    Microsoft Windows SDK 7.0 (x86, x64, ia64)

Microsoft Visual C++ 10.0:
    Microsoft Windows SDK 7.1 (x86, x64, ia64)

Microsoft Visual C++ 14.0:
    Microsoft Visual C++ Build Tools 2015 (x86, x64, arm)
    Microsoft Visual Studio 2017 (x86, x64, arm, arm64)
    Microsoft Visual Studio Build Tools 2017 (x86, x64, arm, arm64)
é    N)ÚLegacyVersion)Úfilterfalseé   )Úget_unpatchedÚWindows)Úwinregc               @   s   e Zd ZdZdZdZdZdS )r   N)Ú__name__Ú
__module__Ú__qualname__Ú
HKEY_USERSÚHKEY_CURRENT_USERÚHKEY_LOCAL_MACHINEÚHKEY_CLASSES_ROOT© r   r   ú5/tmp/pip-build-ue6tjl93/setuptools/setuptools/msvc.pyr   (   s   r   )ÚRegc             C   sž   d}|d| f }yt j|dƒ}W nJ tk
rj   y|d| f }t j|dƒ}W n tk
rd   d}Y nX Y nX |r’tjjjj|dƒ}tjj|ƒr’|S ttƒ| ƒS )a+  
    Patched "distutils.msvc9compiler.find_vcvarsall" to use the standalone
    compiler build for Python (VCForPython). Fall back to original behavior
    when the standalone compiler is not available.

    Redirect the path of "vcvarsall.bat".

    Known supported compilers
    -------------------------
    Microsoft Visual C++ 9.0:
        Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64)

    Parameters
    ----------
    version: float
        Required Microsoft Visual C++ version.

    Return
    ------
    vcvarsall.bat path: str
    z-Software\%sMicrosoft\DevDiv\VCForPython\%0.1fÚ Ú
installdirzWow6432Node\Nzvcvarsall.bat)	r   Ú	get_valueÚKeyErrorÚosÚpathÚjoinÚisfiler   Úmsvc9_find_vcvarsall)ÚversionZVC_BASEÚkeyÚ
productdirÚ	vcvarsallr   r   r   r   ?   s    r   Úx86c             O   sŽ   yt tƒ}|| |f|ž|ŽS  tjjk
r2   Y n tk
rD   Y nX yt|| ƒjƒ S  tjjk
rˆ } zt|| |ƒ ‚ W Y dd}~X nX dS )aœ  
    Patched "distutils.msvc9compiler.query_vcvarsall" for support extra
    compilers.

    Set environment without use of "vcvarsall.bat".

    Known supported compilers
    -------------------------
    Microsoft Visual C++ 9.0:
        Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64)
        Microsoft Windows SDK 6.1 (x86, x64, ia64)
        Microsoft Windows SDK 7.0 (x86, x64, ia64)

    Microsoft Visual C++ 10.0:
        Microsoft Windows SDK 7.1 (x86, x64, ia64)

    Parameters
    ----------
    ver: float
        Required Microsoft Visual C++ version.
    arch: str
        Target architecture.

    Return
    ------
    environment: dict
    N)	r   Úmsvc9_query_vcvarsallÚ	distutilsÚerrorsÚDistutilsPlatformErrorÚ
ValueErrorÚEnvironmentInfoÚ
return_envÚ_augment_exception)ÚverÚarchÚargsÚkwargsÚorigÚexcr   r   r   r    j   s    r    c             C   sn   yt tƒ| ƒS  tjjk
r$   Y nX yt| dd�jƒ S  tjjk
rh } zt|dƒ ‚ W Y dd}~X nX dS )a'  
    Patched "distutils._msvccompiler._get_vc_env" for support extra
    compilers.

    Set environment without use of "vcvarsall.bat".

    Known supported compilers
    -------------------------
    Microsoft Visual C++ 14.0:
        Microsoft Visual C++ Build Tools 2015 (x86, x64, arm)
        Microsoft Visual Studio 2017 (x86, x64, arm, arm64)
        Microsoft Visual Studio Build Tools 2017 (x86, x64, arm, arm64)

    Parameters
    ----------
    plat_spec: str
        Target architecture.

    Return
    ------
    environment: dict
    g      ,@)Ú
vc_min_verN)r   Úmsvc14_get_vc_envr!   r"   r#   r%   r&   r'   )Z	plat_specr-   r   r   r   r/   ™   s    
r/   c              O   sB   dt jkr4ddl}t|jƒtdƒk r4|jjj| |ŽS tt	ƒ| |ŽS )z¦
    Patched "distutils._msvccompiler.gen_lib_options" for fix
    compatibility between "numpy.distutils" and "distutils._msvccompiler"
    (for Numpy < 1.11.2)
    znumpy.distutilsr   Nz1.11.2)
ÚsysÚmodulesZnumpyr   Ú__version__r!   Z	ccompilerZgen_lib_optionsr   Úmsvc14_gen_lib_options)r*   r+   Únpr   r   r   r3   ¿   s
    
r3   r   c             C   s¬   | j d }d|jƒ ks"d|jƒ kr d}|jf tƒ Ž}d}|dkrr|jƒ jdƒdkrh|d	7 }||d
 7 }q |d7 }n.|dkr�|d7 }||d 7 }n|dkr |d7 }|f| _ dS )zl
    Add details to the exception message to help guide the user
    as to what action will resolve it.
    r   r   zvisual cz0Microsoft Visual C++ {version:0.1f} is required.z-www.microsoft.com/download/details.aspx?id=%dg      "@Zia64r   z* Get it with "Microsoft Windows SDK 7.0": iB  z% Get it from http://aka.ms/vcpython27g      $@z* Get it with "Microsoft Windows SDK 7.1": iW   g      ,@zj Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-toolsNéÿÿÿÿ)r*   ÚlowerÚformatÚlocalsÚfind)r-   r   r)   ÚmessageÚtmplZ
msdownloadr   r   r   r'   Ì   s     

r'   c               @   sb   e Zd ZdZejddƒjƒ Zdd„ Ze	dd„ ƒZ
dd	„ Zd
d„ Zddd„Zddd„Zddd„ZdS )ÚPlatformInfoz‚
    Current and Target Architectures informations.

    Parameters
    ----------
    arch: str
        Target architecture.
    Zprocessor_architecturer   c             C   s   |j ƒ jddƒ| _d S )NÚx64Úamd64)r6   Úreplacer)   )Úselfr)   r   r   r   Ú__init__ü   s    zPlatformInfo.__init__c             C   s   | j | j jdƒd d … S )NÚ_r   )r)   r9   )r@   r   r   r   Ú
target_cpuÿ   s    zPlatformInfo.target_cpuc             C   s
   | j dkS )Nr   )rC   )r@   r   r   r   Útarget_is_x86  s    zPlatformInfo.target_is_x86c             C   s
   | j dkS )Nr   )Úcurrent_cpu)r@   r   r   r   Úcurrent_is_x86  s    zPlatformInfo.current_is_x86Fc             C   s.   | j dkr|rdS | j dkr$|r$dS d| j  S )uk  
        Current platform specific subfolder.

        Parameters
        ----------
        hidex86: bool
            return '' and not 'Â†' if architecture is x86.
        x64: bool
            return 'd' and not 'md64' if architecture is amd64.

        Return
        ------
        subfolder: str
            '	arget', or '' (see hidex86 parameter)
        r   r   r>   z\x64z\%s)rE   )r@   Úhidex86r=   r   r   r   Úcurrent_dir	  s    zPlatformInfo.current_dirc             C   s.   | j dkr|rdS | j dkr$|r$dS d| j  S )ar  
        Target platform specific subfolder.

        Parameters
        ----------
        hidex86: bool
            return '' and not '\x86' if architecture is x86.
        x64: bool
            return '\x64' and not '\amd64' if architecture is amd64.

        Return
        ------
        subfolder: str
            '\current', or '' (see hidex86 parameter)
        r   r   r>   z\x64z\%s)rC   )r@   rG   r=   r   r   r   Ú
target_dir  s    zPlatformInfo.target_dirc             C   s0   |rdn| j }| j|krdS | jƒ jdd| ƒS )ao  
        Cross platform specific subfolder.

        Parameters
        ----------
        forcex86: bool
            Use 'x86' as current architecture even if current acritecture is
            not x86.

        Return
        ------
        subfolder: str
            '' if target architecture is current architecture,
            '\current_target' if not.
        r   r   ú\z\%s_)rE   rC   rI   r?   )r@   Úforcex86Úcurrentr   r   r   Ú	cross_dir5  s    zPlatformInfo.cross_dirN)FF)FF)F)r   r	   r
   Ú__doc__Úsafe_envÚgetr6   rE   rA   ÚpropertyrC   rD   rF   rH   rI   rM   r   r   r   r   r<   ñ   s   

r<   c               @   sª   e Zd ZdZejejejejfZ	dd„ Z
edd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZddd„Zdd„ ZdS )ÚRegistryInfoz 
    Microsoft Visual Studio related registry informations.

    Parameters
    ----------
    platform_info: PlatformInfo
        "PlatformInfo" instance.
    c             C   s
   || _ d S )N)Úpi)r@   Zplatform_infor   r   r   rA   Z  s    zRegistryInfo.__init__c             C   s   dS )z<
        Microsoft Visual Studio root registry key.
        ZVisualStudior   )r@   r   r   r   Úvisualstudio]  s    zRegistryInfo.visualstudioc             C   s   t jj| jdƒS )z;
        Microsoft Visual Studio SxS registry key.
        ZSxS)r   r   r   rT   )r@   r   r   r   Úsxsd  s    zRegistryInfo.sxsc             C   s   t jj| jdƒS )z8
        Microsoft Visual C++ VC7 registry key.
        ZVC7)r   r   r   rU   )r@   r   r   r   Úvck  s    zRegistryInfo.vcc             C   s   t jj| jdƒS )z;
        Microsoft Visual Studio VS7 registry key.
        ZVS7)r   r   r   rU   )r@   r   r   r   Úvsr  s    zRegistryInfo.vsc             C   s   dS )z?
        Microsoft Visual C++ for Python registry key.
        zDevDiv\VCForPythonr   )r@   r   r   r   Úvc_for_pythony  s    zRegistryInfo.vc_for_pythonc             C   s   dS )z-
        Microsoft SDK registry key.
        zMicrosoft SDKsr   )r@   r   r   r   Úmicrosoft_sdk€  s    zRegistryInfo.microsoft_sdkc             C   s   t jj| jdƒS )z>
        Microsoft Windows/Platform SDK registry key.
        r   )r   r   r   rY   )r@   r   r   r   Úwindows_sdk‡  s    zRegistryInfo.windows_sdkc             C   s   t jj| jdƒS )z<
        Microsoft .NET Framework SDK registry key.
        ZNETFXSDK)r   r   r   rY   )r@   r   r   r   Ú	netfx_sdkŽ  s    zRegistryInfo.netfx_sdkc             C   s   dS )z<
        Microsoft Windows Kits Roots registry key.
        zWindows Kits\Installed Rootsr   )r@   r   r   r   Úwindows_kits_roots•  s    zRegistryInfo.windows_kits_rootsFc             C   s(   | j jƒ s|rdnd}tjjd|d|ƒS )a
  
        Return key in Microsoft software registry.

        Parameters
        ----------
        key: str
            Registry key path where look.
        x86: str
            Force x86 software registry.

        Return
        ------
        str: value
        r   ZWow6432NodeZSoftwareÚ	Microsoft)rS   rF   r   r   r   )r@   r   r   Znode64r   r   r   Ú	microsoftœ  s    zRegistryInfo.microsoftc             C   sÂ   t j}t j}| j}xª| jD ] }y||||ƒd|ƒ}W nZ ttfk
rŽ   | jjƒ sˆy||||dƒd|ƒ}W qŠ ttfk
r„   wY qŠX nwY nX yt j	||ƒd S  ttfk
r¸   Y qX qW dS )a  
        Look for values in registry in Microsoft software registry.

        Parameters
        ----------
        key: str
            Registry key path where look.
        name: str
            Value name to find.

        Return
        ------
        str: value
        r   TN)
r   ÚKEY_READÚOpenKeyr^   ÚHKEYSÚOSErrorÚIOErrorrS   rF   ÚQueryValueEx)r@   r   Únamer_   ZopenkeyÚmsÚhkeyÚbkeyr   r   r   Úlookup®  s"    

zRegistryInfo.lookupN)F)r   r	   r
   rN   r   r   r   r   r   ra   rA   rQ   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r^   ri   r   r   r   r   rR   L  s"   
rR   c               @   s$  e Zd ZdZejddƒZejddƒZejdeƒZd3dd„Z	d	d
„ Z
dd„ Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd „ ƒZed!d"„ ƒZed#d$„ ƒZed%d&„ ƒZed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZed-d.„ ƒZd/d0„ Zd4d1d2„ZdS )5Ú
SystemInfozê
    Microsoft Windows and Visual Studio related system inormations.

    Parameters
    ----------
    registry_info: RegistryInfo
        "RegistryInfo" instance.
    vc_ver: float
        Required Microsoft Visual C++ version.
    ÚWinDirr   ÚProgramFileszProgramFiles(x86)Nc             C   s"   || _ | j j| _|p| jƒ | _d S )N)ÚrirS   Ú_find_latest_available_vc_verÚvc_ver)r@   Zregistry_inforo   r   r   r   rA   ã  s    
zSystemInfo.__init__c             C   s6   y| j ƒ d S  tk
r0   d}tjj|ƒ‚Y nX d S )Nr   z%No Microsoft Visual C++ version foundr5   )Úfind_available_vc_versÚ
IndexErrorr!   r"   r#   )r@   Úerrr   r   r   rn   è  s
    z(SystemInfo._find_latest_available_vc_verc             C   s6  | j j}| j j| j j| j jf}g }�x| j jD ]ü}xö|D ]î}ytj|||ƒdtjƒ}W n t	t
fk
rp   w8Y nX tj|ƒ\}}}	xPt|ƒD ]D}
y*ttj||
ƒd ƒ}||kr¸|j|ƒ W qŒ tk
rÎ   Y qŒX qŒW xPt|ƒD ]D}
y(ttj||
ƒƒ}||k�r|j|ƒ W qÞ tk
�r    Y qÞX qÞW q8W q.W t|ƒS )zC
        Find all available Microsoft Visual C++ versions.
        r   )rm   r^   rV   rX   rW   ra   r   r`   r_   rb   rc   ZQueryInfoKeyÚrangeÚfloatZ	EnumValueÚappendr$   ÚEnumKeyÚsorted)r@   rf   ZvckeysZvc_versrg   r   rh   ZsubkeysÚvaluesrB   Úir(   r   r   r   rp   ï  s2    


z!SystemInfo.find_available_vc_versc             C   s6   d| j  }tjj| j|ƒ}| jj| jjd| j  ƒp4|S )z4
        Microsoft Visual Studio directory.
        zMicrosoft Visual Studio %0.1fz%0.1f)ro   r   r   r   ÚProgramFilesx86rm   ri   rW   )r@   re   Údefaultr   r   r   ÚVSInstallDir  s    
zSystemInfo.VSInstallDirc             C   sŽ   | j  | jƒ p| jƒ }tjj| jjd| j ƒ}| jj	|dƒ}|rNtjj|dƒn|}| jj	| jj
d| j ƒpl|}tjj|ƒsŠd}tjj|ƒ‚|S )z1
        Microsoft Visual C++ directory.
        z%0.1fr   ZVCz(Microsoft Visual C++ directory not found)r|   Ú	_guess_vcÚ_guess_vc_legacyr   r   r   rm   rX   ro   ri   rV   Úisdirr!   r"   r#   )r@   Úguess_vcZreg_pathZ	python_vcZ
default_vcr   Úmsgr   r   r   ÚVCInstallDir  s    zSystemInfo.VCInstallDirc             C   s^   | j dkrdS d}tjj| j|ƒ}ytj|ƒd }tjj||ƒS  tttfk
rX   Y nX dS )z*
        Locate Visual C for 2017
        g      ,@NzVC\Tools\MSVCr   r5   )	ro   r   r   r   r|   Úlistdirrb   rc   rq   )r@   r{   r€   Zvc_exact_verr   r   r   r}   0  s    
zSystemInfo._guess_vcc             C   s   d| j  }tjj| j|ƒS )z<
        Locate Visual C for versions prior to 2017
        z Microsoft Visual Studio %0.1f\VC)ro   r   r   r   rz   )r@   r{   r   r   r   r~   @  s    
zSystemInfo._guess_vc_legacyc             C   sJ   | j dkrdS | j dkrdS | j dkr*dS | j dkr8dS | j dkrFdS dS )zN
        Microsoft Windows SDK versions for specified MSVC++ version.
        g      "@ú7.0ú6.1ú6.0ag      $@ú7.1ú7.0ag      &@ú8.0ú8.0ag      (@ú8.1ú8.1ag      ,@ú10.0N)r„   r…   r†   )r‡   rˆ   )r‰   rŠ   )r‹   rŒ   )r�   r‹   )ro   )r@   r   r   r   ÚWindowsSdkVersionG  s    




zSystemInfo.WindowsSdkVersionc             C   s   | j tjj| jdƒƒS )z4
        Microsoft Windows SDK last version
        Úlib)Ú_use_last_dir_namer   r   r   ÚWindowsSdkDir)r@   r   r   r   ÚWindowsSdkLastVersionW  s    
z SystemInfo.WindowsSdkLastVersionc             C   sT  d}x8| j D ].}tjj| jjd| ƒ}| jj|dƒ}|rP qW | sRtjj|ƒ rŠtjj| jjd| j	 ƒ}| jj|dƒ}|rŠtjj|dƒ}| sžtjj|ƒ rèxH| j D ]>}|d|j
dƒ… }d	| }tjj| j|ƒ}tjj|ƒr¦|}q¦W | sþtjj|ƒ �r:x:| j D ]0}d
| }tjj| j|ƒ}tjj|ƒ�r|}�qW |�sPtjj| jdƒ}|S )z2
        Microsoft Windows SDK directory.
        r   zv%sÚinstallationfolderz%0.1fr   ZWinSDKNÚ.zMicrosoft SDKs\Windows Kits\%szMicrosoft SDKs\Windows\v%sZPlatformSDK)rŽ   r   r   r   rm   rZ   ri   r   rX   ro   Úrfindrl   r‚   )r@   Úsdkdirr(   Úlocr   Úinstall_baseZintverÚdr   r   r   r‘   _  s6    
zSystemInfo.WindowsSdkDirc       	      C   sÚ   | j dkrd}d}n&d}| j dkr&dnd}| jjd|d�}d	||jd
dƒf }g }| j dkr†x(| jD ]}|tjj| jj	||ƒg7 }qdW x,| j
D ]"}|tjj| jjd| |ƒg7 }qŽW x |D ]}| jj|dƒ}|rºP qºW |S )z=
        Microsoft Windows SDK executable directory.
        g      &@é#   r   é(   g      (@TF)r=   rG   zWinSDK-NetFx%dTools%srJ   ú-g      ,@zv%sAr“   )ro   rS   rH   r?   ÚNetFxSdkVersionr   r   r   rm   r[   rŽ   rZ   ri   )	r@   Znetfxverr)   rG   ZfxZregpathsr(   r   Zexecpathr   r   r   ÚWindowsSDKExecutablePath…  s$    

"
z#SystemInfo.WindowsSDKExecutablePathc             C   s.   d| j  }tjj| jj|ƒ}| jj|dƒp,dS )z0
        Microsoft Visual F# directory.
        z%0.1f\Setup\F#r   r   )ro   r   r   r   rm   rT   ri   )r@   r   r   r   r   ÚFSharpInstallDir¤  s    
zSystemInfo.FSharpInstallDirc             C   sF   | j dkrd}nf }x(|D ] }| jj| jjd| ƒ}|rP qW |pDdS )z8
        Microsoft Universal CRT SDK directory.
        g      ,@Ú10Ú81z
kitsroot%sr   )r    r¡   )ro   rm   ri   r\   )r@   Úversr(   r–   r   r   r   ÚUniversalCRTSdkDir­  s    


zSystemInfo.UniversalCRTSdkDirc             C   s   | j tjj| jdƒƒS )z@
        Microsoft Universal C Runtime SDK last version
        r�   )r�   r   r   r   r£   )r@   r   r   r   ÚUniversalCRTSdkLastVersionÀ  s    
z%SystemInfo.UniversalCRTSdkLastVersionc             C   s   | j dkrdS f S dS )z8
        Microsoft .NET Framework SDK versions.
        g      ,@ú4.6.1ú4.6N)r¥   r¦   )ro   )r@   r   r   r   r�   È  s    
zSystemInfo.NetFxSdkVersionc             C   s>   x4| j D ]*}tjj| jj|ƒ}| jj|dƒ}|rP qW |p<dS )z9
        Microsoft .NET Framework SDK directory.
        Zkitsinstallationfolderr   )r�   r   r   r   rm   r[   ri   )r@   r(   r—   r–   r   r   r   ÚNetFxSdkDirÓ  s    zSystemInfo.NetFxSdkDirc             C   s&   t jj| jdƒ}| jj| jjdƒp$|S )z;
        Microsoft .NET Framework 32bit directory.
        zMicrosoft.NET\FrameworkZframeworkdir32)r   r   r   rk   rm   ri   rV   )r@   Úguess_fwr   r   r   ÚFrameworkDir32ß  s    zSystemInfo.FrameworkDir32c             C   s&   t jj| jdƒ}| jj| jjdƒp$|S )z;
        Microsoft .NET Framework 64bit directory.
        zMicrosoft.NET\Framework64Zframeworkdir64)r   r   r   rk   rm   ri   rV   )r@   r¨   r   r   r   ÚFrameworkDir64ê  s    zSystemInfo.FrameworkDir64c             C   s
   | j dƒS )z:
        Microsoft .NET Framework 32bit versions.
        é    )Ú_find_dot_net_versions)r@   r   r   r   ÚFrameworkVersion32õ  s    zSystemInfo.FrameworkVersion32c             C   s
   | j dƒS )z:
        Microsoft .NET Framework 64bit versions.
        é@   )r¬   )r@   r   r   r   ÚFrameworkVersion64ü  s    zSystemInfo.FrameworkVersion64c             C   s˜   | j j| j jd| ƒ}t| d| ƒ}|p6| j|dƒp6d}| jdkrL|df}n:| jdkrx|jƒ dd	… d
krndn|df}n| jdkr†d}| jdkr”d}|S )z¡
        Find Microsoft .NET Framework versions.

        Parameters
        ----------
        bits: int
            Platform number of bits: 32 or 64.
        zframeworkver%dzFrameworkDir%dÚvr   g      (@zv4.0g      $@Né   Zv4z
v4.0.30319úv3.5g      "@ú
v2.0.50727g       @úv3.0)r²   r³   )r´   r³   )rm   ri   rV   Úgetattrr�   ro   r6   )r@   ÚbitsZreg_verZdot_net_dirr(   Zframeworkverr   r   r   r¬     s    





z!SystemInfo._find_dot_net_versionsc                s,   ‡ ‡fdd„t tjˆ ƒƒD ƒ}t|dƒp*dS )zî
        Return name of the last dir in path or '' if no dir found.

        Parameters
        ----------
        path: str
            Use dirs in this path
        prefix: str
            Use only dirs startings by this prefix
        c             3   s2   | ]*}t jjt jjˆ |ƒƒr|jˆƒr|V  qd S )N)r   r   r   r   Ú
startswith)Ú.0Zdir_name)r   Úprefixr   r   ú	<genexpr>)  s   z0SystemInfo._use_last_dir_name.<locals>.<genexpr>Nr   )Úreversedr   rƒ   Únext)r@   r   r¹   Zmatching_dirsr   )r   r¹   r   r�     s    zSystemInfo._use_last_dir_name)N)r   ) r   r	   r
   rN   rO   rP   rk   rl   rz   rA   rn   rp   rQ   r|   r‚   r}   r~   rŽ   r’   r‘   rž   rŸ   r£   r¤   r�   r§   r©   rª   r­   r¯   r¬   r�   r   r   r   r   rj   Ñ  s4   

&	rj   c               @   sR  e Zd ZdZd=dd„Zedd„ ƒZedd	„ ƒZed
d„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zedd„ ƒZedd„ ƒZed d!„ ƒZed"d#„ ƒZed$d%„ ƒZed&d'„ ƒZed(d)„ ƒZed*d+„ ƒZed,d-„ ƒZed.d/„ ƒZed0d1„ ƒZed2d3„ ƒZed4d5„ ƒZd>d7d8„Zd9d:„ Zd?d;d<„Z dS )@r%   aY  
    Return environment variables for specified Microsoft Visual C++ version
    and platform : Lib, Include, Path and libpath.

    This function is compatible with Microsoft Visual C++ 9.0 to 14.0.

    Script created by analysing Microsoft environment configuration files like
    "vcvars[...].bat", "SetEnv.Cmd", "vcbuildtools.bat", ...

    Parameters
    ----------
    arch: str
        Target architecture.
    vc_ver: float
        Required Microsoft Visual C++ version. If not set, autodetect the last
        version.
    vc_min_ver: float
        Minimum Microsoft Visual C++ version.
    Nr   c             C   sB   t |ƒ| _t| jƒ| _t| j|ƒ| _| j|k r>d}tjj	|ƒ‚d S )Nz.No suitable Microsoft Visual C++ version found)
r<   rS   rR   rm   rj   Úsiro   r!   r"   r#   )r@   r)   ro   r.   rr   r   r   r   rA   I  s    

zEnvironmentInfo.__init__c             C   s   | j jS )z/
        Microsoft Visual C++ version.
        )r½   ro   )r@   r   r   r   ro   R  s    zEnvironmentInfo.vc_verc                sV   ddg}ˆ j dkrDˆ jjddd�}|dg7 }|dg7 }|d| g7 }‡ fd	d
„|D ƒS )z/
        Microsoft Visual Studio Tools
        zCommon7\IDEzCommon7\Toolsg      ,@T)rG   r=   z1Common7\IDE\CommonExtensions\Microsoft\TestWindowzTeam Tools\Performance ToolszTeam Tools\Performance Tools%sc                s   g | ]}t jjˆ jj|ƒ‘qS r   )r   r   r   r½   r|   )r¸   r   )r@   r   r   ú
<listcomp>f  s    z+EnvironmentInfo.VSTools.<locals>.<listcomp>)ro   rS   rH   )r@   ÚpathsÚarch_subdirr   )r@   r   ÚVSToolsY  s    


zEnvironmentInfo.VSToolsc             C   s$   t jj| jjdƒt jj| jjdƒgS )zL
        Microsoft Visual C++ & Microsoft Foundation Class Includes
        ÚIncludezATLMFC\Include)r   r   r   r½   r‚   )r@   r   r   r   Ú
VCIncludesh  s    zEnvironmentInfo.VCIncludesc                sb   ˆ j dkrˆ jjdd�}nˆ jjdd�}d| d| g}ˆ j dkrP|d| g7 }‡ fd	d
„|D ƒS )zM
        Microsoft Visual C++ & Microsoft Foundation Class Libraries
        g      .@T)r=   )rG   zLib%szATLMFC\Lib%sg      ,@zLib\store%sc                s   g | ]}t jjˆ jj|ƒ‘qS r   )r   r   r   r½   r‚   )r¸   r   )r@   r   r   r¾   ~  s    z/EnvironmentInfo.VCLibraries.<locals>.<listcomp>)ro   rS   rI   )r@   rÀ   r¿   r   )r@   r   ÚVCLibrariesp  s    

zEnvironmentInfo.VCLibrariesc             C   s"   | j dk rg S tjj| jjdƒgS )zA
        Microsoft Visual C++ store references Libraries
        g      ,@zLib\store\references)ro   r   r   r   r½   r‚   )r@   r   r   r   ÚVCStoreRefs€  s    
zEnvironmentInfo.VCStoreRefsc             C   s  | j }tjj|jdƒg}| jdkr&dnd}| jj|ƒ}|rT|tjj|jd| ƒg7 }| jdkrˆd| jjdd� }|tjj|j|ƒg7 }nŒ| jdkrþ| jj	ƒ r d	nd
}|tjj|j|| jj
dd� ƒg7 }| jj| jjkrü|tjj|j|| jjdd� ƒg7 }n|tjj|jdƒg7 }|S )z,
        Microsoft Visual C++ Tools
        Z
VCPackagesg      $@TFzBin%sg      ,@)rG   g      .@zbin\HostX86%szbin\HostX64%s)r=   ÚBin)r½   r   r   r   r‚   ro   rS   rM   rH   rF   rI   rE   rC   )r@   r½   ÚtoolsrK   rÀ   r   Zhost_dirr   r   r   ÚVCTools‰  s&    

zEnvironmentInfo.VCToolsc             C   st   | j dkr2| jjddd�}tjj| jjd| ƒgS | jjdd�}tjj| jjdƒ}| j}tjj|d||f ƒgS dS )	z1
        Microsoft Windows SDK Libraries
        g      $@T)rG   r=   zLib%s)r=   r�   z%sum%sN)	ro   rS   rI   r   r   r   r½   r‘   Ú_sdk_subdir)r@   rÀ   r�   Zlibverr   r   r   ÚOSLibraries©  s    
zEnvironmentInfo.OSLibrariesc             C   s|   t jj| jjdƒ}| jdkr.|t jj|dƒgS | jdkr@| j}nd}t jj|d| ƒt jj|d| ƒt jj|d| ƒgS d	S )
z/
        Microsoft Windows SDK Include
        Úincludeg      $@Úglg      ,@r   z%ssharedz%sumz%swinrtN)r   r   r   r½   r‘   ro   rÉ   )r@   rË   Úsdkverr   r   r   Ú
OSIncludes¸  s    

zEnvironmentInfo.OSIncludesc             C   sº   t jj| jjdƒ}g }| jdkr*|| j7 }| jdkrH|t jj|dƒg7 }| jdkr¶||t jj| jjdƒt jj|ddƒt jj|d	dƒt jj|d
dƒt jj| jjddd| j dddƒg7 }|S )z7
        Microsoft Windows SDK Libraries Paths
        Z
Referencesg      "@g      &@zCommonConfiguration\Neutralg      ,@ZUnionMetadataz'Windows.Foundation.UniversalApiContractz1.0.0.0z%Windows.Foundation.FoundationContractz,Windows.Networking.Connectivity.WwanContractZExtensionSDKszMicrosoft.VCLibsz%0.1fZCommonConfigurationZneutral)r   r   r   r½   r‘   ro   rÊ   )r@   ÚrefÚlibpathr   r   r   Ú	OSLibpathË  s>    




zEnvironmentInfo.OSLibpathc             C   s   t | jƒ ƒS )z-
        Microsoft Windows SDK Tools
        )ÚlistÚ
_sdk_tools)r@   r   r   r   ÚSdkToolsø  s    zEnvironmentInfo.SdkToolsc             c   s  | j dk r0| j dkrdnd}tjj| jj|ƒV  | jjƒ sd| jjdd�}d| }tjj| jj|ƒV  | j dksx| j dkr¶| jj	ƒ rˆd	}n| jjddd
�}d| }tjj| jj|ƒV  nL| j dk�rtjj| jjdƒ}| jjdd�}| jj
}tjj|d||f ƒV  | jj�r| jjV  dS )z=
        Microsoft Windows SDK Tools paths generator
        g      .@g      &@rÆ   zBin\x86T)r=   zBin%sg      $@r   )rG   r=   zBin\NETFX 4.0 Tools%sz%s%sN)ro   r   r   r   r½   r‘   rS   rF   rH   rD   r’   rž   )r@   Úbin_dirrÀ   r   rÍ   r   r   r   rÓ   ÿ  s(    



zEnvironmentInfo._sdk_toolsc             C   s   | j j}|rd| S dS )z6
        Microsoft Windows SDK version subdir
        z%s\r   )r½   r’   )r@   Úucrtverr   r   r   rÉ     s    zEnvironmentInfo._sdk_subdirc             C   s"   | j dkrg S tjj| jjdƒgS )z-
        Microsoft Windows SDK Setup
        g      "@ZSetup)ro   r   r   r   r½   r‘   )r@   r   r   r   ÚSdkSetup%  s    
zEnvironmentInfo.SdkSetupc                s”   | j }| j‰ | jdkr0d}|jƒ  o,|jƒ  }n$|jƒ p>|jƒ }|jdkpR|jdk}g }|rt|‡ fdd„ˆ jD ƒ7 }|r�|‡ fdd„ˆ jD ƒ7 }|S )z0
        Microsoft .NET Framework Tools
        g      $@Tr>   c                s   g | ]}t jjˆ j|ƒ‘qS r   )r   r   r   r©   )r¸   r(   )r½   r   r   r¾   @  s   z+EnvironmentInfo.FxTools.<locals>.<listcomp>c                s   g | ]}t jjˆ j|ƒ‘qS r   )r   r   r   rª   )r¸   r(   )r½   r   r   r¾   C  s   )	rS   r½   ro   rD   rF   rE   rC   r­   r¯   )r@   rS   Z	include32Z	include64rÇ   r   )r½   r   ÚFxTools/  s    
zEnvironmentInfo.FxToolsc             C   s>   | j dk s| jj rg S | jjdd�}tjj| jjd| ƒgS )z8
        Microsoft .Net Framework SDK Libraries
        g      ,@T)r=   zlib\um%s)ro   r½   r§   rS   rI   r   r   r   )r@   rÀ   r   r   r   ÚNetFxSDKLibrariesG  s    z!EnvironmentInfo.NetFxSDKLibrariesc             C   s,   | j dk s| jj rg S tjj| jjdƒgS )z7
        Microsoft .Net Framework SDK Includes
        g      ,@z
include\um)ro   r½   r§   r   r   r   )r@   r   r   r   ÚNetFxSDKIncludesR  s    z EnvironmentInfo.NetFxSDKIncludesc             C   s   t jj| jjdƒgS )z>
        Microsoft Visual Studio Team System Database
        zVSTSDB\Deploy)r   r   r   r½   r|   )r@   r   r   r   ÚVsTDb\  s    zEnvironmentInfo.VsTDbc             C   s~   | j dk rg S | j dk r0| jj}| jjdd�}n| jj}d}d| j |f }tjj||ƒg}| j dkrz|tjj||dƒg7 }|S )z(
        Microsoft Build Engine
        g      (@g      .@T)rG   r   zMSBuild\%0.1f\bin%sZRoslyn)	ro   r½   rz   rS   rH   r|   r   r   r   )r@   Ú	base_pathrÀ   r   Úbuildr   r   r   ÚMSBuildc  s    


zEnvironmentInfo.MSBuildc             C   s"   | j dk rg S tjj| jjdƒgS )z.
        Microsoft HTML Help Workshop
        g      &@zHTML Help Workshop)ro   r   r   r   r½   rz   )r@   r   r   r   ÚHTMLHelpWorkshopz  s    
z EnvironmentInfo.HTMLHelpWorkshopc             C   sL   | j dk rg S | jjdd�}tjj| jjdƒ}| j}tjj|d||f ƒgS )z=
        Microsoft Universal C Runtime SDK Libraries
        g      ,@T)r=   r�   z%sucrt%s)	ro   rS   rI   r   r   r   r½   r£   Ú_ucrt_subdir)r@   rÀ   r�   rÖ   r   r   r   ÚUCRTLibraries„  s    
zEnvironmentInfo.UCRTLibrariesc             C   s6   | j dk rg S tjj| jjdƒ}tjj|d| j ƒgS )z;
        Microsoft Universal C Runtime SDK Include
        g      ,@rË   z%sucrt)ro   r   r   r   r½   r£   rà   )r@   rË   r   r   r   ÚUCRTIncludes‘  s    
zEnvironmentInfo.UCRTIncludesc             C   s   | j j}|rd| S dS )zB
        Microsoft Universal C Runtime SDK version subdir
        z%s\r   )r½   r¤   )r@   rÖ   r   r   r   rà   œ  s    zEnvironmentInfo._ucrt_subdirc             C   s    | j dk r| j dkrg S | jjS )z%
        Microsoft Visual F#
        g      &@g      (@)ro   r½   rŸ   )r@   r   r   r   ÚFSharp¤  s    zEnvironmentInfo.FSharpc             C   sl   | j jdd�}| jdk r&| jj}d}n| jjjddƒ}d}| jdkrHdn| j}||| j|f }tjj||ƒS )	zA
        Microsoft Visual C++ runtime redistribuable dll
        T)r=   é   z-redist%s\Microsoft.VC%d0.CRT\vcruntime%d0.dllz\Toolsz\Redistz.onecore%s\Microsoft.VC%d0.CRT\vcruntime%d0.dllg      ,@)	rS   rI   ro   r½   r‚   r?   r   r   r   )r@   rÀ   Zredist_pathZ	vcruntimeZdll_verr   r   r   ÚVCRuntimeRedist®  s    
zEnvironmentInfo.VCRuntimeRedistTc             C   s¶   t | jd| j| j| j| jg|ƒ| jd| j| j| j| j	| j
g|ƒ| jd| j| j| j| jg|ƒ| jd| j| j| j| j| j| j| j| j| jg	|ƒd�}| jdkr²tjj| jƒr²| j|d< |S )z—
        Return environment dict.

        Parameters
        ----------
        exists: bool
            It True, only return existing paths.
        rË   r�   rÐ   r   )rË   r�   rÐ   r   é   Zpy_vcruntime_redist)ÚdictÚ_build_pathsrÃ   rÎ   râ   rÚ   rÄ   rÊ   rØ   rá   rÙ   rÅ   rÑ   rÈ   rÁ   rÛ   rÔ   r×   rÞ   rß   rã   ro   r   r   r   rå   )r@   ÚexistsÚenvr   r   r   r&   Á  sD    	

zEnvironmentInfo.return_envc       
      C   sx   t jj|ƒ}tj|dƒjtjƒ}t j||ƒ}|rBtt	tj
j|ƒƒn|}|sbd|jƒ  }tjj|ƒ‚| j|ƒ}	tjj|	ƒS )a  
        Given an environment variable name and specified paths,
        return a pathsep-separated string of paths containing
        unique, extant, directories from those paths and from
        the environment variable. Raise an error if no paths
        are resolved.
        r   z %s environment variable is empty)Ú	itertoolsÚchainÚfrom_iterablerO   rP   Úsplitr   ÚpathseprÒ   Úfilterr   r   Úupperr!   r"   r#   Ú_unique_everseenr   )
r@   re   Zspec_path_listsré   Z
spec_pathsZ	env_pathsr¿   Zextant_pathsr�   Zunique_pathsr   r   r   rè   î  s    	
zEnvironmentInfo._build_pathsc             c   sj   t ƒ }|j}|dkr:xPt|j|ƒD ]}||ƒ |V  q"W n,x*|D ]"}||ƒ}||kr@||ƒ |V  q@W dS )z×
        List unique elements, preserving order.
        Remember all elements ever seen.

        _unique_everseen('AAAABBBCCDAABBB') --> A B C D

        _unique_everseen('ABBCcAD', str.lower) --> A B C D
        N)ÚsetÚaddr   Ú__contains__)r@   Úiterabler   ÚseenZseen_addÚelementÚkr   r   r   rò     s    	
z EnvironmentInfo._unique_everseen)Nr   )T)N)!r   r	   r
   rN   rA   rQ   ro   rÁ   rÃ   rÄ   rÅ   rÈ   rÊ   rÎ   rÑ   rÔ   rÓ   rÉ   r×   rØ   rÙ   rÚ   rÛ   rÞ   rß   rá   râ   rà   rã   rå   r&   rè   rò   r   r   r   r   r%   1  s:   
		 -




-r%   )r   )r   )!rN   r   r0   Úplatformrë   Zdistutils.errorsr!   Z#setuptools.extern.packaging.versionr   Zsetuptools.extern.six.movesr   Zmonkeyr   Úsystemr   ÚenvironrO   rç   ÚImportErrorr"   r#   Z_msvc9_suppress_errorsZdistutils.msvc9compilerr   r   r    r/   r3   r'   r<   rR   rj   r%   r   r   r   r   Ú<module>   s>   
+
/&
%[   b