a
    5h                     @  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
mZ ddlmZ ddlZe
rzddlmZm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eZG dd dZdS )zo
Environment info about Microsoft Compilers.

>>> getfixture('windows_only')
>>> ei = EnvironmentInfo('amd64')
    )annotationsN)TYPE_CHECKING	TypedDict)unique_everseen)LiteralStringNotRequired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                   @  st   e Zd ZdZedd ZddddZe	dd	 Z
d
d Zdd ZdddddZdddddZdddZdS )PlatformInfoz
    Current and Target Architectures information.

    Parameters
    ----------
    arch: str
        Target architecture.
    Zprocessor_architecture Nonereturnc                 C  s   |  dd| _d S )Nx64amd64)lowerreplacearch)selfr   r   r   r   __init__5   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_cpu8   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_x86D   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_x86O   s    	zPlatformInfo.current_is_x86Fstrc                 C  s0   | 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\r(   r   hidex86r   r   r   r   current_dirZ   s    
zPlatformInfo.current_dirc                 C  s0   | 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_dirr   s    
zPlatformInfo.target_dirc                 C  s4   |rdn| j }| j|krdS |  d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   r-   r    )r)   r$   r1   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*   r0   r1   r4   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ddZ
eddddZed	d
 Zedd Zedd ZeddddZeddddZedd Zedd Zedd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.
    r   r   c                 C  s
   || _ d S N)pi)r   Zplatform_infor   r   r   r      s    zRegistryInfo.__init__r+   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joinr;   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r<   r=   r>   r?   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   r<   r=   r>   rD   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NETFXSDKrE   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)r:   r*   r<   r=   r>   )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CloseKeyrJ   HKEYSOSErrorr:   r*   ZQueryValueEx)	r   rI   nameZkey_readZopenkeyZclosekeymshkeybkeyr   r   r   lookup5  s6    



zRegistryInfo.lookupN)F)r   r   r   r5   r
   r   r   r   r   rM   r   r7   r;   r?   rA   rB   rC   rD   rF   rG   rH   rJ   rS   r   r   r   r   r8      s6   






r8   c                   @  sf  e Zd ZdZeddZeddZedeZd=ddd	d
Z	dd Z
dd ZddddZedd Zedd Zedd Zdd Zdd ZeddddZedd  Zed!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d0d1 Zed2d3 Zed4dd5d6Zed4dd7d8Z d4dd9d:Z!ed>d;d<Z"dS )?
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)Nr   r   c                 C  s2   || _ | j j| _|  | _|p$|   | _| _d S r9   )rir:   find_programdata_vs_versknown_vs_paths_find_latest_available_vs_vervs_vervc_ver)r   Zregistry_infor\   r   r   r   r   q  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_versrY   	distutilserrorsDistutilsPlatformErrorsetupdatesorted)r   Zreg_vc_versZvc_versr   r   r   rZ   z  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)rW   rJ   rA   rC   rB   	itertoolsproductrM   r
   rL   rK   rN   ZQueryInfoKeyrange
contextlibsuppress
ValueErrorfloatZ	EnumValueappendZEnumKeyrd   )r   rP   ZvckeysZvs_versrQ   rI   rR   Zsubkeysvaluesr    iverr   r   r   r^     s*    	
*
NzSystemInfo.find_reg_vs_verszdict[float, str]c           	   
   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)
