U
    ui                     @  s   U d Z ddlmZ ddl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Ze
se dkrddlZddlmZ nG dd	 d	Ze Zd
ed< G dd dZG dd dZG dd dZG dd dZdS )zo
Environment info about Microsoft Compilers.

>>> getfixture('windows_only')
>>> ei = EnvironmentInfo('amd64')
    )annotationsN)TYPE_CHECKING)unique_everseenWindows)environc                   @  s   e Zd ZdZdZdZdZdS )winregN)__name__
__module____qualname__
HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEHKEY_CLASSES_ROOT r   r   3/tmp/pip-unpacked-wheel-9osl9suo/setuptools/msvc.pyr      s   r   zdict[str, str]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 information.

    Parameters
    ----------
    arch: str
        Target architecture.
    Zprocessor_architecture c                 C  s   |  dd| _d S )Nx64amd64)lowerreplacearch)selfr   r   r   r   __init__2   s    zPlatformInfo.__init__c                 C  s   | j | j dd d S )zs
        Return Target CPU architecture.

        Return
        ------
        str
            Target CPU
        _   N)r   findr   r   r   r   
target_cpu5   s    
zPlatformInfo.target_cpuc                 C  s
   | j dkS )z
        Return True if target CPU is x86 32 bits..

        Return
        ------
        bool
            CPU is x86 32 bits
        x86r   r   r   r   r   target_is_x86A   s    	zPlatformInfo.target_is_x86c                 C  s
   | j dkS )z
        Return True if current CPU is x86 32 bits..

        Return
        ------
        bool
            CPU is x86 32 bits
        r   current_cpur   r   r   r   current_is_x86L   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
        ------
        str
            subfolder: '	arget', or '' (see hidex86 parameter)
        r   r   r   \x64\%sr"   r   hidex86r   r   r   r   current_dirW   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
        ------
        str
            subfolder: '\current', or '' (see hidex86 parameter)
        r   r   r   r%   r&   r    r'   r   r   r   
target_diro   s    zPlatformInfo.target_dirc                 C  s0   |rdn| j }| j|krdS |  dd| S )ap  
        Cross platform specific subfolder.

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

        Return
        ------
        str
            subfolder: '' if target architecture is current architecture,
            '\current_target' if not.
        r   r   \z\%s_)r#   r   r*   r   )r   forcex86currentr   r   r   	cross_dir   s
    zPlatformInfo.cross_dirN)FF)FF)F)r   r	   r
   __doc__r   getr   r#   r   propertyr   r!   r$   r)   r*   r.   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 information.

    Parameters
    ----------
    platform_info: PlatformInfo
        "PlatformInfo" instance.
    c                 C  s
   || _ d S N)pi)r   Zplatform_infor   r   r   r      s    zRegistryInfo.__init__c                 C  s   dS )z
        Microsoft Visual Studio root registry key.

        Return
        ------
        str
            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.

        Return
        ------
        str
            Registry key
        ZSxS)ospathjoinr5   r   r   r   r   sxs   s    
zRegistryInfo.sxsc                 C  s   t j| jdS )z|
        Microsoft Visual C++ VC7 registry key.

        Return
        ------
        str
            Registry key
        ZVC7r6   r7   r8   r9   r   r   r   r   vc   s    
zRegistryInfo.vcc                 C  s   t j| jdS )z
        Microsoft Visual Studio VS7 registry key.

        Return
        ------
        str
            Registry key
        ZVS7r:   r   r   r   r   vs   s    
zRegistryInfo.vsc                 C  s   dS )z
        Microsoft Visual C++ for Python registry key.

        Return
        ------
        str
            Registry key
        zDevDiv\VCForPythonr   r   r   r   r   vc_for_python   s    
zRegistryInfo.vc_for_pythonc                 C  s   dS )zq
        Microsoft SDK registry key.

        Return
        ------
        str
            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.

        Return
        ------
        str
            Registry key
        r   r6   r7   r8   r>   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.

        Return
        ------
        str
            Registry key
        ZNETFXSDKr?   r   r   r   r   	netfx_sdk  s    
zRegistryInfo.netfx_sdkc                 C  s   dS )z
        Microsoft Windows Kits Roots registry key.

        Return
        ------
        str
            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
            Registry key
        r   ZWow6432NodeZSoftware	Microsoft)r4   r$   r6   r7   r8   )r   keyr   Znode64r   r   r   	microsoft  s    zRegistryInfo.microsoftc           	      C  s   t j}t j}t j}| j}| jD ]}d}z||||d|}W nX tk
