3
LY                 @   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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 7.0 (x86, x64, ia64);
    Microsoft Windows SDK 6.1 (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)
    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   i/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/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 |rt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   4   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 standalones
    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 7.0 (x86, x64, ia64);
        Microsoft Windows SDK 6.1 (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    _   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 standalones
    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)

    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rd}|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 )ul  
        Target 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
            '\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_dir(  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   M  s    zRegistryInfo.__init__c             C   s   dS )z<
        Microsoft Visual Studio root registry key.
        ZVisualStudior   )r@   r   r   r   visualstudioP  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   sxsW  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   vc^  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   vse  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_pythonl  s    zRegistryInfo.vc_for_pythonc             C   s   dS )z-
        Microsoft SDK registry key.
        zMicrosoft SDKsr   )r@   r   r   r   microsoft_sdks  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_sdkz  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 sy||||dd|}W q ttfk
r   wY qX 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   ?  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d(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)d&d'ZdS )*
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   sX   || _ | j j| _|r|| _n8y| j d | _W n$ tk
rR   d}tjj|Y nX d S )Nr   z%No Microsoft Visual C++ version foundr5   )rirS   vc_verfind_available_vc_vers
IndexErrorr!   r"   r#   )r@   Zregistry_inforn   errr   r   r   rA     s    
zSystemInfo.__init__c             C   s"  | j j| j jf}g }x| j jD ]}x|D ]}ytj||dtj}W n ttfk
r^   w*Y nX tj	|\}}}xPt
|D ]D}	y*ttj||	d }
|
|kr|j|
 W qz tk
r   Y qzX qzW xNt
|D ]B}	y&ttj||	}
|
|kr|j|
 W q tk
