B
    Uvg                 @   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 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   7/tmp/pip-install-r_9ig3yj/setuptools/setuptools/msvc.pyr   (   s   r   )Regc             C   s   d}|d| f }yt |d}W nJ tk
rj   y|d| f }t |d}W n tk
rd   d}Y nX Y nX |rtjjj|d}t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||  S  tjjk
r } zt|| |  W dd}~X Y 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 S  tjjk
rh } zt|d  W dd}~X Y 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| ks"d| krd}|jf t }d}|dkrr| 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ia64z* 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      ,@z^ Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/N)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dd 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   |  dd| _d S )Nx64amd64)r6   replacer)   )selfr)   r   r   r   __init__   s    zPlatformInfo.__init__c             C   s   | 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 |  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_dir4  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   Y  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dS )z;
        Microsoft Visual Studio SxS registry key.
        ZSxS)r   r   r   rT   )r@   r   r   r   sxsc  s    zRegistryInfo.sxsc             C   s   t j| jdS )z8
        Microsoft Visual C++ VC7 registry key.
        ZVC7)r   r   r   rU   )r@   r   r   r   vcj  s    zRegistryInfo.vcc             C   s   t j| jdS )z;
        Microsoft Visual Studio VS7 registry key.
        ZVS7)r   r   r   rU   )r@   r   r   r   vsq  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_pythonx  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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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  s|rdnd}t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 sy||||dd|}W q ttfk
r   wY qX nwY nX yt 	||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   K  s"   
rR   c               @   s$  e Zd ZdZeddZeddZe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|  | _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|   d S  tk
r0   d}tj|Y nX d S )Nr5   z%No Microsoft Visual C++ version found)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|||dtj}W n t	t
fk
rp   w8Y nX t|\}}}	xPt|D ]D}
y*tt||
d }||kr|| W q tk
r   Y qX qW xPt|D ]D}
y(tt||
}||kr|| W q tk
r    Y qX qW 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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  |  p|  }tj| jjd| j }| j	|d}|rNtj|dn|}| j	| jj
d| j pl|}tj|sd}t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|}yt|d }tj||S  tttfk
rX   Y nX dS )z*
        Locate Visual C for 2017
        g      ,@NzVC\Tools\MSVCr5   )	ro   r   r   r   r|   listdirrb   rc   rq   )r@   r{   r   Zvc_exact_verr   r   r   r}   /  s    
zSystemInfo._guess_vcc             C   s   d| j  }t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      "@)z7.0z6.1z6.0ag      $@)z7.1z7.0ag      &@)z8.0z8.0ag      (@)z8.1z8.1ag      ,@)z10.0z8.1N)ro   )r@   r   r   r   WindowsSdkVersionF  s    




zSystemInfo.WindowsSdkVersionc             C   s   |  tj| jdS )z4
        Microsoft Windows SDK last version
        lib)_use_last_dir_namer   r   r   WindowsSdkDir)r@   r   r   r   WindowsSdkLastVersionV  s    
z SystemInfo.WindowsSdkLastVersionc             C   sD  d}x8| j D ].}tj| jjd| }| j|d}|rP qW |rNtj|stj| jjd| j	 }| j|d}|rtj|d}|rtj|sxH| j D ]>}|d|
d }d	| }tj| j|}tj|r|}qW |rtj|s*x6| j D ],}d
| }tj| j|}tj|r|}qW |s@t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	||d
df }g }| j dkrx(| jD ]}|tj| jj	||g7 }qdW x,| j
D ]"}|tj| jjd| |g7 }qW x |D ]}| j|d}|rP qW |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|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d}x(|D ] }| j| jjd| }|rP qW |pDdS )z8
        Microsoft Universal CRT SDK directory.
        g      ,@)10Z81r   z
kitsroot%sr   )ro   rm   ri   r\   )r@   versr(   r   r   r   r   UniversalCRTSdkDir  s    


zSystemInfo.UniversalCRTSdkDirc             C   s   |  t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 dS dS )z8
        Microsoft .NET Framework SDK versions.
        g      ,@)z4.6.1z4.6r   N)ro   )r@   r   r   r   r     s    
zSystemInfo.NetFxSdkVersionc             C   s>   x4| j D ]*}t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d}| 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d}| 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
   |  dS )z:
        Microsoft .NET Framework 32bit versions.
            )_find_dot_net_versions)r@   r   r   r   FrameworkVersion32  s    zSystemInfo.FrameworkVersion32c             C   s
   |  dS )z:
        Microsoft .NET Framework 64bit versions.
        @   )r   )r@   r   r   r   FrameworkVersion64  s    zSystemInfo.FrameworkVersion64c             C   s   | j | j jd| }t| d| }|p6| |dp6d}| jdkrL|df}n:| jdkrx| dd	 d
krndn|df}n| jdkrd}| jdkrd}|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.30319zv3.5g      "@)zv3.5z
v2.0.50727g       @)zv3.0z
v2.0.50727)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 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t j |r|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	|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   H  s    

zEnvironmentInfo.__init__c             C   s   | j jS )z/
        Microsoft Visual C++ version.
        )r   ro   )r@   r   r   r   ro   Q  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|qS r   )r   r   r   r   r|   )r   r   )r@   r   r   
<listcomp>e  s    z+EnvironmentInfo.VSTools.<locals>.<listcomp>)ro   rS   rH   )r@   pathsarch_subdirr   )r@   r   VSToolsX  s    


zEnvironmentInfo.VSToolsc             C   s$   t j| jjdt 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   
VCIncludesg  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|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   VCLibrarieso  s    

zEnvironmentInfo.VCLibrariesc             C   s"   | j dk rg S t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dg}| jdkr&dnd}| j|}|rT|tj|jd| g7 }| jdkrd| jjdd }|tj|j|g7 }n| jdkr| j	 rd	nd
}|tj|j|| jj
dd g7 }| jj| jjkr|tj|j|| jjdd g7 }n|t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d| gS | jjdd}tj| jjd}| j}t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d}| jdkr.|t j|dgS | jdkr@| j}nd}t j|d| t j|d| t 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d}g }| jdkr*|| j7 }| jdkrH|t j|dg7 }| jdkr||t j| jjdt j|ddt j|d	dt j|d
dt 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 |  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|V  | j sd| jjdd}d| }tj| jj|V  | j dksx| j dkr| j	 rd	}n| jjddd
}d| }tj| jj|V  nL| j dkrtj| jjd}| jjdd}| jj
}t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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}|  o,|  }n$| p>| }|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|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|qS r   )r   r   r   r   )r   r(   )r   r   r   r   B  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sg S | jjdd}t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   NetFxSDKLibrariesF  s    z!EnvironmentInfo.NetFxSDKLibrariesc             C   s*   | j dk s| jjsg S t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   NetFxSDKIncludesQ  s    z EnvironmentInfo.NetFxSDKIncludesc             C   s   t 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||g}| j dkrz|t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   MSBuildb  s    


zEnvironmentInfo.MSBuildc             C   s"   | j dk rg S t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   HTMLHelpWorkshopy  s    
z EnvironmentInfo.HTMLHelpWorkshopc             C   sL   | j dk rg S | jjdd}tj| jjd}| j}t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d}t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dd}d}| jdkrHdn| j}||| j|f }t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 | d| j| j| j| jg|| d| j| j| j| j	| j
g|| d| j| j| j| jg|| d| j| j| j| j| j| j| j| j| jg	|d}| jdkrt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|}t|dtj}t ||}|rBtt	tj
j|n|}|sbd|  }tj|| |}	t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%   0  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