U
    h                     @   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z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-2aersu7t/setuptools/setuptools/msvc.pyr   (   s   r   )Regc                 C   s   d}|d| f }zt |d}W nJ tk
rj   z|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   zt t}|| |f||W S  tjjk
r4   Y n tk
rF   Y nX zt||  W S  tjjk
r } zt|| |  W 5 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   sr   zt t| W S  tjjk
r&   Y nX zt| dd W S  tjjk
rl } zt|d  W 5 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
          ,@)
vc_min_verN)r   msvc14_get_vc_envr!   r"   r#   r%   r&   r'   )Z	plat_specr-   r   r   r   r0      s    
r0   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   r4      s
    
r4   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=%d      "@Zia64z* Get it with "Microsoft Windows SDK 7.0": iB  z% Get it from http://aka.ms/vcpython27      $@z* Get it with "Microsoft Windows SDK 7.1": iW   r.   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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)r9   replacer)   )selfr)   r   r   r   __init__   s    zPlatformInfo.__init__c                 C   s   | j | j dd d  S )N_r   )r)   r<   rC   r   r   r   
target_cpu   s    zPlatformInfo.target_cpuc                 C   s
   | j dkS Nr   rG   rF   r   r   r   target_is_x86  s    zPlatformInfo.target_is_x86c                 C   s
   | j dkS rH   current_cpurF   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   rA   \x64\%srK   rC   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   rA   rN   rO   rI   rP   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_)rL   rG   rS   rB   )rC   forcex86currentr   r   r   	cross_dir5  s    zPlatformInfo.cross_dirN)FF)FF)F)r   r	   r
   __doc__safe_envgetr9   rL   rD   propertyrG   rJ   rM   rR   rS   rW   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)rC   Zplatform_infor   r   r   rD   Z  s    zRegistryInfo.__init__c                 C   s   dS )z<
        Microsoft Visual Studio root registry key.
        ZVisualStudior   rF   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   r_   rF   r   r   r   sxsd  s    zRegistryInfo.sxsc                 C   s   t j| jdS )z8
        Microsoft Visual C++ VC7 registry key.
        ZVC7r   r   r   r`   rF   r   r   r   vck  s    zRegistryInfo.vcc                 C   s   t j| jdS )z;
        Microsoft Visual Studio VS7 registry key.
        ZVS7ra   rF   r   r   r   vsr  s    zRegistryInfo.vsc                 C   s   dS )z?
        Microsoft Visual C++ for Python registry key.
        zDevDiv\VCForPythonr   rF   r   r   r   vc_for_pythony  s    zRegistryInfo.vc_for_pythonc                 C   s   dS )z-
        Microsoft SDK registry key.
        zMicrosoft SDKsr   rF   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   re   rF   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NETFXSDKrf   rF   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   rF   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)r^   rM   r   r   r   )rC   r   r   Znode64r   r   r   	microsoft  s    zRegistryInfo.microsoftc                 C   s   t j}t j}| j}| jD ]}z||||d|}W n` ttfk
r   | j sz||||dd|}W q ttfk
r   Y Y qY qX nY qY nX zt 	||d W   S  ttfk
r   Y qX q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OpenKeyrk   HKEYSOSErrorIOErrorr^   rM   QueryValueEx)rC   r   namerl   Zopenkeymshkeybkeyr   r   r   lookup  s"    