r   Y qX qW q*W q W t|S )zC
        Find all available Microsoft Visual C++ versions.
        r   )rm   rV   rX   ra   r   r`   r_   rb   rc   ZQueryInfoKeyrangefloatZ	EnumValueappendr$   EnumKeysorted)r@   ZvckeysZvc_versrg   r   rh   ZsubkeysvaluesrB   ir(   r   r   r   ro     s0    

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)rn   r   r   r   ProgramFilesx86rm   ri   rW   )r@   re   defaultr   r   r   VSInstallDir  s    
zSystemInfo.VSInstallDirc             C   s   d| j  }tjj| j|}tjj| jjd| j  }| jj|d}|rRtjj|dn|}| jj| jjd| j  pp|}tjj	|sd}t
jj||S )z1
        Microsoft Visual C++ directory.
        z Microsoft Visual Studio %0.1f\VCz%0.1fr   ZVCz(Microsoft Visual C++ directory not found)rn   r   r   r   ry   rm   rX   ri   rV   isdirr!   r"   r#   )r@   rz   Zguess_vcZreg_pathZ	python_vcZ
default_vcr   msgr   r   r   VCInstallDir  s    
zSystemInfo.VCInstallDirc             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 )z1
        Microsoft Windows SDK versions.
        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   )rn   )r@   r   r   r   WindowsSdkVersion"  s    




zSystemInfo.WindowsSdkVersionc             C   sT  d}x8| j D ].}tjj| jjd| }| jj|d}|rP qW | sRtjj| rtjj| jjd| j	 }| jj|d}|rtjj|d}| stjj| rxH| j D ]>}|d|j
d }d	| }tjj| j|}tjj|r|}qW | st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   rn   rfindrl   r~   )r@   sdkdirr(   locr   install_baseZintverdr   r   r   WindowsSdkDir3  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rx(| jD ]}|tjj| jj	||g7 }qdW x,| j
D ]"}|tjj| jjd| |g7 }qW x |D ]}| j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   )rn   rS   rH   r?   NetFxSdkVersionr   r   r   rm   r[   r   rZ   ri   )	r@   Znetfxverr)   rG   ZfxZregpathsr(   r   Zexecpathr   r   r   WindowsSDKExecutablePathY  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   )rn   r   r   r   rm   rT   ri   )r@   r   r   r   r   FSharpInstallDirx  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   )rn   rm   ri   r\   )r@   versr(   r   r   r   r   UniversalCRTSdkDir  s    


zSystemInfo.UniversalCRTSdkDirc             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   )rn   )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.FrameworkVersion64r   c             C   sz   | j j| j jd| pd}| jdkr.|df}n:| jdkrZ|j dd dkrPd	n|d
f}n| jdkrhd}| jdkrvd}|S )z
        Find Microsoft .NET Framework versions.

        Parameters
        ----------
        bits: int
            Platform number of bits: 32 or 64.
        zframeworkver%dr   g      (@zv4.0g      $@N   Zv4z
v4.0.30319v3.5g      "@
v2.0.50727g       @v3.0)r   r   )r   r   )rm   ri   rV   rn   r6   )r@   bitsr(   Zframeworkverr   r   r   r     s    





z!SystemInfo._find_dot_net_versions)N)r   )r   r	   r
   rN   rO   rP   rk   rl   ry   rA   ro   rQ   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rj     s(   

&	rj   c               @   s:  e Zd ZdZd8d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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d9d0d1Zd2d3 Zd:d4d5Zd6d7 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.
    Nc             C   sF   t || _t| j| _t| j|| _|rB| j|k rBd}tjj	|d S )Nz.No suitable Microsoft Visual C++ version found)
r<   rS   rR   rm   rj   sirn   r!   r"   r#   )r@   r)   rn   r.   rq   r   r   r   rA      s    

zEnvironmentInfo.__init__c             C   s   | j jS )z/
        Microsoft Visual C++ version.
        )r   rn   )r@   r   r   r   rn   
  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{   ).0r   )r@   r   r   
<listcomp>  s    z+EnvironmentInfo.VSTools.<locals>.<listcomp>)rn   rS   rH   )r@   pathsarch_subdirr   )r@   r   VSTools  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   
VCIncludes   s    zEnvironmentInfo.VCIncludesc                sH    j jdd}d| d| g} jdkr6|d| g7 } fdd|D S )	zM
        Microsoft Visual C++ & Microsoft Foundation Class Libraries
        T)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   3  s    z/EnvironmentInfo.VCLibraries.<locals>.<listcomp>)rS   rI   rn   )r@   r   r   r   )r@   r   VCLibraries(  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)rn   r   r   r   r   r~   )r@   r   r   r   VCStoreRefs5  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rd| jjdd }|tjj|j|g7 }n|tjj|jdg7 }|S )	z,
        Microsoft Visual C++ Tools
        Z
VCPackagesg      $@TFzBin%sg      ,@)rG   Bin)	r   r   r   r   r~   rn   rS   rM   rH   )r@   r   toolsrK   r   r   r   r   r   VCTools>  s    
zEnvironmentInfo.VCToolsc             C   sx   | 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=   libz%sum%sN)	rn   rS   rI   r   r   r   r   r   _get_content_dirname)r@   r   r   Zlibverr   r   r   OSLibrariesT  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rD| 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   rn   r   )r@   r   Zsdkverr   r   r   
OSIncludesc  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   rn   r   )r@   reflibpathr   r   r   	OSLibpathv  s>    




zEnvironmentInfo.OSLibpathc             C   s   | j dkrdnd}tjj| jj|g}| jj s^| jjdd}d| }|tjj| jj|g7 }| j dksr| j dkr| jj	 rd}n| jjddd	}d
| }|tjj| jj|g7 }| jj
r|| jj
g7 }|S )z-
        Microsoft Windows SDK Tools
        g      &@r   zBin\x86T)r=   zBin%sg      $@r   )rG   r=   zBin\NETFX 4.0 Tools%s)rn   r   r   r   r   r   rS   rF   rH   rD   r   )r@   bin_dirr   r   r   r   r   r   SdkTools  s    

zEnvironmentInfo.SdkToolsc             C   s"   | j dkrg S tjj| jjdgS )z-
        Microsoft Windows SDK Setup
        g      "@ZSetup)rn   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     s   )	rS   r   rn   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)rn   r   r   rS   rI   r   r   r   )r@   r   r   r   r   NetFxSDKLibraries  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)rn   r   r   r   r   r   )r@   r   r   r   NetFxSDKIncludes  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jdd}d| j |f }tjj| jj|gS )z(
        Microsoft Build Engine
        g      (@T)rG   zMSBuild\%0.1f\bin%s)rn   rS   rH   r   r   r   r   ry   )r@   r   r   r   r   r   MSBuild  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)rn   r   r   r   r   ry   )r@   r   r   r   HTMLHelpWorkshop  s    
z EnvironmentInfo.HTMLHelpWorkshopc             C   sP   | j dk rg S | jjdd}tjj| jjd}| j|}tjj|d||f gS )z3
        Microsoft Universal CRT Libraries
        g      ,@T)r=   r   z%sucrt%s)	rn   rS   rI   r   r   r   r   r   r   )r@   r   r   ucrtverr   r   r   UCRTLibraries  s    

zEnvironmentInfo.UCRTLibrariesc             C   s>   | j dk rg S tjj| jjd}| j|}tjj|d| gS )z1
        Microsoft Universal CRT Include
        g      ,@r   z%sucrt)rn   r   r   r   r   r   r   )r@   r   r   r   r   r   UCRTIncludes  s
    

zEnvironmentInfo.UCRTIncludesc             C   s    | j dk r| j dkrg S | jjS )z%
        Microsoft Visual F#
        g      &@g      (@)rn   r   r   )r@   r   r   r   FSharp*  s    zEnvironmentInfo.FSharpc             C   s6   | j jdd}d}||| j| jf }tjj| jj|S )zA
        Microsoft Visual C++ runtime redistribuable dll
        T)r=   z-redist%s\Microsoft.VC%d0.CRT\vcruntime%d0.dll)rS   rI   rn   r   r   r   r   r~   )r@   r   Z	vcruntimer   r   r   VCRuntimeRedist4  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rt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   rn   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   pathseplist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   k  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_everseenc             C   s<   yt j|}|rd|d  S dS  ttfk
r6   dS X dS )z
        Return name of the first dir in path or '' if no dir found.

        Parameters
        ----------
        path: str
            Path where search dir.

        Return
        ------
        foldername: str
            "name" or ""
        z%s\r   r   N)r   listdirrb   rc   )r@   r   re   r   r   r   r     s    
z$EnvironmentInfo._get_content_dirname)NN)T)N)r   r	   r
   rN   rA   rQ   rn   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%     s6   

	-





-
r%   )r   )r   )rN   r   r0   platformr   Zdistutils.errorsr!   Z&pkg_resources.extern.packaging.versionr   Zsetuptools.extern.six.movesr   Zmonkeyr   systemr   environrO   r   Zdistutils.msvc9compilerr   ImportErrorr   r    r/   r3   r'   r<   rR   rj   r%   r   r   r   r   <module>   s:   +
/$
%[   &