a
    G*fW                     @  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   .lib/python3.9/site-packages/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   forcex86Z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joinr4   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r5   r6   r7   r8   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VS7r9   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   r5   r6   r7   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SoftwareZ	Microsoft)r3   r$   r5   r6   r7   )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 nT ty   | j sz||||dd|}W q ty   Y Y qY q0 nY qY n0 zHz$t 	||d W W |r||   S  ty   Y n0 W |r|| q|r|| 0 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CloseKeyrC   HKEYSOSErrorr3   r$   ZQueryValueEx)	r   rB   nameZkey_readZopenkeyZclosekeymshkeybkeyr   r   r   lookup2  s6    



zRegistryInfo.lookupN)F)r   r	   r
   r.   r   r   r   r   r   rF   r   r0   r4   r8   r:   r;   r<   r=   r?   r@   rA   rC   rL   r   r   r   r   r1      s6   










r1   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 r2   )rir3   find_programdata_vs_versknown_vs_paths_find_latest_available_vs_vervs_vervc_ver)r   Zregistry_inforU   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_versrR   	distutilserrorsDistutilsPlatformErrorsetupdatesorted)r   Zreg_vc_versZvc_versr   r   r   rS   w  s    	
z(SystemInfo._find_latest_available_vs_verc                 C  sj  | j j}| j j| j j| j jf}g }t| j j|D ],\}}zt	|||dtj
}W n tyl   Y q2Y n0 | t|\}}}	t|D ]T}
tt6 tt||
d }||vr|| W d   q1 s0    Y  qt|D ]T}
tt4 tt||
}||vr|| W d   q1 s40    Y  qW d   q21 sV0    Y  q2t|S )z
        Find Microsoft Visual Studio versions available in registry.

        Return
        ------
        list of float
            Versions
        r   N)rP   rC   r:   r<   r;   	itertoolsproductrF   r   rE   rD   rG   ZQueryInfoKeyrange
contextlibsuppress
ValueErrorfloatZ	EnumValueappendZEnumKeyr]   )r   rI   ZvckeysZvs_versrJ   rB   rK   Zsubkeysvaluesr   iverr   r   r   rW     s*    	
*
NzSystemInfo.find_reg_vs_versc           	   
   C  s   i }d}zt |}W n ty,   | Y S 0 |D ]}zzt j||d}t|ddd}t|}W d   n1 sv0    Y  |d }t t j|d ||| |d	 < W q2 tt	fy   Y q2Y q20 q2|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.jsonZrtzutf-8)encodingNZinstallationPathVC\Tools\MSVCZinstallationVersion)
r5   listdirrG   r6   r7   openjsonload_as_float_versionKeyError)	r   Zvs_versionsZinstances_dirZhashed_namesrH   Z
state_pathZ
state_filestateZvs_pathr   r   r   rQ     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   )rd   r7   split)versionr   r   r   ro     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)r5   r6   r7   ProgramFilesx86rT   rP   rL   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_legacyr5   r6   isdirrX   rY   rZ   )r   r6   msgr   r   r   VCInstallDir  s
    
zSystemInfo.VCInstallDirc              	   C  s   | j dkrdS z| j| j  }W n ty6   | j}Y n0 tj|d}z*t|d }| || _	tj||W S  t
tfy   Y dS 0 dS )zl
        Locate Visual C++ for VS2017+.

        Return
        ------
        str
            path
              ,@r   rj   rV   N)rT   rR   rp   ry   r5   r6   r7   rk   ro   rU   rG   
