mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
Module moves (with imports, paths, argv literals, scripts, docs, and
parents[N] formulas updated in lockstep):
- cli/deploy -> cli/administration/deploy
- cli/validate/inventory -> cli/administration/inventory/validate
- cli/vault -> cli/administration/secrets/vault
- cli/administration/inventory/encrypt -> cli/administration/secrets/seal
- cli/mirror -> cli/contributing/mirror
The new cli/administration/secrets cluster collocates the whole-file
ansible-vault wrapper next to the inventory-aware per-field sealer.
The user-facing CLI subcommand paths follow the package layout, e.g.
"infinito administration deploy dedicated <inv>" and
"infinito administration inventory validate <inv>".
Help system redesign in cli/core/{discovery,help,app}.py:
- Discovery now distinguishes runnable commands (directories with
__main__.py) from category folders (directories that only group
further commands). Empty support packages are filtered out.
- Each category folder MAY carry a README.md; its H1 heading is used
as the title and its first paragraph as the one-line description in
the help output.
- "infinito" / "infinito --help" prints only the top-level entries
(one level deep). "infinito <category>" navigates into a folder and
shows its sub-folders and commands one level deep, with the README
title as the page heading and the invocation as a dim subtitle.
- New "--tree [N]" flag walks the tree under the (optional) path
prefix recursively. N caps the depth (1-based); omit N for an
unbounded walk. The output uses Unicode tree connectors, an emoji
per entry (folder for categories, gear for commands), a globally
aligned description column, and multi-line wrapped descriptions
with tree-continuity bars on continuation lines.
- Category and command listings use the full invocation
("infinito meta callorder") rather than the bare leaf name, so the
output is copy-pasteable.
Convention doc + 17 CLI READMEs:
- New docs/contributing/artefact/files/cli/readme_md.md describes the
H1+paragraph layout the help system reads, and how it differs from
role/docs READMEs.
- README.md added for cli/{administration, build, contributing, meta}
and their immediate sub-folders, plus cli/meta/roles/applications
and its resolution sub-folder. Each follows the "title with trailing
emoji + single descriptive paragraph" convention.
Mirror resolver/sync description strings (the help system reads them
from argparse --help output) added so they no longer surface as
"options:" in the global index. cli/mirror/cleanup already had a
description and is unchanged.
Fixes uncovered by the move:
- import unittest.mock added to four dedicated-deploy tests so
unittest.mock.patch resolves under stdlib unittest discovery
(Python 3.13 no longer surfaces unittest.mock through "import
unittest" alone).
- parents[N] index in the new
cli/administration/inventory/validate/__init__.py corrected from
3 to 4 to match the deeper layout.
- test_paths.INVENTORY_VALIDATOR_PATH assertion and test_runner
substring assertions updated to match the new validator path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
107 lines
3.6 KiB
Python
107 lines
3.6 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import TYPE_CHECKING
|
|
|
|
from . import PROJECT_ROOT
|
|
from .deps import apps_with_deps, resolve_run_after
|
|
|
|
if TYPE_CHECKING:
|
|
from .compose import Compose
|
|
|
|
|
|
# Mirrors INVENTORY_VARS_FILE from scripts/meta/env/inventory.sh; a unit
|
|
# test locks the two literals together so they cannot drift.
|
|
DEV_INVENTORY_VARS_FILE: str = os.environ.get(
|
|
"INVENTORY_VARS_FILE", "inventories/development/default.yml"
|
|
)
|
|
|
|
|
|
VALID_DISTROS: tuple[str, ...] = ("arch", "debian", "ubuntu", "fedora", "centos")
|
|
|
|
|
|
def compose_file_args() -> list[str]:
|
|
"""Compose `-f` flags shared by up and down flows."""
|
|
from .profile import Profile
|
|
|
|
out = ["-f", "compose.yml"]
|
|
if Profile().registry_cache_active():
|
|
out += ["-f", "compose/cache.override.yml"]
|
|
return out
|
|
|
|
|
|
def cache_env_overrides() -> dict[str, str]:
|
|
"""Env vars consumed strictly by compose/cache.override.yml."""
|
|
from .profile import Profile
|
|
|
|
if not Profile().registry_cache_active():
|
|
return {}
|
|
|
|
ca_dir = os.environ.get("INFINITO_PACKAGE_CACHE_FRONTEND_CA_DIR", "").strip()
|
|
if not ca_dir:
|
|
raise SystemExit(
|
|
"INFINITO_PACKAGE_CACHE_FRONTEND_CA_DIR is not set. Source "
|
|
"scripts/meta/env/cache/package.sh (or scripts/meta/env/all.sh) "
|
|
"before invoking cli.administration.deploy.development."
|
|
)
|
|
return {
|
|
"INFINITO_REGISTRY_CACHE_PROXY_CONF": "./compose/registry-cache/proxy.conf",
|
|
"INFINITO_PACKAGE_CACHE_PIP_CONF": "./compose/package-cache/pip.conf",
|
|
"INFINITO_PACKAGE_CACHE_NPMRC": "./compose/package-cache/npmrc",
|
|
"INFINITO_PACKAGE_CACHE_APT_LIST": "./compose/package-cache/apt.list",
|
|
"INFINITO_PACKAGE_CACHE_FRONTEND_CA_FILE": f"{ca_dir}/ca.crt",
|
|
}
|
|
|
|
|
|
def resolve_distro() -> str:
|
|
"""Return INFINITO_DISTRO; raise SystemExit if missing or invalid."""
|
|
distro = os.environ.get("INFINITO_DISTRO", "").strip()
|
|
if not distro:
|
|
raise SystemExit(
|
|
"INFINITO_DISTRO is not set. Source scripts/meta/env/defaults.sh "
|
|
"or export INFINITO_DISTRO=<arch|debian|ubuntu|fedora|centos> "
|
|
"before invoking cli.administration.deploy.development."
|
|
)
|
|
if distro not in VALID_DISTROS:
|
|
raise SystemExit(
|
|
f"INFINITO_DISTRO={distro!r} is not a valid distro. "
|
|
f"Valid: {', '.join(VALID_DISTROS)}."
|
|
)
|
|
return distro
|
|
|
|
|
|
def resolve_container() -> str:
|
|
"""Return INFINITO_CONTAINER; raise SystemExit if unset."""
|
|
container = os.environ.get("INFINITO_CONTAINER", "").strip()
|
|
if not container:
|
|
raise SystemExit(
|
|
"INFINITO_CONTAINER is not set. Source scripts/meta/env/defaults.sh "
|
|
"before invoking cli.administration.deploy.development."
|
|
)
|
|
return container
|
|
|
|
|
|
def make_compose() -> Compose:
|
|
from .compose import Compose
|
|
|
|
distro = resolve_distro()
|
|
# Surface env-script gap here rather than as a cryptic compose error later.
|
|
resolve_container()
|
|
return Compose(repo_root=PROJECT_ROOT, distro=distro)
|
|
|
|
|
|
def resolve_deploy_ids_for_app(compose: Compose, app_id: str) -> list[str]:
|
|
deps = resolve_run_after(compose, app_id)
|
|
return apps_with_deps(app_id, deps_role_names=deps)
|
|
|
|
|
|
def resolve_deploy_ids_for_apps(compose: Compose, app_spec: str) -> list[str]:
|
|
"""Resolve deploy ids for one or more space- or comma-separated app ids."""
|
|
app_ids = [a.strip() for a in app_spec.replace(",", " ").split() if a.strip()]
|
|
result: list[str] = []
|
|
for app_id in app_ids:
|
|
for dep in resolve_deploy_ids_for_app(compose, app_id):
|
|
if dep not in result:
|
|
result.append(dep)
|
|
return result
|