()
| 21 | |
| 22 | |
| 23 | def _resolve_project_root() -> Path: |
| 24 | # Optional explicit override for environments running from installed packages. |
| 25 | env_root = os.getenv("CACTUS_PROJECT_ROOT", "").strip() |
| 26 | if env_root: |
| 27 | candidate = Path(env_root).expanduser().resolve() |
| 28 | if _looks_like_project_root(candidate): |
| 29 | return candidate |
| 30 | |
| 31 | # Prefer the repo containing this CLI module. |
| 32 | module_root = SCRIPT_DIR.parent.parent |
| 33 | if _looks_like_project_root(module_root): |
| 34 | return module_root |
| 35 | |
| 36 | # Fallback: repo containing current working directory. |
| 37 | cwd = Path.cwd().resolve() |
| 38 | for candidate in [cwd, *cwd.parents]: |
| 39 | if _looks_like_project_root(candidate): |
| 40 | return candidate |
| 41 | |
| 42 | # Final fallback for unusual layouts. |
| 43 | return module_root |
| 44 | |
| 45 | |
| 46 | PROJECT_ROOT = _resolve_project_root() |
no test coverage detected