[docs]classUnknownPlatformArchitectureError(Exception):"""Raised when the platform architecture can't be determined."""
[docs]def__init__(self,value:str)->None:"""Instantiate class. Args: value: The value causing the architecture to be unknown. """super().__init__(f"Unknown system architecture detected! ({value})")
[docs]@finalclassSystemInfo:"""Information about the system running the application."""__instance:ClassVar[SystemInfo|None]=None
[docs]def__new__(cls,*args:object,**kwargs:object)->SystemInfo:"""Create a new instance of class. This class is a singleton so it will always return the same instance. """ifcls.__instanceisNone:cls.__instance=cast(SystemInfo,super().__new__(cls,*args,**kwargs))returncls.__instance
@cached_propertydefarchitecture(self)->Literal["amd32","amd64","arm32","arm64"]:"""System's CPU architecture."""ifself.is_arm:ifself.is_64bit:return"arm64"return"arm32"ifself.is_x86:ifself.is_64bit:return"amd64"return"amd32"raiseUnknownPlatformArchitectureError(platform.machine())@cached_propertydefis_32bit(self)->bool:"""Whether the system is 32-bit."""returnsys.maxsize<=2**32@cached_propertydefis_64bit(self)->bool:"""Whether the system is 64-bit."""returnsys.maxsize>2**32@cached_propertydefis_arm(self)->bool:"""Whether the system is arm based."""return"arm"inplatform.machine().lower()@cached_propertydefis_frozen(self)->bool:"""Whether or not app is running from a frozen package."""ifgetattr(sys,"frozen",False):returnTruereturnFalse@cached_propertydefis_x86(self)->bool:"""Whether the system is x86."""returnplatform.machine().lower()in("i386","amd64","x86_64")@cached_propertydefos(self)->OsInfo:"""Operating system information."""returnOsInfo()
[docs]@classmethoddefclear_singleton(cls)->None:"""Clear singleton instances. Intended to only be used for running tests. """cls.__instance=None