Skip to content

Config

transcript_indexer.config

default_db_path()

Return the OS-appropriate user-level database path.

Source code in src/transcript_indexer/config.py
def default_db_path() -> Path:
    """Return the OS-appropriate user-level database path."""
    return user_data_path(_APP_NAME) / "index.db"

default_config_path()

Return the OS-appropriate user-level config path.

Source code in src/transcript_indexer/config.py
def default_config_path() -> Path:
    """Return the OS-appropriate user-level config path."""
    return user_config_path(_APP_NAME) / "config.toml"

render_default_config_toml()

Return the default config file contents with platform-appropriate paths.

Source code in src/transcript_indexer/config.py
def render_default_config_toml() -> str:
    """Return the default config file contents with platform-appropriate paths."""
    return _DEFAULT_CONFIG_TEMPLATE.format(db_path=default_db_path())

ensure_config_file(path=None, *, force=False)

Create the user-level config file with defaults if it doesn't exist.

Returns (path, created). created is True if a new file was written. With force=True, an existing file is overwritten.

Source code in src/transcript_indexer/config.py
def ensure_config_file(path: Path | None = None, *, force: bool = False) -> tuple[Path, bool]:
    """Create the user-level config file with defaults if it doesn't exist.

    Returns (path, created). `created` is True if a new file was written.
    With `force=True`, an existing file is overwritten.
    """
    target = (path or default_config_path()).expanduser()
    if target.exists() and not force:
        return target, False
    target.parent.mkdir(parents=True, exist_ok=True)
    target.write_text(render_default_config_toml())
    return target, True

load_config(explicit=None)

Load config from --config flag, env var, default user path, or defaults.

If no config file exists at the default user-level path (and the user didn't specify one), seed it with the default template so first-time users have a discoverable file to edit.

Override hierarchy: CLI flag > env var > config file > built-in default.

Source code in src/transcript_indexer/config.py
def load_config(explicit: Path | None = None) -> Config:
    """Load config from --config flag, env var, default user path, or defaults.

    If no config file exists at the default user-level path (and the user
    didn't specify one), seed it with the default template so first-time
    users have a discoverable file to edit.

    Override hierarchy: CLI flag > env var > config file > built-in default.
    """
    path: Path | None = None
    if explicit is not None:
        path = explicit.expanduser()
    else:
        for candidate in _config_search_paths():
            if candidate.is_file():
                path = candidate
                break
        if path is None and "TRANSCRIPT_INDEXER_CONFIG" not in os.environ:
            try:
                path, _ = ensure_config_file()
            except OSError:
                path = None

    if path is None or not path.is_file():
        return Config()

    with path.open("rb") as f:
        data = tomllib.load(f)
    return Config.model_validate(data)