Files
arma-modlist-tools/check_deps.py
revernomad17 86a6ab9b01 fix check_deps.py crash on Python < 3.10
str | None union syntax requires Python 3.10+. Adding
from __future__ import annotations makes all annotations
lazy so the script can run on older Python and report the
version requirement instead of crashing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 16:13:47 +07:00

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, 11)
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()