check_sys_env.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (c) Opendatalab. All rights reserved.
  2. import platform
  3. from packaging import version
  4. def is_windows_environment() -> bool:
  5. return platform.system() == "Windows"
  6. # Detect if the current environment is a Mac computer
  7. def is_mac_environment() -> bool:
  8. return platform.system() == "Darwin"
  9. # Detect if CPU is Apple Silicon architecture
  10. def is_apple_silicon_cpu() -> bool:
  11. return platform.machine() in ["arm64", "aarch64"]
  12. # If Mac computer with Apple Silicon architecture, check if macOS version is 13.5 or above
  13. def is_mac_os_version_supported(min_version: str = "13.5") -> bool:
  14. if not is_mac_environment() or not is_apple_silicon_cpu():
  15. return False
  16. mac_version = platform.mac_ver()[0]
  17. if not mac_version:
  18. return False
  19. # print("Mac OS Version:", mac_version)
  20. return version.parse(mac_version) >= version.parse(min_version)
  21. if __name__ == "__main__":
  22. print("Is Mac Environment:", is_mac_environment())
  23. print("Is Apple Silicon CPU:", is_apple_silicon_cpu())
  24. print("Is Mac OS Version Supported (>=13.5):", is_mac_os_version_supported())