r<   listdirrN   r=   r>   openjsonload_as_float_versionKeyError)	r   Zvs_versionsZinstances_dirZhashed_namesrO   Z
state_pathZ
state_filestateZvs_pathr   r   r   rX     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   )rk   r>   split)versionr   r   r   rv     s    zSystemInfo._as_float_versionc                 C  s6   t j| jd| jd}| j| jj| jdp4|S )zp
        Microsoft Visual Studio directory.

        Return
        ------
        str
            path
        Microsoft Visual Studio 0.1f)r<   r=   r>   ProgramFilesx86r[   rW   rS   rB   )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_legacyr<   r=   isdirr_   r`   ra   )r   r=   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   rq   r]   N)r[   rY   rw   r   r<   r=   r>   rr   rv   r\   rN   
IndexError)r   Zvs_dirZguess_vcr\   r   r   r   r     s    	
zSystemInfo._guess_vcc                 C  st   t j| jd| jdd}t j| jj| jd}| j|d}|rTt j|dn|}| j| jj| jdpr|S )z{
        Locate Visual C++ for versions prior to 2017.

        Return
        ------
        str
            path
        r}   r~   z\VC
installdirZVC)	r<   r=   r>   r   r[   rW   rC   rS   rA   )r   r   Zreg_pathZ	python_vcZ
default_vcr   r   r   r   *  s    	zSystemInfo._guess_vc_legacyztuple[LiteralString, ...]c                 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   r   r[   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_namer<   r=   r>   WindowsSdkDirr#   r   r   r   WindowsSdkLastVersionV  s    
z SystemInfo.WindowsSdkLastVersion
str | Nonec                 C  s@  d}| j D ]2}tj| jjd| }| j|d}|r
 q>q
|rNtj|stj| jj| j	d}| 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|s<tj| jd}|S )zn
        Microsoft Windows SDK directory.

        Return
        ------
        str
            path
        r   vinstallationfolderr~   r   ZWinSDKNry   zMicrosoft SDKs\Windows Kits\zMicrosoft SDKs\Windows\vZPlatformSDK)r   r<   r=   r>   rW   rF   rS   r   rC   r\   rfindrV   r   )r   sdkdirro   locr=   Zinstall_baseZintverdr   r   r   r   b  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| d| }g }| j dkr| jD ]}|tj| jj	||g7 }qf| j
D ]&}|tj| jjd| 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/   r-   -zWinSDK-NetFxZToolsr   r   Ar   N)r[   r:   r0   r   NetFxSdkVersionr<   r=   r>   rW   rG   r   rF   rS   )	r   Znetfxverr   r/   ZfxZregpathsro   r=   Zexecpathr   r   r   WindowsSDKExecutablePath  s$    



$
z#SystemInfo.WindowsSDKExecutablePathc                 C  s.   t j| jj| jdd}| j|dp,dS )zl
        Microsoft Visual F# directory.

        Return
        ------
        str
            path
        r~   z	\Setup\F#Z
productdirr   )r<   r=   r>   rW   r;   r[   rS   )r   r=   r   r   r   FSharpInstallDir  s    
zSystemInfo.FSharpInstallDirc                 C  sH   | 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kitsrootr   N)r[   rW   rS   rH   )r   Zversro   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   r<   r=   r>   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   r<   r=   r>   rW   rG   rS   )r   r   ro   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r<   r=   r>   rU   rW   rS   rA   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.FrameworkDir64ztuple[str, ...]c                 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| }|p:| |dp:d}| jdkrN|dfS | jdkrx| dd	 d
krpd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frameworkverZFrameworkDirr   r   r   zv4.0r   Nrz   Zv4z
v4.0.30319v3.5r   )r   
v2.0.50727g       @)zv3.0r   r   )rW   rS   rA   getattrr   r[   r   )r   bitsZreg_verZdot_net_dirro   r   r   r   r   ;  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 r9   )r<   r=   r   r>   
startswith).0Zdir_namer=   prefixr   r   	<genexpr>j  s   
z0SystemInfo._use_last_dir_name.<locals>.<genexpr>Nr   )reversedr<   rr   next)r=   r   Zmatching_dirsr   r   r   r   Y  s    zSystemInfo._use_last_dir_name)N)r   )#r   r   r   r5   r	   r6   rU   rV   r   r   rZ   r^   rX   staticmethodrv   r7   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rT   _  sZ   	*



*
$






rT   c                   @  s6   e Zd ZU ded< ded< ded< ded< ded< dS )	_EnvironmentDictr+   includer   libpathr=   zNotRequired[str | None]py_vcruntime_redistN)r   r   r   __annotations__r   r   r   r   r   s  s
   
r   c                   @  sh  e Zd ZdZdCd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d0d1 Zed2d3 Zed4d5 Zed6d7 Zed8dd9d:ZdDd<d=d>d?d@ZdAdB Z dS )E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   r   r   c                 C  sB   t || _t| j| _t| j|| _| j|k r>d}tj	|d S )Nz.No suitable Microsoft Visual C++ version found)
r   r:   r8   rW   rT   sir\   r_   r`   ra   )r   r   r\   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   r[   r#   r   r   r   r[     s    
zEnvironmentInfo.vs_verc                 C  s   | j jS )zp
        Microsoft Visual C++ version.

        Return
        ------
        float
            version
        )r   r\   r#   r   r   r   r\     s    
