Skip to content

Configuration

load_tripwire_config

load_tripwire_config(start=None)

Walk up from start (default: Path.cwd()) to find pyproject.toml.

Returns the [tool.tripwire] table as a dict, or {} if: - no pyproject.toml found in start or any ancestor directory - pyproject.toml found but has no [tool.tripwire] section

Raises tomllib.TOMLDecodeError if pyproject.toml is malformed. This is intentional: a malformed pyproject.toml is a user error that must not silently produce empty config.

Results are cached per-resolved-search-path (start if provided, else Path.cwd() at call time). The cache survives across calls in the same process; tests that REWRITE an already-observed pyproject.toml mid-session must call load_tripwire_config.cache_clear() in their teardown to bust the cache. Tests that simply chdir between cases get fresh entries because the resolved cwd is the cache key.

Source code in src/tripwire/_config.py
def load_tripwire_config(start: Path | None = None) -> dict[str, Any]:
    """Walk up from start (default: Path.cwd()) to find pyproject.toml.

    Returns the [tool.tripwire] table as a dict, or {} if:
    - no pyproject.toml found in start or any ancestor directory
    - pyproject.toml found but has no [tool.tripwire] section

    Raises tomllib.TOMLDecodeError if pyproject.toml is malformed.
    This is intentional: a malformed pyproject.toml is a user error that
    must not silently produce empty config.

    Results are cached per-resolved-search-path (``start`` if provided,
    else ``Path.cwd()`` at call time). The cache survives across calls
    in the same process; tests that REWRITE an already-observed
    ``pyproject.toml`` mid-session must call
    ``load_tripwire_config.cache_clear()`` in their teardown to bust the
    cache. Tests that simply ``chdir`` between cases get fresh entries
    because the resolved cwd is the cache key.
    """
    search = start if start is not None else Path.cwd()
    return _load_tripwire_config_cached(search)