Files
computer-playbook/cli/meta/runtime/__init__.py
T
kevinveenbirkenbachandClaude Opus 4.7 553d51fb4c fix(cli): define PROJECT_ROOT in cli.meta.runtime to break circular self-import
The earlier project-root-import refactor (9f62f9bb0) replaced the local
get_project_root() helper with `from . import PROJECT_ROOT`, but the
constant was never actually defined in cli/meta/runtime/__init__.py —
the import resolved against the package being initialized, producing a
circular ImportError at runtime that broke `make up` in CI.

Define PROJECT_ROOT directly via `Path(__file__).resolve().parents[3]`,
matching the pattern used in sibling packages (e.g. cli/build/tree).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-07 22:28:30 +02:00

50 lines
1.2 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
PROJECT_ROOT: Path = Path(__file__).resolve().parents[3]
def detect_runtime(project_root: Path | None = None) -> str:
"""
Detect the current execution runtime.
Returns one of:
- "act" : local GitHub Actions emulation (act)
- "github" : real GitHub Actions runner
- "dev" : local development compose stack
- "host" : native host execution (default)
Precedence:
1) RUNTIME (explicit override)
2) act (must come before github because act sets GITHUB_ACTIONS=true)
3) github
4) dev (marker relative to project root)
5) host
"""
# 1) explicit override wins
v = (os.getenv("RUNTIME") or "").strip()
if v:
return v
# 2) act (must be before GitHub)
if os.getenv("ACT") == "true" or os.getenv("ACT_RUNNER"):
return "act"
# 3) GitHub Actions
if (
os.getenv("GITHUB_ACTIONS") == "true"
or os.getenv("RUNNING_ON_GITHUB") == "true"
):
return "github"
# 4) local dev compose stack (project-root relative marker)
root = project_root or PROJECT_ROOT
if (root / "env.development").exists():
return "dev"
# 5) default
return "host"