zEnvironmentInfo.vc_verc                   sX   ddg} j dkrF 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 Toolsc                   s   g | ]}t j jj|qS r   r<   r=   r>   r   r   r   r=   r#   r   r   
<listcomp>      z+EnvironmentInfo.VSTools.<locals>.<listcomp>)r[   r:   r0   )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r<   r=   r>   r   r   r#   r   r   r   
VCIncludes  s    zEnvironmentInfo.VCIncludesc                   sh    j dkr jjdd}n jjdd}d| d| g} j dkrV|d| g7 } fd	d
|D S )z
        Microsoft Visual C++ & Microsoft Foundation Class Libraries.

        Return
        ------
        list of str
            paths
              .@Tr   r/   Libz
ATLMFC\Libr   z	Lib\storec                   s   g | ]}t j jj|qS r   r   r   r#   r   r   r     r   z/EnvironmentInfo.VCLibraries.<locals>.<listcomp>)r[   r:   r1   )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)r[   r<   r=   r>   r   r   r#   r   r   r   VCStoreRefs  s    

zEnvironmentInfo.VCStoreRefsc                 C  s8  | j }tj|jdg}| jdkr&dnd}| j|}|rV|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j	
d	d
 }tjdd| d}|tj|j|| jjdd g7 }| jj	| jjkr4|tj|j|| jjdd g7 }n|tj|jdg7 }|S )a  
        Microsoft Visual C++ Tools.

        Return
        ------
        list of str
            paths

        When host CPU is ARM, the tools should be found for ARM.

        >>> getfixture('windows_only')
        >>> mp = getfixture('monkeypatch')
        >>> mp.setattr(PlatformInfo, 'current_cpu', 'arm64')
        >>> ei = EnvironmentInfo(arch='irrelevant')
        >>> paths = ei.VCTools
        >>> any('HostARM64' in path for path in paths)
        True
        Z
VCPackagesr   TFBinr   r   r   r   r   binZHostz%sr   )r   r<   r=   r>   r   r[   r:   r4   r0   r)   r   upperr1   r$   )r   r   toolsr2   r   r=   Zhost_idZhost_dirr   r   r   VCTools  s.    
zEnvironmentInfo.VCToolsc                 C  sx   | j dkr4| 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| gS dS )	zw
        Microsoft Windows SDK Libraries.

        Return
        ------
        list of str
            paths
        r   Tr   r   r   r   umN)	r[   r:   r1   r<   r=   r>   r   r   _sdk_subdir)r   r   r   Zlibverr   r   r   OSLibraries-  s    

zEnvironmentInfo.OSLibrariesc                 C  s   t j| jjd}| jdkr.|t j|dgS | jdkr@| j}nd}t j|| dt j|| dt j|| dgS d	S )
zu
        Microsoft Windows SDK Include.

        Return
        ------
        list of str
            paths
        r   r   glr   r   Zsharedr   ZwinrtN)r<   r=   r>   r   r   r[   r   )r   r   sdkverr   r   r   
OSIncludesA  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| jd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)r<   r=   r>   r   r   r[   r   )r   refr   r   r   r   	OSLibpath[  s4    




zEnvironmentInfo.OSLibpathc                 C  s   t |  S )zs
        Microsoft Windows SDK Tools.

        Return
        ------
        list of str
            paths
        )list
