Skip to content

eftoolkit.config

Configuration utilities for JSON loading and logging setup.

Functions

load_json_config

load_json_config

load_json_config(
    path: str | Path, *, strip_comment_keys: bool = False
) -> dict

Load a JSON config file, stripping JSONC-style comments.

Supports: - Standard JSON files - JSONC files with // single-line comments - JSONC files with / / block comments

Parameters:

Name Type Description Default
path str | Path

Path to the JSON/JSONC file

required
strip_comment_keys bool

If True, also remove keys starting with '_comment' from the loaded config using remove_comments(). Default: False.

False

Returns:

Type Description
dict

Parsed JSON as a dictionary

Raises:

Type Description
FileNotFoundError

If the file does not exist

JSONDecodeError

If the content is not valid JSON after stripping comments

Example

Load config with _comment keys stripped

config = load_json_config('config.json', strip_comment_keys=True)

Source code in eftoolkit/config/utils.py
def load_json_config(path: str | Path, *, strip_comment_keys: bool = False) -> dict:
    """Load a JSON config file, stripping JSONC-style comments.

    Supports:
    - Standard JSON files
    - JSONC files with // single-line comments
    - JSONC files with /* */ block comments

    Args:
        path: Path to the JSON/JSONC file
        strip_comment_keys: If True, also remove keys starting with '_comment'
            from the loaded config using remove_comments(). Default: False.

    Returns:
        Parsed JSON as a dictionary

    Raises:
        FileNotFoundError: If the file does not exist
        json.JSONDecodeError: If the content is not valid JSON after stripping comments

    Example:
        >>> # Load config with _comment keys stripped
        >>> config = load_json_config('config.json', strip_comment_keys=True)
    """
    path = Path(path)
    content = path.read_text()
    stripped = _strip_comments(content)
    result = json.loads(stripped)
    if strip_comment_keys:
        result = remove_comments(result)
    return result

setup_logging

setup_logging

setup_logging(
    level: int = INFO,
    format: str | None = None,
    date_format: str | None = None,
) -> None

Configure the root logger with the specified level and format.

Parameters:

Name Type Description Default
level int

Logging level (default: logging.INFO)

INFO
format str | None

Log format string (default: '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

None
date_format str | None

Date/time format string for %(asctime)s (default: None, uses logging module default of '%Y-%m-%d %H:%M:%S,uuu')

None
Source code in eftoolkit/config/utils.py
def setup_logging(
    level: int = logging.INFO,
    format: str | None = None,
    date_format: str | None = None,
) -> None:
    """Configure the root logger with the specified level and format.

    Args:
        level: Logging level (default: logging.INFO)
        format: Log format string (default: '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        date_format: Date/time format string for %(asctime)s (default: None, uses
            logging module default of '%Y-%m-%d %H:%M:%S,uuu')
    """
    if format is None:
        format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'

    logging.basicConfig(
        level=level,
        format=format,
        datefmt=date_format,
        force=True,
    )