1
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ä608_‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ `    ‹      Õ—ÑnÓ0†ï÷ÆÜµ'Ý[j4šITl]µ!„PåÚnc-±#Ûmžž“¤°njH)7qŽýÇÿùùÄ‰_%7£Ù—é%ù0»¾"ÓOï¯Æ#B{ ŸOF É,iNûÑ àrB	MC(Î Ê²ì—'}ëV0»…4äÙ)øà´}$eGqÝÇŽHœ*.±%qÐ!Sll¤z vIÀ®ƒ×Rás•‡ÅÚƒ±R�T-TD ŠuKíò’;5oEZy-xÖF‚‹T�®'=‰¡µ@SØºÆ+«:™ÁËãü"_4þõ­cqHÉ†gze†4Ø‚²Xç+â�RÐÂ4Ï¸¹ï¯ô’ž…!ý:Ý|C„´~šÅœ¤N-‡ôÝh89¿&”Mx®bàû5×¨¹ ìŠû@r+õR+yP|×Šïô÷Ã&­&Q^8]mÍ£qUØÌYß AêvU­Dþn5¸x²Ó‹ÛËÉ,ß¶K"ë)³û—¯‘²)Ž›@í”ÖU[ÌÖóµYøâügH¶N¯Ò@!=²Wùäksoliváqa÷b›*LUTóL5÷øö(ÛÓ¹ð,ããèømo0èG$ŠÎðJqÛü�hë†–L<S•QÖ4Lß¬ó…rs»œ{<eOãýÚâÍn(¸Ãï–.ÊtÑ§X°äë²xôÖÑm¤œOˆ0î"PS›;ZŒCU`òõµƒÉ¯±´mÛ”¼òuæÞ[¡yÐ*Êöv¿<Þò`{ü�¡9uÇÐþü 6¹e    C   ˆl–Ðz¾”Šj"Tâ‚À½q¶”Å£�þFë¬¬ãe#qº•à?Ç„hO8ïÆ_ŠI|¥�+Wé3ž¯ÅÄ ?÷     """
Environment info about Microsoft Compilers.

>>> getfixture('windows_only')
>>> ei = EnvironmentInfo('amd64')
"""

from __future__ import annotations

import contextlib
import itertools
import json
import os
import os.path
import platform
from typing import TYPE_CHECKING, TypedDict, overload

from more_itertools import unique_everseen

from ._path import StrPath
from .compat import py310

import distutils.errors

if TYPE_CHECKING:
    from typing_extensions import LiteralString, NotRequired

# https://github.com/python/mypy/issues/8166
if not TYPE_CHECKING and platform.system() == 'Windows':
    import winreg
    from os import environ
else:
    # Mock winreg and environ so the module can be imported on this platform.

    class winreg:
        HKEY_USERS = None
        HKEY_CURRENT_USER = None
        HKEY_LOCAL_MACHINE = None
        HKEY_CLASSES_ROOT = None

    environ: dict[str, str] = {}


class PlatformInfo:
    """
    Current and Target Architectures information.

    Parameters
    ----------
    arch: str
        Target architecture.
    """

    current_cpu = environ.get('processor_architecture', '').lower()

    def __init__(self, arch: str) -> None:
        self.arch = arch.lower().replace('x64', 'amd64')

    @property
    def target_cpu(self) -> str:
        """
        Return Target CPU architecture.

        Return
        ------
        str
            Target CPU
        """
        return self.arch[self.arch.find('_') + 1 :]

    def target_is_x86(self) -> bool:
        """
        Return True if target CPU is x86 32 bits..

        Return
        ------
        bool
            CPU is x86 32 bits
        """
        return self.target_cpu == 'x86'

    def current_is_x86(self) -> bool:
        """
        Return True if current CPU is x86 32 bits..

        Return
        ------
        bool
            CPU is x86 32 bits
        """
        return self.current_cpu == 'x86'

    def current_dir(self, hidex86=False, x64=False) -> str:
        """
        Current 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: '\target', or '' (see hidex86 parameter)
        """
        return (
            ''
            if (self.current_cpu == 'x86' and hidex86)
            else r'\x64'
            if (self.current_cpu == 'amd64' and x64)
            else rf'\{self.current_cpu}'
        )

    def target_dir(self, hidex86=False, x64=False) -> str:
        r"""
        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)
        """
        return (
            ''
            if (self.target_cpu == 'x86' and hidex86)
            else r'\x64'
            if (self.target_cpu == 'amd64' and x64)
            else rf'\{self.target_cpu}'
        )

    def cross_dir(self, forcex86=False) -> str:
        r"""
        Cross platfor