_sdk_toolsr#   r   r   r   SdkTools  s    
zEnvironmentInfo.SdkToolsc                 c  s  | j dk r0| j dkrdnd}tj| jj|V  | j sf| jjdd}d| }tj| jj|V  | j dv r| j	 rd}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|| | 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   zBin\NETFX 4.0 ToolsN)r[   r<   r=   r>   r   r   r:   r*   r0   r'   r   r   )r   Zbin_dirr   r=   r   r   r   r   r     s(    	







zEnvironmentInfo._sdk_toolsc                 C  s   | j j}|r| dS dS )zu
        Microsoft Windows SDK version subdir.

        Return
        ------
        str
            subdir
        r-   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)r[   r<   r=   r>   r   r   r#   r   r   r   SdkSetup  s    

zEnvironmentInfo.SdkSetupc                   s   | j }| j | jdkr0d}|  o,|  }n$| p>| }|jdkpR|jdk}g }|rt| fdd jD 7 }|r| fdd jD 7 }|S )zv
        Microsoft .NET Framework Tools.

        Return
        ------
        list of str
            paths
        r   Tr   c                   s   g | ]}t j j|qS r   )r<   r=   r>   r   r   ro   r   r   r   r     s   z+EnvironmentInfo.FxTools.<locals>.<listcomp>c                   s   g | ]}t j j|qS r   )r<   r=   r>   r   r   r   r   r   r     s   )	r:   r   r[   r'   r*   r)   r$   r   r   )r   r:   Z	include32Z	include64r   r   r   r   FxTools  s"    

zEnvironmentInfo.FxToolsc                 C  s>   | j dk s| jjsg S | jjdd}tj| jjd| gS )z~
        Microsoft .Net Framework SDK Libraries.

        Return
        ------
        list of str
            paths
        r   Tr   zlib\um)r[   r   r   r:   r1   r<   r=   r>   )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)r[   r   r   r<   r=   r>   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 dd| }tj||g}| j dkr|tj||d	g7 }|S )
zn
        Microsoft Build Engine.

        Return
        ------
        list of str
            paths
        r   r   Tr   r   zMSBuild\r~   z\binZRoslyn)	r[   r   r   r:   r0   r   r<   r=   r>   )r   	base_pathr   r=   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)r[   r<   r=   r>   r   r   r#   r   r   r   HTMLHelpWorkshop4  s    

z EnvironmentInfo.HTMLHelpWorkshopc                 C  sN   | j dk rg S | jjdd}tj| jjd}| j}tj|| d| gS )z
        Microsoft Universal C Runtime SDK Libraries.

        Return
        ------
        list of str
            paths
        r   Tr   r   ucrt)	r[   r:   r1   r<   r=   r>   r   r   _ucrt_subdir)r   r   r   r   r   r   r   UCRTLibrariesC  s    

zEnvironmentInfo.UCRTLibrariesc                 C  s8   | j dk rg S tj| jjd}tj|| j dgS )z
        Microsoft Universal C Runtime SDK Include.

        Return
        ------
        list of str
            paths
        r   r   r   )r[   r<   r=   r>   r   r   r   )r   r   r   r   r   UCRTIncludesU  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   e  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   )r[   r   r   r#   r   r   r   FSharpr  s    
zEnvironmentInfo.FSharpr   c                   s   d| j  d| jjddd g }| jj}tj|	dd}tj
|r|tj|t|d }||tj|d	g7 }|tj|d
g7 }d| j d  ddt| jd  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.
        	vcruntimez0.dllTr   r-   z\Toolsz\Redistr]   ZonecoreZredistzMicrosoft.VC
   z.CRTc                 3  s$   | ]\}}t j| |V  qd S r9   )r<   r=   r>   )r   r   Zcrt_dirr   r   r   r   r     s   z2EnvironmentInfo.VCRuntimeRedist.<locals>.<genexpr>N)r\   r:   r1   stripr   r   r<   r=   dirnamer   r   r>   rr   intr[   re   rf   r   filterisfile)r   prefixesZ
tools_pathZredist_pathZcrt_dirsZcandidate_pathsr   r   r   VCRuntimeRedist  s     
zEnvironmentInfo.VCRuntimeRedistTboolr   )existsr   c                 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   r=   )r   r   r   r=      r   )r   _build_pathsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r[   r   )r   r   envr   r   r   
return_env  sV    
+
zEnvironmentInfo.return_envc           
      C  sx   t j|}t|dtj}t ||}|rBtt	tj
j|n|}|sd|  d}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 environment variable is empty)re   chainfrom_iterabler	   r6   r{   r<   pathsepr   r   r=   r   r   r_   r`   ra   r   r>   )
r   rO   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   r5   r   r7   r[   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r   r   r   {  sj   	






2


'
#











"=r   )r5   Z
__future__r   rh   re   rt   r<   Zos.pathplatformtypingr   r   Zmore_itertoolsr   Zdistutils.errorsr_   Ztyping_extensionsr   r   systemr
   r	   dictr   r   r8   rT   r   r   r   r   r   r   <module>   s6   y >    