|
| 1 | +__all__ = ("TargetTriple", "pythonTriple") |
| 2 | +import sys |
| 3 | +import typing |
| 4 | + |
| 5 | + |
| 6 | +class TargetTripleParser: |
| 7 | + __slots__ = ("archs", "oses", "abis") |
| 8 | + |
| 9 | + def __init__(self, archs: typing.Set[str], oses: typing.Set[str], abis: typing.Set[str]): |
| 10 | + self.archs = archs |
| 11 | + self.oses = oses |
| 12 | + self.abis = abis |
| 13 | + |
| 14 | + |
| 15 | +class _TargetTriple: |
| 16 | + __slots__ = ("arch", "bitness", "os", "abi") |
| 17 | + |
| 18 | + def __init__(self, arch: typing.Optional[str] = None, os: typing.Optional[str] = None, abi: typing.Optional[str] = None, bitness: typing.Optional[int] = None) -> None: |
| 19 | + self.arch = arch |
| 20 | + self.os = os |
| 21 | + self.abi = abi |
| 22 | + self.bitness = bitness |
| 23 | + |
| 24 | + @classmethod |
| 25 | + def parse(cls, s: str, parser: TargetTripleParser) -> "_TargetTriple": |
| 26 | + |
| 27 | + return cls() |
| 28 | + |
| 29 | + def getTuple(self) -> typing.Tuple[str, str, str]: |
| 30 | + return (self.arch, self.os, self.abi) |
| 31 | + |
| 32 | + def __str__(self) -> str: |
| 33 | + return "-".join(self.getTuple()) |
| 34 | + |
| 35 | + def __repr__(self) -> str: |
| 36 | + return self.__class__.__name__ + "(" + ", ".join(repr(c) for c in self.getTuple()) + ")" |
| 37 | + |
| 38 | + def __hash__(self) -> int: |
| 39 | + return hash(self.getTuple()) |
| 40 | + |
| 41 | + def __eq__(self, other: "_TargetTriple") -> bool: |
| 42 | + if isinstance(other, str): |
| 43 | + return other == str(self) |
| 44 | + else: |
| 45 | + return self.getTuple() == other.getTuple() |
| 46 | + |
| 47 | + |
| 48 | +pythonTriple = sys.implementation._multiarch.split("-") |
| 49 | +pythonTriple = _TargetTriple(pythonTriple[0], pythonTriple[1], pythonTriple[2]) |
| 50 | + |
| 51 | + |
| 52 | +class TargetTriple(_TargetTriple): |
| 53 | + __slots__ = () |
| 54 | + |
| 55 | + def __init__(self, arch: typing.Optional[str] = None, os: typing.Optional[str] = None, abi: typing.Optional[str] = None, bitness: typing.Optional[int] = None) -> None: |
| 56 | + arch = arch if arch is not None else pythonTriple.arch |
| 57 | + os = os if os is not None else pythonTriple.os |
| 58 | + abi = abi if abi is not None else pythonTriple.abi |
| 59 | + bitness = bitness if bitness is not None else pythonTriple.bitness |
| 60 | + super().__init__(arch, os, abi, bitness) |
0 commit comments