r   | j sz||||dd|}W q tk
r   Y Y qY qX nY qY nX z4zt 	||d W W   S  tk
r   Y nX W 5 |r|| 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
        Nr   T)
r   KEY_READOpenKeyZCloseKeyrE   HKEYSOSErrorr4   r$   QueryValueEx)	r   rD   nameZkey_readZopenkeyZclosekeymshkeybkeyr   r   r   lookup2  s,    



zRegistryInfo.lookupN)F)r   r	   r
   r/   r   r   r   r   r   rH   r   r1   r5   r9   r;   r<   r=   r>   r@   rA   rB   rE   rO   r   r   r   r   r2      s6   










r2   c                   @  s<  e Zd ZdZeddZeddZedeZd7ddZ	d	d
 Z
dd Zdd Ze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/d0 Zed1d2 Z d3d4 Z!ed8d5d6Z"dS )9
SystemInfoz
    Microsoft Windows and Visual Studio related system information.

    Parameters
    ----------
    registry_info: RegistryInfo
        "RegistryInfo" instance.
    vc_ver: float
        Required Microsoft Visual C++ version.
    WinDirr   ProgramFileszProgramFiles(x86)Nc                 C  s2   || _ | j j| _|  | _|p$|   | _| _d S r3   )rir4   find_programdata_vs_versknown_vs_paths_find_latest_available_vs_vervs_vervc_ver)r   Zregistry_inforX   r   r   r   r   n  s    

zSystemInfo.__init__c                 C  s>   |   }|s| jstjdt|}|| j t|d S )zm
        Find the latest VC version

        Return
        ------
        float
            version
        z%No Microsoft Visual C++ version found)find_reg_vs_versrU   	distutilserrorsDistutilsPlatformErrorsetupdatesorted)r   Zreg_vc_versZvc_versr   r   r   rV   w  s    	
z(SystemInfo._find_latest_available_vs_verc                 C  s*  | j j}| j j| j j| j jf}g }t| j j|D ]\}}zt	|||dtj
}W n tk
rl   Y q2Y nX | t|\}}}	t|D ]@}
tt, tt||
d }||kr|| W 5 Q R X qt|D ]>}
tt* tt||
}||kr
|| W 5 Q R X qW 5 Q R X q2t|S )z
        Find Microsoft Visual Studio versions available in registry.

        Return
        ------
        list of float
            Versions
        r   )rS   rE   r;   r=   r<   	itertoolsproductrH   r   rG   rF   rI   ZQueryInfoKeyrange
