guardconfig.py¶
clew/guardconfig.py
Read a repo's gate config — the `guard:` section of its `.clew.yaml` — for the INDEX.
read_guard_config
GuardConfigRead clew.guardconfig.read_guard_config(Path|str repo_root)
Read the guard: section of a repo's .clew.yaml , merged over the gate's defaults.
Called by load_guard_config
Calls load_config, read_guard_section, read_requirements_section
Source · 36 lines
def read_guard_config(repo_root: Path | str) -> GuardConfigRead:
"""THE single guard-config load for the index. Both consumers — the `@req` id
pattern / catalog mapping in `requirements.py` and the declaration's view of the
file — go through here, so an invalid section is reported once and cannot be
tolerated by one reader and fatal to the other.
@brief Load a repo's gate config for the index.
@return The read result.
"""
from .guard.config import (
CONFIG_FILE_NAME,
load_config,
read_guard_section,
read_requirements_section,
)
from .guard.errors import ConfigError
path = Path(repo_root).expanduser() / CONFIG_FILE_NAME
try:
## A catalog with no `guard:` section is still a declaration (2.0.0): the top-level
## `requirements:` belongs to the repository, not to the gate.
declared = path.is_file() and (
read_guard_section(path) is not None or read_requirements_section(path) is not None
)
config = load_config(path) if declared else {}
except ConfigError as exc:
problems = tuple(exc.problems) or (exc.message,)
logger.warning(
"guard config: %s is INVALID (%s) — the index continues with built-in defaults "
"for the requirement-tag id pattern and the requirements catalog mapping; "
"run 'clew guard validate' to see the gate refuse it",
path,
"; ".join(problems),
)
return GuardConfigRead(config={}, path=path, rejected=problems)
return GuardConfigRead(config=config, path=path)1 more lines, not shown
Activity · 11 steps
Requirements
usable
bool clew.guardconfig.GuardConfigRead.usable(self)
Whether the read produced a config to declare from.
Source · 5 lines
def usable(self) -> bool:
"""@brief Whether any config was recovered from the file."""
return bool(self.config)