fix(codex): drop Python 3.11 requirement, auto-install python3

- tomllib fallback: try tomllib (3.11+) -> tomli -> minimal parser
- Works with Python 3.8+ (Ubuntu 20.04, Debian 11, etc.)
- Auto-install python3 if not found (like Gemini/Qwen scripts)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
delta-cloud-208e
2026-03-08 10:58:16 +00:00
parent d37772d67c
commit deb1c2cfd2
3 changed files with 108 additions and 11 deletions

View File

@@ -21,7 +21,56 @@ import shutil
import platform
import subprocess
import argparse
import tomllib
try:
import tomllib
except ModuleNotFoundError:
try:
import tomli as tomllib
except ModuleNotFoundError:
# Minimal TOML reader for Python < 3.11
import re as _re
class _T:
@staticmethod
def load(f):
raw = f.read()
return _T._parse(raw.decode("utf-8") if isinstance(raw, bytes) else raw)
@staticmethod
def loads(s):
return _T._parse(s)
@staticmethod
def _parse(text):
result, cur = {}, None
for line in text.split("\n"):
line = line.strip()
if not line or line.startswith("#"):
continue
m = _re.match(r'^\[([^\]]+)\]$', line)
if m:
keys = [k.strip() for k in m.group(1).split(".")]
cur = result
for k in keys:
cur = cur.setdefault(k, {})
continue
m = _re.match(r'^([^=]+?)\s*=\s*(.+)$', line)
if m and cur is not None:
k, v = m.group(1).strip(), m.group(2).strip()
if v.startswith('"') and v.endswith('"'): v = v[1:-1]
elif v == "true": v = True
elif v == "false": v = False
elif _re.match(r'^-?\d+$', v): v = int(v)
elif v.startswith("[") and v.endswith("]"):
inner = v[1:-1].strip()
v = [x.strip().strip('"') for x in inner.split(",")] if inner else []
cur[k] = v
elif m:
k, v = m.group(1).strip(), m.group(2).strip()
if v.startswith('"') and v.endswith('"'): v = v[1:-1]
elif v == "true": v = True
elif v == "false": v = False
elif _re.match(r'^-?\d+$', v): v = int(v)
result[k] = v
return result
tomllib = _T()
from pathlib import Path
from datetime import datetime