Files
computer-playbook/cli/__main__.py
T
kevinveenbirkenbachandClaude Opus 4.7 ddd2fee129 fix(cli): auto-load .env in the infinito CLI entry-point
Direct `infinito <subcmd>` calls from an interactive shell skipped the
bash env loader (`scripts/meta/env/load.sh`) and crashed on any module
that strict-reads an INFINITO_* key without a Python-side default —
the trigger was `infinito contributing update repository` raising
`KeyError: 'INFINITO_WORKER_FETCH'` from `resolve_max_fetch_workers`,
which only exists in `.env` because it is computed dynamically by
`make dotenv` (INFINITO_WORKER_CPU * 20).

Adds `utils.env.loader.load_dotenv_once()`: walks up from a start
path until it finds `.env`, parses it via the existing
`parse_static_env`, and injects each key with `os.environ.setdefault`.
Idempotent via `INFINITO_ENV_LOADED=1` to mirror the bash loader so
make-dispatched calls (which already set the flag) skip the work.

`cli/__main__.py` calls it once right after the sys.path bootstrap and
before importing `cli.core.app`, so every subcommand and transitive
import sees the defaults. Caller-set env vars still win — only
unset keys are filled.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 14:55:10 +02:00

28 lines
977 B
Python
Executable File

#!/usr/bin/env python3
from __future__ import annotations
import sys
from pathlib import Path
# This file is invoked directly as a script (the ``cli`` console-script
# entry-point and the integration help-test), in which case
# ``from . import PROJECT_ROOT`` fails with ``attempted relative import
# with no known parent package``. Compute the repo root
# locally and prepend it to sys.path before any project-package import
# resolves. Without this, sys.path[0] points to ``<root>/cli`` and
# importing ``cli.*`` may accidentally resolve to an installed package
# from site-packages.
# nocheck: project-root-import sys.path bootstrap before package imports resolve
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from utils.env.loader import load_dotenv_once # noqa: E402
load_dotenv_once(PROJECT_ROOT)
from cli.core.app import main # noqa: E402
if __name__ == "__main__":
main()