Option C Tools
Loading...
Searching...
No Matches
octrc Namespace Reference

Functions

tuple[dict, list[str]] load_octrc (Path project_root)
dict load_octrc_safe (Path project_root)

Variables

str OCTRC_FILENAME = ".octrc.json"

Detailed Description

Purpose
-------
OI-519 — single source of truth for ``.octrc.json`` loading. Multiple OCT
modules (linter, formatter, health, typecheck, MCP config) used to each
carry their own ``json.loads`` + ``try/except`` around the same file; that
drift-prone pattern is replaced by :func:`load_octrc` and its silent
convenience wrapper :func:`load_octrc_safe`.

Responsibilities
----------------
- Resolve ``<project_root>/.octrc.json``.
- Tolerate missing file, OSError, invalid JSON, and non-object top-level
  documents — never raise.
- Return a ``(config, errors)`` tuple from :func:`load_octrc` so callers
  that care about strict-mode handling (the linter) can surface messages.
- Return a plain ``dict`` from :func:`load_octrc_safe` for callers that
  only want the data.

Diagnostics
-----------
Domain: OCT-CORE
Levels:
    (No diagnostics emitted; callers decide how to react to errors.)

Contracts
---------
- Both functions accept the project root, not the config path, so behavior
  stays consistent with every other OCT helper.
- ``load_octrc_safe(root)`` is exactly equivalent to
  ``load_octrc(root)[0]``.
- ``load_octrc`` never raises; errors are always returned as strings.

Dependencies
------------
- oct.core.option_c_dir (resolve_octrc path resolver)

Function Documentation

◆ load_octrc()

tuple[dict, list[str]] octrc.load_octrc ( Path project_root)
Load the project's OCT RC config (``.octrc.json`` / ``octrc.json``).

FS-539: prefers ``.option_c/octrc.json`` when present, falls back to
the legacy ``<project_root>/.octrc.json`` otherwise. The concrete
path is resolved via :func:`oct.core.option_c_dir.resolve_octrc`.

Returns
-------
(config, errors) : tuple[dict, list[str]]
    ``config`` is the parsed JSON object, or an empty dict if the file
    is missing / unreadable / malformed / not a JSON object.
    ``errors`` is a list of human-readable error strings; empty when
    the file was absent or loaded successfully.

Definition at line 54 of file octrc.py.

Here is the caller graph for this function:

◆ load_octrc_safe()

dict octrc.load_octrc_safe ( Path project_root)
Load ``.octrc.json`` quietly, returning ``{}`` on any failure.

Definition at line 93 of file octrc.py.

Here is the call graph for this function:

Variable Documentation

◆ OCTRC_FILENAME

str octrc.OCTRC_FILENAME = ".octrc.json"

Definition at line 51 of file octrc.py.