contextlibsuppress
ValueErrorfloatZ	EnumValueappendEnumKeyr`   )r   rL   ZvckeysZvs_versrM   rD   rN   Zsubkeysvaluesr   iverr   r   r   rZ     s*    	

"zSystemInfo.find_reg_vs_versc           	   
   C  s   i }d}zt |}W n tk
r.   | Y S X |D ]}zft j||d}t|ddd}t|}W 5 Q R X |d }t t j|d ||| |d < W q4 tt	fk
r   Y q4Y q4X q4|S )	z
        Find Visual studio 2017+ versions from information in
        "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances".

        Return
        ------
        dict
            float version as key, path as value.
        z9C:\ProgramData\Microsoft\VisualStudio\Packages\_Instancesz
state.jsonrtzutf-8)encodingZinstallationPathVC\Tools\MSVCZinstallationVersion)
r6   listdirrI   r7   r8   openjsonload_as_float_versionKeyError)	r   Zvs_versionsZinstances_dirZhashed_namesrK   Z
state_pathZ
state_filestateZvs_pathr   r   r   rT     s$    

z#SystemInfo.find_programdata_vs_versc                 C  s   t d| ddd S )z
        Return a string version as a simplified float version (major.minor)

        Parameters
        ----------
        version: str
            Version.

        Return
        ------
        float
            version
        .N   )rg   r8   split)versionr   r   r   rt     s    zSystemInfo._as_float_versionc                 C  s2   t j| jd| j }| j| jjd| j p0|S )zp
        Microsoft Visual Studio directory.

        Return
        ------
        str
            path
        zMicrosoft Visual Studio %0.1f%0.1f)r6   r7   r8   ProgramFilesx86rW   rS   rO   r<   )r   defaultr   r   r   VSInstallDir  s
     zSystemInfo.VSInstallDirc                 C  s0   |   p|  }tj|s,d}tj||S )zm
        Microsoft Visual C++ directory.

        Return
        ------
        str
            path
        z(Microsoft Visual C++ directory not found)	_guess_vc_guess_vc_legacyr6   r7   isdirr[   r\   r]   )r   r7   msgr   r   r   VCInstallDir  s
    
zSystemInfo.VCInstallDirc              	   C  s   | j dkrdS z| j| j  }W n tk
r8   | j}Y nX tj|d}z*t|d }| || _	tj||W S  t
tfk
r   Y dS X dS )zl
        Locate Visual C++ for VS2017+.

        Return
        ------
        str
            path
              ,@r   ro   rY   N)rW   rU   ru   r~   r6   r7   r8   rp   rt   rX   rI   
IndexError)r   Zvs_dirZguess_vcrX   r   r   r   r   	  s    	
zSystemInfo._guess_vcc                 C  sn   t j| jd| j }t j| jjd| j }| j|d}|rNt j|dn|}| j| jjd| j pl|S )z{
        Locate Visual C++ for versions prior to 2017.

        Return
        ------
        str
            path
        z Microsoft Visual Studio %0.1f\VCr{   
installdirZVC)	r6   r7   r8   r|   rW   rS   r=   rO   r;   )r   r}   Zreg_pathZ	python_vcZ
default_vcr   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 )z
        Microsoft Windows SDK versions for specified MSVC++ version.

        Return
        ------
        tuple of str
            versions
              "@)z7.0z6.1z6.0a      $@)z7.1z7.0a      &@)z8.0z8.0a      (@)8.1z8.1ar   )z10.0r   NrW   r   r   r   r   WindowsSdkVersion<  s    





zSystemInfo.WindowsSdkVersionc                 C  s   |  tj| jdS )zt
        Microsoft Windows SDK last version.

        Return
        ------
        str
            version
        lib)_use_last_dir_namer6   r7   r8   WindowsSdkDirr   r   r   r   WindowsSdkLastVersionR  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 )zn
        Microsoft Windows SDK directory.

        Return
        ------
        str
            path
        r   zv%sinstallationfolderr{   r   ZWinSDKNrw   zMicrosoft SDKs\Windows Kits\%szMicrosoft SDKs\Windows\v%sZPlatformSDK)r   r6   r7   r8   rS   r@   rO   r   r=   rX   rfindrR   r   )r   sdkdirrl   locr7   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|  S qdS )zy
        Microsoft Windows SDK executable directory.

        Return
        ------
        str
            path
        r   #   r   (   r   TF)r   r(   zWinSDK-NetFx%dTools%sr+   -r   zv%sAr   N)rW   r4   r)   r   NetFxSdkVersionr6   r7   r8   rS   rA   r   r@   rO   )	r   Znetfxverr   r(   ZfxZregpathsrl   r7   Zexecpathr   r   r   WindowsSDKExecutablePath  s$    



 
z#SystemInfo.WindowsSDKExecutablePathc                 C  s*   t j| jjd| j }| j|dp(dS )zl
        Microsoft Visual F# directory.

        Return
        ------
        str
            path
        z%0.1f\Setup\F#Z
productdirr   )r6   r7   r8   rS   r5   rW   rO   )r   r7   r   r   r   FSharpInstallDir  s    
zSystemInfo.FSharpInstallDirc                 C  sF   | j dkrdnd}|D ]*}| j| jjd| }|r|p:d  S qdS )zt
        Microsoft Universal CRT SDK directory.

        Return
        ------
        str
            path
        r   )10Z81r   z
kitsroot%sr   N)rW   rS   rO   rB   )r   versrl   r   r   r   r   UniversalCRTSdkDir  s    zSystemInfo.UniversalCRTSdkDirc                 C  s   |  tj| jdS )z
        Microsoft Universal C Runtime SDK last version.

        Return
        ------
        str
            version
        r   )r   r6   r7   r8   r   r   r   r   r   UniversalCRTSdkLastVersion  s    
z%SystemInfo.UniversalCRTSdkLastVersionc                 C  s   | j dkrdS dS )z
        Microsoft .NET Framework SDK versions.

        Return
        ------
        tuple of str
            versions
        r   )	z4.7.2z4.7.1z4.7z4.6.2z4.6.1z4.6z4.5.2z4.5.1z4.5r   r   r   r   r   r   r     s    zSystemInfo.NetFxSdkVersionc                 C  s<   d}| j D ],}tj| jj|}| j|d}|r
 q8q
|S )zu
        Microsoft .NET Framework SDK directory.

        Return
        ------
        str
            path
        r   Zkitsinstallationfolder)r   r6   r7   r8   rS   rA   rO   )r   r   rl   r   r   r   r   NetFxSdkDir  s    

zSystemInfo.NetFxSdkDirc                 C  s&   t j| jd}| j| jjdp$|S )zw
        Microsoft .NET Framework 32bit directory.

        Return
        ------
        str
            path
        zMicrosoft.NET\FrameworkZframeworkdir32r6   r7   r8   rQ   rS   rO   r;   r   Zguess_fwr   r   r   FrameworkDir32  s    zSystemInfo.FrameworkDir32c                 C  s&   t j| jd}| j| jjdp$|S )zw
        Microsoft .NET Framework 64bit directory.

        Return
        ------
        str
            path
        zMicrosoft.NET\Framework64Zframeworkdir64r   r   r   r   r   FrameworkDir64  s    zSystemInfo.FrameworkDir64c                 C  s
   |  dS )z
        Microsoft .NET Framework 32bit versions.

        Return
        ------
        tuple of str
            versions
            _find_dot_net_versionsr   r   r   r   FrameworkVersion32  s    
zSystemInfo.FrameworkVersion32c                 C  s
   |  dS )z
        Microsoft .NET Framework 64bit versions.

        Return
        ------
        tuple of str
            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rJ|dfS | jdkrt| dd	 d
krldn|dfS | jdkrdS | jdkrdS dS )z
        Find Microsoft .NET Framework versions.

        Parameters
        ----------
        bits: int
            Platform number of bits: 32 or 64.

        Return
        ------
        tuple of str
            versions
        zframeworkver%dzFrameworkDir%dvr   r   zv4.0r   Nrx   Zv4z
v4.0.30319v3.5r   )r   
v2.0.50727g       @)zv3.0r   )rS   rO   r;   getattrr   rW   r   )r   bitsZreg_verZdot_net_dirrl   r   r   r   r   7  s    

 

z!SystemInfo._find_dot_net_versionsc                   s,    fddt t D }t|dp*dS )a)  
        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 starting by this prefix

        Return
        ------
        str
            name
        c                 3  s2   | ]*}t jt j |r|r|V  qd S r3   )r6   r7   r   r8   
startswith).0Zdir_namer7   prefixr   r   	<genexpr>f  s   
z0SystemInfo._use_last_dir_name.<locals>.<genexpr>Nr   )reversedr6   rp   next)r7   r   Zmatching_dirsr   r   r   r   U  s    zSystemInfo._use_last_dir_name)N)r   )#r   r	   r
   r/   r   r0   rQ   rR   r|   r   rV   rZ   rT   staticmethodrt   r1   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   \  sZ   
	*





*
$








rP   c                   @  sZ  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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d0d1 Zed2d3 Zed4d5 Zed6d7d8d9Zd@d;d<Zd=d> Z dS )AEnvironmentInfoaY  
    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.X.

    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   r4   r2   rS   rP   sirX   r[   r\   r]   )r   r   rX   Z
vc_min_vererrr   r   r   r     s    

zEnvironmentInfo.__init__c                 C  s   | j jS )zk
        Microsoft Visual Studio.

        Return
        ------
        float
            version
        )r   rW   r   r   r   r   rW     s    
zEnvironmentInfo.vs_verc                 C  s   | j jS )zp
        Microsoft Visual C++ version.

        Return
        ------
        float
            version
        )r   rX   r   r   r   r   rX     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 )zu
        Microsoft Visual Studio Tools.

        Return
        ------
        list of str
            paths
        zCommon7\IDEzCommon7\Toolsr   Tr(   r   z1Common7\IDE\CommonExtensions\Microsoft\TestWindowzTeam Tools\Performance ToolszTeam Tools\Performance Tools%sc                   s   g | ]}t j jj|qS r   r6   r7   r8   r   r~   r   r7   r   r   r   
<listcomp>  s     z+EnvironmentInfo.VSTools.<locals>.<listcomp>)rW   r4   r)   )r   pathsarch_subdirr   r   r   VSTools  s    



zEnvironmentInfo.VSToolsc                 C  s$   t j| jjdt j| jjdgS )z
        Microsoft Visual C++ & Microsoft Foundation Class Includes.

        Return
        ------
        list of str
            paths
        IncludezATLMFC\Includer6   r7   r8   r   r   r   r   r   r   
VCIncludes  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 )z
        Microsoft Visual C++ & Microsoft Foundation Class Libraries.

        Return
        ------
        list of str
            paths
              .@Tr   r(   Lib%szATLMFC\Lib%sr   zLib\store%sc                   s   g | ]}t j jj|qS r   r   r   r   r   r   r     s     z/EnvironmentInfo.VCLibraries.<locals>.<listcomp>)rW   r4   r*   )r   r   r   r   r   r   VCLibraries  s    


zEnvironmentInfo.VCLibrariesc                 C  s"   | j dk rg S tj| jjdgS )z
        Microsoft Visual C++ store references Libraries.

        Return
        ------
        list of str
            paths
        r   zLib\store\references)rW   r6   r7   r8   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 )zr
        Microsoft Visual C++ Tools.

        Return
        ------
        list of str
            paths
        Z
VCPackagesr   TFBin%sr   r   r   zbin\HostX86%szbin\HostX64%sr   Bin)r   r6   r7   r8   r   rW   r4   r.   r)   r$   r*   r#   r   )r   r   toolsr,   r   r7   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 )	zw
        Microsoft Windows SDK Libraries.

        Return
        ------
        list of str
            paths
        r   Tr   r   r   r   z%sum%sN)	rW   r4   r*   r6   r7   r8   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 )
zu
        Microsoft Windows SDK Include.

        Return
        ------
        list of str
            paths
        includer   glr   r   z%ssharedz%sumz%swinrtN)r6   r7   r8   r   r   rW   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 )z}
        Microsoft Windows SDK Libraries Paths.

        Return
        ------
        list of str
            paths
        Z
Referencesr   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)r6   r7   r8   r   r   rW   r   )r   reflibpathr   r   r   	OSLibpathF  s8    




  zEnvironmentInfo.OSLibpathc                 C  s   t |  S )zs
        Microsoft Windows SDK Tools.

        Return
        ------
        list of str
            paths
        )list
_sdk_toolsr   r   r   r   SdkToolsn  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r| j	 r~d	}n| jjddd
}d| }tj| jj|V  nJ| j dkrt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.

        Return
        ------
        generator of str
            paths
        r   r   r   zBin\x86Tr   r   )r   r   r   r   zBin\NETFX 4.0 Tools%sz%s%sN)rW   r6   r7   r8   r   r   r4   r$   r)   r!   r   r   )r   bin_dirr   r7   r   r   r   r   r   z  s(    	





zEnvironmentInfo._sdk_toolsc                 C  s   | j j}|rd| S dS )zu
        Microsoft Windows SDK version subdir.

        Return
        ------
        str
            subdir
        %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 )zs
        Microsoft Windows SDK Setup.

        Return
        ------
        list of str
            paths
        r   Setup)rW   r6   r7   r8   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 )zv
        Microsoft .NET Framework Tools.

        Return
        ------
        list of str
            paths
        r   Tr   c                   s   g | ]}t j j|qS r   )r6   r7   r8   r   r   rl   r   r   r   r     s    z+EnvironmentInfo.FxTools.<locals>.<listcomp>c                   s   g | ]}t j j|qS r   )r6   r7   r8   r   r   r   r   r   r     s    )	r4   r   rW   r!   r$   r#   r   r   r   )r   r4   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 )z~
        Microsoft .Net Framework SDK Libraries.

        Return
        ------
        list of str
            paths
        r   Tr   zlib\um%s)rW   r   r   r4   r*   r6   r7   r8   )r   r   r   r   r   NetFxSDKLibraries  s    
z!EnvironmentInfo.NetFxSDKLibrariesc                 C  s*   | j dk s| jjsg S tj| jjdgS )z}
        Microsoft .Net Framework SDK Includes.

        Return
        ------
        list of str
            paths
        r   z
include\um)rW   r   r   r6   r7   r8   r   r   r   r   NetFxSDKIncludes  s    
z EnvironmentInfo.NetFxSDKIncludesc                 C  s   t j| jjdgS )z
        Microsoft Visual Studio Team System Database.

        Return
        ------
        list of str
            paths
        zVSTSDB\Deployr   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 )zn
        Microsoft Build Engine.

        Return
        ------
        list of str
            paths
        r   r   Tr   r   zMSBuild\%0.1f\bin%sZRoslyn)	rW   r   r|   r4   r)   r~   r6   r7   r8   )r   	base_pathr   r7   buildr   r   r   MSBuild  s    



zEnvironmentInfo.MSBuildc                 C  s"   | j dk rg S tj| jjdgS )zt
        Microsoft HTML Help Workshop.

        Return
        ------
        list of str
            paths
        r   zHTML Help Workshop)rW   r6   r7   r8   r   r|   r   r   r   r   HTMLHelpWorkshop  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.

        Return
        ------
        list of str
            paths
        r   Tr   r   z%sucrt%s)	rW   r4   r*   r6   r7   r8   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.

        Return
        ------
        list of str
            paths
        r   r   z%sucrt)rW   r6   r7   r8   r   r   r   )r   r   r   r   r   UCRTIncludes@  s    

zEnvironmentInfo.UCRTIncludesc                 C  s   | j j}|rd| S dS )z
        Microsoft Universal C Runtime SDK version subdir.

        Return
        ------
        str
            subdir
        r   r   )r   r   r   r   r   r   r   P  s    
zEnvironmentInfo._ucrt_subdirc                 C  s(   d| j   krdkrn ng S | jjgS )zk
        Microsoft Visual F#.

        Return
        ------
        list of str
            paths
        r   r   )rW   r   r   r   r   r   r   FSharp]  s    
zEnvironmentInfo.FSharpz
str | None)returnc                   s   d| j  | jjddd g }| jj}tj|	dd}tj
|rxtj|t|d }||tj|dg7 }|tj|d	g7 }d
| j d  d
t| jd  f} fddt||D }tttjj|dS )z{
        Microsoft Visual C++ runtime redistributable dll.

        Returns the first suitable path found or None.
        zvcruntime%d0.dllTr   r+   z\Toolsz\RedistrY   ZonecoreZredistzMicrosoft.VC%d.CRT
   c                 3  s$   | ]\}}t j| |V  qd S r3   )r6   r7   r8   )r   r   Zcrt_dirr   Z	vcruntimer   r   r     s   z2EnvironmentInfo.VCRuntimeRedist.<locals>.<genexpr>N)rX   r4   r*   stripr   r   r6   r7   dirnamer   r   r8   rp   intrW   ra   rb   r   filterisfile)r   prefixesZ
tools_pathZredist_pathZcrt_dirsZcandidate_pathsr   r   r   VCRuntimeRedistl  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r| jr| j|d< |S )z
        Return environment dict.

        Parameters
        ----------
        exists: bool
            It True, only return existing paths.

        Return
        ------
        dict
            environment
        r   r   r   r7   )r   r   r   r7      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   rW   r   )r   existsenvr   r   r   
return_env  sV    
+
zEnvironmentInfo.return_envc           
      C  sv   t j|}t|dtj}t ||}|rBtt	tj
j|n|}|sbd|  }tj|t|}	tj|	S )aC  
        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.

        Parameters
        ----------
        name: str
            Environment variable name
        spec_path_lists: list of str
            Paths
        exists: bool
            It True, only return existing paths.

        Return
        ------
        str
            Pathsep-separated paths
        r   z %s environment variable is empty)ra   chainfrom_iterabler   r0   ry   r6   pathsepr   r   r7   r   upperr[   r\   r]   r   r8   )
r   rK   Zspec_path_listsr   Z
spec_pathsZ	env_pathsr   Zextant_pathsr   Zunique_pathsr   r   r   r     s    zEnvironmentInfo._build_paths)Nr   )T)!r   r	   r
   r/   r   r1   rW   rX   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   o  sj   
	






)


'
#











"
=r   )r/   
__future__r   rd   ra   rr   r6   os.pathplatformtypingr   Zmore_itertoolsr   distutils.errorsr[   systemr   r   r   __annotations__r   r2   rP   r   r   r   r   r   <module>   s0   y >    