tlcconfig.logic¶

Configuration transformation and validation logic.

This module centralizes all business logic for configuration values:

  • Path expansion (environment variables, ~, anchored paths)

  • Type coercion

  • Validation

By keeping logic here, the schema remains pure metadata and the loader stays dumb.

.. rubric:: Example

from tlcconfig.logic import ConfigLogic
from tlcconfig.config_source import ConfigSource

# Expand a path
expanded = ConfigLogic.expand_path(
    "~/projects",
    ConfigSource.USER_CONFIG_FILE,
    "/path/to/config.yaml"
)

# Validate a port
if ConfigLogic.is_valid_port(8080):
    print("Port is valid")

Module Contents¶

Classes¶

Class

Description

ConfigLogic

Centralized configuration transformation and validation logic.

Data¶

Data

Description

logger

API¶

class ConfigLogic¶

Centralized configuration transformation and validation logic.

All business rules for configuration values live here. This keeps the schema pure metadata and the loader dumb.

static expand_path(
raw: str | None,
source: ConfigSource,
source_info: str | None,
absolutize: bool = True,
) str¶

Expand environment variables, ~, and anchored paths.

Parameters:
  • raw – The raw path string.

  • source – Where the value came from (for anchored path resolution).

  • source_info – Source context (config file path for anchoring).

  • absolutize – Whether to convert relative paths to absolute.

Returns:

The expanded path string.

static is_valid_display_progress(
value: bool,
) bool¶

Validate display progress value.

Parameters:

value – The display progress value.

Returns:

True if value is a boolean.

static is_valid_log_level(
level: str,
) bool¶

Validate that a log level is valid.

Parameters:

level – The log level string.

Returns:

True if level is a valid Python log level.

static is_valid_port(
port: int,
) bool¶

Validate that a port number is valid.

Parameters:

port – The port number.

Returns:

True if port is in valid range (1-65535).

static is_writable_directory(
path: str,
) bool¶

Validate that a path is a writable directory.

Creates the directory if it doesn’t exist.

Parameters:

path – The path to validate.

Returns:

True if the path is writable.

static is_writable_file(
path: str,
) bool¶

Validate that a file path is writable.

Creates parent directory if it doesn’t exist.

Parameters:

path – The file path to validate.

Returns:

True if the file path is writable.

static transform_aliases(
raw: dict[str, Any] | None,
source: ConfigSource,
source_info: str | None,
) dict[str, str]¶

Expand paths in alias values.

Parameters:
  • raw – The raw aliases dict.

  • source – Where the value came from.

  • source_info – Source context for path expansion.

Returns:

Dict with expanded paths as values.

static transform_root_url(
raw: Any,
source: ConfigSource,
source_info: str | None,
) Any¶

Transform root URL to a Url object.

Parameters:
  • raw – The raw root URL (string, Url, or None).

  • source – Where the value came from.

  • source_info – Source context for path expansion.

Returns:

A Url object wrapping the expanded path.

Raises:

TypeError – If raw is not a string, Url, or None.

static transform_scan_urls(
raw: str | list | None,
source: ConfigSource,
source_info: str | None,
) list[dict]¶

Normalize scan URLs to a list of dicts.

Every entry is returned in dict form so downstream consumers see a single shape. Plain-string entries are wrapped as {"url": <expanded>, "layout": "project"}; dict entries pass through with the url field path-expanded and layout defaulted to "project" if unset.

Handles input formats:

  • String: “url1,url2” -> [{“url”: “url1”, …}, {“url”: “url2”, …}]

  • List of strings: [“url1”, …] -> [{“url”: “url1”, …}, …]

  • List of dicts: [{“url”: “…”, “layout”: “flat”}] -> passed through (path-expanded)

Parameters:
  • raw – The raw scan URLs value.

  • source – Where the value came from.

  • source_info – Source context for path expansion.

Returns:

List of dicts. Each dict has at least a url key and a layout key.

logger = getLogger(...)¶