INNER CODE UNIT · Python
deep_set
x-cmd/x-cmd · mod/codex/lib/py/use-ds.py:59
def deep_set(doc, path, value):
"""Set a dotted-path key in a tomlkit document, creating tables as needed."""
keys = path.split(".")
cur = doc
for k in keys[:-1]:
if k not in cur or not isinstance(cur[k], dict):
cur[k] = tomlkit.table()
cur = cur[k]
cur[keys[-1]] = value
# ── resolve config path ───────────────────────────────────────────
config_dir = os.environ.get("CODEX_HOME") or os.path.expanduser("~/.codex")
config_file = os.path.join(config_dir, "config.toml")
os.makedirs(config_dir, exist_ok=True)
# ── read existing doc (or empty) ──────────────────────────────────