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.

clew/guardconfig.py:59

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
lines 68–73from .guard.config import ( CONFIG_FILE_NAME, load_config, read_guard_section, read_requirements_section, )lines 74–74from .guard.errors import ConfigErrorlines 76–76path = Path(repo_root).expanduser() / CONFIG_FILE_NAMElines 77–77trylines 80–82declared = path.is_file() and ( read_guard_section(path) is not None or read_requirements_section(path) is not None )lines 83–83config = load_config(path) if declared else {}lines 84–84except ConfigError as exclines 85–85problems = tuple(exc.problems) or (exc.message,)lines 86–92logger.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), )lines 93–93return GuardConfigRead(config={}, path=path, rejected=problems)lines 94–94return GuardConfigRead(config=config, path=path)

Requirements

REQ-DDB-CONFIG-001

usable

bool clew.guardconfig.GuardConfigRead.usable(self)

Whether the read produced a config to declare from.

clew/guardconfig.py:48

Show on the map →

Called by none

Calls none

Source · 5 lines
    def usable(self) -> bool:
        """@brief Whether any config was recovered from the file."""
        return bool(self.config)

Activity · 1 steps
lines 50–50return bool(self.config)

Requirements

REQ-DDB-CONFIG-001