IndexError)r   Zvs_dirZguess_vcrU   r   r   r   rz   	  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\VCrv   
installdirZVC)	r5   r6   r7   rw   rT   rP   r<   rL   r:   )r   rx   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rT   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_namer5   r6   r7   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installationfolderrv   r   ZWinSDKNrr   zMicrosoft SDKs\Windows Kits\%szMicrosoft SDKs\Windows\v%sZPlatformSDK)r   r5   r6   r7   rP   r?   rL   r|   r<   rU   rfindrO   r~   )r   sdkdirrh   locr6   Z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)rT   r3   r)   r   NetFxSdkVersionr5   r6   r7   rP   r@   r   r?   rL   )	r   Znetfxverr   r(   ZfxZregpathsrh   r6   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   )r5   r6   r7   rP   r4   rT   rL   )r   r6   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   )Z10Z81r   z
kitsroot%sr   N)rT   rP   rL   rA   )r   Zversrh   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   r5   r6   r7   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   r5   r6   r7   rP   r@   rL   )r   r   rh   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r5   r6   r7   rN   rP   rL   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   Nrs   Zv4z
v4.0.30319v3.5r   )r   
v2.0.50727g       @)zv3.0r   )rP   rL   r:   getattrr   rT   r   )r   bitsZreg_verZdot_net_dirrh   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 r2   )r5   r6   r|   r7   
startswith).0Zdir_namer6   prefixr   r   	<genexpr>f  s   
z0SystemInfo._use_last_dir_name.<locals>.<genexpr>Nr   )reversedr5   rk   next)r6   r   Zmatching_dirsr   r   r   r   U  s    zSystemInfo._use_last_dir_name)N)r   )#r   r	   r
   r.   r   r/   rN   rO   rw   r   rS   rW   rQ   staticmethodro   r0   ry   r~   rz   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   \  sZ   
	*





*
$








rM   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   r3   r1   rP   rM   sirU   rX   rY   rZ   )r   r   rU   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   rT   r   r   r   r   rT     s    
zEnvironmentInfo.vs_verc                 C  s   | j jS )zp
        Microsoft Visual C++ version.

        Return
        ------
        float
            version
        )r   rU   r   r   r   r   rU     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   r5   r6   r7   r   ry   r   r6   r   r   r   
<listcomp>      z+EnvironmentInfo.VSTools.<locals>.<listcomp>)rT   r3   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
        ZIncludezATLMFC\Includer5   r6   r7   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     r   z/EnvironmentInfo.VCLibraries.<locals>.<listcomp>)rT   r3   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)rT   r5   r6   r7   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   r5   r6   r7   r~   rT   r3   r-   r)   r$   r*   r#   r   )r   r   toolsr,   r   r6   Zhost_dirr   r   r   VCTools  s.    


zEnvironmentInfo.VCToolsc                 C  st   | j dkr2| jjddd}tj| jjd| gS | jjdd}tj| jjd}| j}tj|d||f gS dS )	zw
        Microsoft Windows SDK Libraries.

        Return
        ------
        list of str
            paths
        r   Tr   r   r   r   z%sum%sN)	rT   r3   r*   r5   r6   r7   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   Zglr   r   z%ssharedz%sumz%swinrtN)r5   r6   r7   r   r   rT   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.VCLibsrv   ZCommonConfigurationZneutral)r5   r6   r7   r   r   rT   r   )r   reflibpathr   r   r   	OSLibpathF  s4    




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v 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)rT   r5   r6   r7   r   r   r3   r$   r)   r!   r   r   )r   Zbin_dirr   r6   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   ZSetup)rT   r5   r6   r7   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   )r5   r6   r7   r   r   rh   r   r   r   r     s   z+EnvironmentInfo.FxTools.<locals>.<listcomp>c                   s   g | ]}t j j|qS r   )r5   r6   r7   r   r   r   r   r   r     s   )	r3   r   rT   r!   r$   r#   r   r   r   )r   r3   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)rT   r   r   r3   r*   r5   r6   r7   )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)rT   r   r   r5   r6   r7   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)	rT   r   rw   r3   r)   ry   r5   r6   r7   )r   	base_pathr   r6   Z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)rT   r5   r6   r7   r   rw   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)	rT   r3   r*   r5   r6   r7   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)rT   r5   r6   r7   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   )rT   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\RedistrV   ZonecoreZredistzMicrosoft.VC%d.CRT
   c                 3  s$   | ]\}}t j| |V  qd S r2   )r5   r6   r7   )r   r   Zcrt_dirr   Z	vcruntimer   r   r     s   z2EnvironmentInfo.VCRuntimeRedist.<locals>.<genexpr>N)rU   r3   r*   stripr   r~   r5   r6   dirnamer   r|   r7   rk   intrT   r^   r_   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   r6   )r   r   r   r6      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   rT   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)r^   chainfrom_iterabler   r/   rt   r5   pathsepr   r   r6   r|   upperrX   rY   rZ   r   r7   )
r   rH   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   r0   rT   rU   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.   Z
__future__r   ra   r^   rm   r5   os.pathplatformtypingr   Zmore_itertoolsr   Zdistutils.errorsrX   systemr   r   r   __annotations__r   r1   rM   r   r   r   r   r   <module>   s0   y >    