parser.py and update_mods.py were missing 'from __future__ import annotations', causing a TypeError on Python < 3.10 when the X | Y union syntax is evaluated at runtime. All other modules already had the import. Also lowers MIN_PYTHON from 3.11 to 3.9 -- the toolchain does not use any Python 3.10/3.11-specific stdlib features beyond the union annotation syntax which is now handled by the future import. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
95 lines
2.4 KiB
Python
95 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Verify Python version, OS, and required packages before running the toolchain.
|
|
|
|
Usage:
|
|
python check_deps.py
|
|
"""
|
|
|
|
from __future__ import annotations # allows str | None syntax on Python < 3.10
|
|
|
|
import importlib.metadata
|
|
import sys
|
|
|
|
# Must not import arma_modlist_tools here — that's what we're checking FOR.
|
|
|
|
MIN_PYTHON = (3, 9)
|
|
REQUIRED_PACKAGES = ["requests", "tqdm"]
|
|
|
|
|
|
def _python_ok() -> bool:
|
|
return sys.version_info >= MIN_PYTHON
|
|
|
|
|
|
def _get_os_label() -> str:
|
|
"""Inline OS detection — avoids importing compat before deps are confirmed."""
|
|
import platform
|
|
if sys.platform == "win32":
|
|
if "Server" in platform.version() or "Server" in platform.uname().version:
|
|
return "Windows Server"
|
|
return "Windows"
|
|
if sys.platform == "linux":
|
|
try:
|
|
with open("/etc/os-release", encoding="utf-8") as f:
|
|
text = f.read().lower()
|
|
if "ubuntu" in text:
|
|
import os
|
|
headless = not (os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"))
|
|
return "Ubuntu Server" if headless else "Ubuntu"
|
|
except OSError:
|
|
pass
|
|
return "Linux"
|
|
return "Unknown"
|
|
|
|
|
|
def _pkg_version(name: str) -> str | None:
|
|
try:
|
|
return importlib.metadata.version(name)
|
|
except importlib.metadata.PackageNotFoundError:
|
|
return None
|
|
|
|
|
|
def main() -> None:
|
|
print()
|
|
|
|
# Python version
|
|
ver = sys.version.split()[0]
|
|
py_ok = _python_ok()
|
|
status = "OK" if py_ok else f"NEED >= {MIN_PYTHON[0]}.{MIN_PYTHON[1]}"
|
|
print(f" {'Python':<14} {ver:<12} {status}")
|
|
|
|
# OS
|
|
os_label = _get_os_label()
|
|
print(f" {'OS':<14} {os_label}")
|
|
print()
|
|
|
|
# Packages
|
|
missing = []
|
|
for pkg in REQUIRED_PACKAGES:
|
|
v = _pkg_version(pkg)
|
|
if v:
|
|
print(f" {pkg:<14} {v:<12} OK")
|
|
else:
|
|
print(f" {pkg:<14} {'---':<12} MISSING")
|
|
missing.append(pkg)
|
|
|
|
print()
|
|
|
|
if not py_ok:
|
|
print(f" Python {MIN_PYTHON[0]}.{MIN_PYTHON[1]}+ is required.")
|
|
sys.exit(1)
|
|
|
|
if missing:
|
|
print(f" {len(missing)} package(s) missing. Install with:")
|
|
print(f" pip install {' '.join(missing)}")
|
|
print()
|
|
print(" Run check_deps.py again to verify.")
|
|
sys.exit(1)
|
|
|
|
print(" All checks passed. Ready to run.")
|
|
print()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|