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

@@ -5,7 +5,42 @@ checks config.toml values and environment variables.
"""
import os
import tomllib
try:
import tomllib
except ModuleNotFoundError:
try:
import tomli as tomllib
except ModuleNotFoundError:
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 _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:
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)
(cur if cur is not None else result)[k] = v
return result
tomllib = _T()
from dataclasses import dataclass
from typing import Callable, Optional