|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Check developer environment for required toolchain versions. |
| 3 | +
|
| 4 | +Usage: python scripts/check_env.py |
| 5 | +Exits 0 if checks pass, non-zero otherwise. |
| 6 | +""" |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +import shutil |
| 10 | +import subprocess |
| 11 | +import sys |
| 12 | + |
| 13 | + |
| 14 | +def check_python(min_major: int = 3, min_minor: int = 11) -> bool: |
| 15 | + v = sys.version_info |
| 16 | + ok = (v.major > min_major) or (v.major == min_major and v.minor >= min_minor) |
| 17 | + print(f"Python: {v.major}.{v.minor}.{v.micro} -> {'OK' if ok else 'FAIL (need >=%d.%d)' % (min_major, min_minor)}") |
| 18 | + return ok |
| 19 | + |
| 20 | + |
| 21 | +def check_executable(name: str) -> bool: |
| 22 | + path = shutil.which(name) |
| 23 | + print(f"{name}: {'found at ' + path if path else 'NOT FOUND'}") |
| 24 | + return bool(path) |
| 25 | + |
| 26 | + |
| 27 | +def check_aws_cli(min_version: tuple[int, int, int] = (2, 27, 50)) -> bool: |
| 28 | + if not check_executable("aws"): |
| 29 | + return False |
| 30 | + try: |
| 31 | + out = subprocess.check_output(["aws", "--version"], stderr=subprocess.STDOUT) |
| 32 | + s = out.decode("utf-8", errors="ignore") |
| 33 | + # Example: aws-cli/2.7.18 Python/3.9.16 Linux/5.15.0 |
| 34 | + parts = s.split()[0].split("/") |
| 35 | + if len(parts) >= 2: |
| 36 | + ver = parts[1] |
| 37 | + nums = tuple(int(p) for p in ver.split(".")[:3]) |
| 38 | + ok = nums >= min_version |
| 39 | + print(f"AWS CLI: {ver} -> {'OK' if ok else 'FAIL (need >=%s)' % ('.'.join(map(str,min_version)))}") |
| 40 | + return ok |
| 41 | + except Exception as e: |
| 42 | + print("Error checking aws --version:", e) |
| 43 | + return False |
| 44 | + |
| 45 | + |
| 46 | +def main() -> None: |
| 47 | + ok = True |
| 48 | + ok = check_python() and ok |
| 49 | + ok = check_executable("poetry") and ok |
| 50 | + ok = check_aws_cli() and ok |
| 51 | + if not ok: |
| 52 | + print("One or more environment checks failed.") |
| 53 | + sys.exit(2) |
| 54 | + print("Environment OK") |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + main() |
0 commit comments