zRegistryInfo.lookupN)F)r   r	   r
   rX   r   r   r   r   r   rn   rD   r[   r_   r`   rb   rc   rd   re   rg   rh   ri   rk   rv   r   r   r   r   r\   L  s6   









r\   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 r]   )rir^   _find_latest_available_vc_vervc_ver)rC   Zregistry_infor|   r   r   r   rD     s    
zSystemInfo.__init__c                 C   s8   z|   d W S  tk
r2   d}tj|Y nX d S )Nr7   z%No Microsoft Visual C++ version found)find_available_vc_vers
IndexErrorr!   r"   r#   )rC   errr   r   r   r{     s
    z(SystemInfo._find_latest_available_vc_verc                 C   s$  | j j}| j j| j j| j jf}g }| j jD ]}|D ]}zt|||dtj}W n t	t
fk
rl   Y q2Y nX t|\}}}	t|D ]D}
z*tt||
d }||kr|| W q tk
r   Y qX qt|D ]B}
z&tt||
}||kr|| W q tk
r   Y qX qq2q*t|S )zC
        Find all available Microsoft Visual C++ versions.
        r   )rz   rk   rb   rd   rc   rn   r   rm   rl   ro   rp   ZQueryInfoKeyrangefloatZ	EnumValueappendr$   EnumKeysorted)rC   rs   ZvckeysZvc_versrt   r   ru   ZsubkeysvaluesrE   ir(   r   r   r   r}     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.1f%0.1f)r|   r   r   r   ProgramFilesx86rz   rv   rc   )rC   rr   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.
        r   r   ZVCz(Microsoft Visual C++ directory not found)r   	_guess_vc_guess_vc_legacyr   r   r   rz   rd   r|   rv   rb   isdirr!   r"   r#   )rC   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|}zt|d }tj||W S  tttfk
rZ   Y nX dS )z*
        Locate Visual C for 2017
        r.   NzVC\Tools\MSVCr7   )	r|   r   r   r   r   listdirro   rp   r~   )rC   r   r   Zvc_exact_verr   r   r   r   0  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)r|   r   r   r   r   )rC   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.
        r6   )z7.0z6.1z6.0ar8   )z7.1z7.0a      &@)z8.0z8.0a      (@)8.1z8.1ar.   )z10.0r   Nr|   rF   r   r   r   WindowsSdkVersionG  s    




zSystemInfo.WindowsSdkVersionc                 C   s   |  tj| jdS )z4
        Microsoft Windows SDK last version
        lib)_use_last_dir_namer   r   r   WindowsSdkDirrF   r   r   r   WindowsSdkLastVersionW  s    
 z SystemInfo.WindowsSdkLastVersionc                 C   s:  d}| j D ]0}tj| jjd| }| j|d}|r
 q<q
|rLtj|stj| jjd| j	 }| j|d}|rtj|d}|rtj|s| j D ]>}|d|
d }d	| }tj| j|}tj|r|}q|rtj|s | j D ],}d
| }tj| j|}tj|r|}q|s6tj| jd}|S )z2
        Microsoft Windows SDK directory.
        r   zv%sinstallationfolderr   r   ZWinSDKN.zMicrosoft SDKs\Windows Kits\%szMicrosoft SDKs\Windows\v%sZPlatformSDK)r   r   r   r   rz   rg   rv   r   rd   r|   rfindry   r   )rC   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r| jD ]}|tj| jj	||g7 }qb| j
D ]"}|tj| jjd| |g7 }q|D ]}| j|d}|r qq|S )z=
        Microsoft Windows SDK executable directory.
        r   #   r   (   r   TF)r@   rQ   zWinSDK-NetFx%dTools%srT   -r.   zv%sAr   )r|   r^   rR   rB   NetFxSdkVersionr   r   r   rz   rh   r   rg   rv   )	rC   Znetfxverr)   rQ   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   )r|   r   r   r   rz   r_   rv   )rC   r   r   r   r   FSharpInstallDir  s    
zSystemInfo.FSharpInstallDirc                 C   sD   | j dkrd}nd}|D ]"}| j| jjd| }|r q<q|pBdS )z8
        Microsoft Universal CRT SDK directory.
        r.   )10Z81r   z
kitsroot%sr   )r|   rz   rv   ri   )rC   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   rF   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.
        r.   )z4.6.1z4.6r   Nr   rF   r   r   r   r     s    
zSystemInfo.NetFxSdkVersionc                 C   s<   | j D ],}tj| jj|}| j|d}|r q4q|p:dS )z9
        Microsoft .NET Framework SDK directory.
        Zkitsinstallationfolderr   )r   r   r   r   rz   rh   rv   )rC   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   rx   rz   rv   rb   rC   Z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frameworkdir64r   r   r   r   r   FrameworkDir64  s    zSystemInfo.FrameworkDir64c                 C   s
   |  dS )z:
        Microsoft .NET Framework 32bit versions.
            _find_dot_net_versionsrF   r   r   r   FrameworkVersion32  s    zSystemInfo.FrameworkVersion32c                 C   s
   |  dS )z:
        Microsoft .NET Framework 64bit versions.
        @   r   rF   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   r   zv4.0r8   N   Zv4z
v4.0.30319v3.5r6   )r   
v2.0.50727g       @)zv3.0r   )rz   rv   rb   getattrr   r|   r9   )rC   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 r]   )r   r   r   r   
startswith).0Zdir_namer   prefixr   r   	<genexpr>(  s   
z0SystemInfo._use_last_dir_name.<locals>.<genexpr>Nr   )reversedr   r   next)rC   r   r   Zmatching_dirsr   r   r   r     s    zSystemInfo._use_last_dir_name)N)r   ) r   r	   r
   rX   rY   rZ   rx   ry   r   rD   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   rw     sR   





%












rw   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?   r^   r\   rz   rw   sir|   r!   r"   r#   )rC   r)   r|   r/   r   r   r   r   rD   I  s    

zEnvironmentInfo.__init__c                 C   s   | j jS )z/
        Microsoft Visual C++ version.
        )r   r|   rF   r   r   r   r|   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\Toolsr.   TrQ   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   rF   r   r   
<listcomp>f  s     z+EnvironmentInfo.VSTools.<locals>.<listcomp>)r|   r^   rR   )rC   pathsarch_subdirr   rF   r   VSToolsY  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   rF   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
              .@Tr@   rQ   Lib%szATLMFC\Lib%sr.   zLib\store%sc                    s   g | ]}t j jj|qS r   r   r   rF   r   r   r   ~  s     z/EnvironmentInfo.VCLibraries.<locals>.<listcomp>)r|   r^   rS   )rC   r   r   r   rF   r   VCLibrariesp  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
        r.   zLib\store\references)r|   r   r   r   r   r   rF   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
VCPackagesr8   TFBin%sr.   r   r   zbin\HostX86%szbin\HostX64%sr   Bin)r   r   r   r   r   r|   r^   rW   rR   rM   rS   rL   rG   )rC   r   toolsrU   r   r   Zhost_dirr   r   r   VCTools  s0    

  
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
        r8   Tr   r   r   r   z%sum%sN)	r|   r^   rS   r   r   r   r   r   _sdk_subdir)rC   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
        includer8   glr.   r   z%ssharedz%sumz%swinrtN)r   r   r   r   r   r|   r   )rC   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
Referencesr6   r   zCommonConfiguration\Neutralr.   ZUnionMetadataz'Windows.Foundation.UniversalApiContractz1.0.0.0z%Windows.Foundation.FoundationContractz,Windows.Networking.Connectivity.WwanContractZExtensionSDKszMicrosoft.VCLibsr   ZCommonConfigurationZneutral)r   r   r   r   r   r|   r   )rC   reflibpathr   r   r   	OSLibpath  sH    



zEnvironmentInfo.OSLibpathc                 C   s   t |  S )z-
        Microsoft Windows SDK Tools
        )list
_sdk_toolsrF   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
        r   r   r   zBin\x86Tr   r   r8   r   r   zBin\NETFX 4.0 Tools%sz%s%sN)r|   r   r   r   r   r   r^   rM   rR   rJ   r   r   )rC   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
        %s\r   )r   r   rC   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
        r6   Setup)r|   r   r   r   r   r   rF   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
        r8   TrA   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   C  s   )	r^   r   r|   rJ   rM   rL   rG   r   r   )rC   r^   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
        r.   Tr   zlib\um%s)r|   r   r   r^   rS   r   r   r   )rC   r   r   r   r   NetFxSDKLibrariesG  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
        r.   z
include\um)r|   r   r   r   r   r   rF   r   r   r   NetFxSDKIncludesR  s    z EnvironmentInfo.NetFxSDKIncludesc                 C   s   t j| jjdgS )z>
        Microsoft Visual Studio Team System Database
        zVSTSDB\Deployr   rF   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
        r   r   Tr   r   zMSBuild\%0.1f\bin%sZRoslyn)	r|   r   r   r^   rR   r   r   r   r   )rC   	base_pathr   r   buildr   r   r   MSBuildc  s    


zEnvironmentInfo.MSBuildc                 C   s"   | j dk rg S tj| jjdgS )z.
        Microsoft HTML Help Workshop
        r   zHTML Help Workshop)r|   r   r   r   r   r   rF   r   r   r   HTMLHelpWorkshopz  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
        r.   Tr   r   z%sucrt%s)	r|   r^   rS   r   r   r   r   r   _ucrt_subdir)rC   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
        r.   r   z%sucrt)r|   r   r   r   r   r   r   )rC   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
        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#
        r   r   )r|   r   r   rF   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
        Tr      z-redist%s\Microsoft.VC%d0.CRT\vcruntime%d0.dllz\Toolsz\Redistz.onecore%s\Microsoft.VC%d0.CRT\vcruntime%d0.dllr.   )	r^   rS   r|   r   r   rB   r   r   r   )rC   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   r|   r   r   r   r   )rC   existsenvr   r   r   r&     sV    		 
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_iterablerY   rZ   splitr   pathsepr   filterr   r   upperr!   r"   r#   _unique_everseenr   )
rC   rr   Zspec_path_listsr   Z
spec_pathsZ	env_pathsr   Zextant_pathsr   Zunique_pathsr   r   r   r     s    	
zEnvironmentInfo._build_pathsc                 c   sb   t  }|j}|dkr6t|j|D ]}|| |V  q n(|D ]"}||}||kr:|| |V  q: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__)rC   iterabler   seenseen_addelementkr   r   r   r    s    	
z EnvironmentInfo._unique_everseen)Nr   )T)N)!r   r	   r
   rX   rD   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   r   r%   1  sh   
	








,


	



	


	




	

-r%   )r   )r   )!rX   r   r1   platformr   Zdistutils.errorsr!   Z#setuptools.extern.packaging.versionr   Zsetuptools.extern.six.movesr   Zmonkeyr   systemr   environrY   r   ImportErrorr"   r#   Z_msvc9_suppress_errorsZdistutils.msvc9compilerr   r   r    r0   r4   r'   r?   r\   rw   r%   r   r   r   r   <module>   s@   	+
/&
%[   b