Skip to content

config

config

Configuration management for journal_lib.

This module provides centralized configuration management for the journal_lib package, allowing users to customize behavior through environment variables while providing sensible defaults. All configuration is handled through the JournalConfig class, which supports customization of paths, repositories, GitHub organizations, and user settings.

Example usage

from journal_lib.config import config

Access configured values

notes_path = config.notes_dir repo = config.default_repo orgs = config.github_orgs

Environment variables

JOURNAL_NOTES_DIR: Directory containing daily notes (default: ~/notes) JOURNAL_DEFAULT_REPO: Default GitHub repository in owner/repo format JOURNAL_GITHUB_ORGS: Comma-separated list of GitHub organizations to search JOURNAL_GITHUB_USER: GitHub username or '@me' for authenticated user

JournalConfig dataclass

JournalConfig(
    notes_dir: Path = (
        lambda: Path(
            getenv(
                "JOURNAL_NOTES_DIR", str(home() / "notes")
            )
        )
    )(),
    default_repo: str = (
        lambda: getenv("JOURNAL_DEFAULT_REPO", "")
    )(),
    github_orgs: list[str] = (lambda: split(","))(),
    github_user: str = (
        lambda: getenv("JOURNAL_GITHUB_USER", "@me")
    )(),
)

Configuration class for journal_lib package.

This class manages all configuration options through environment variables with sensible defaults, making the library portable across different environments and users.

__post_init__

__post_init__()

Validate configuration after initialization.

Source code in packages/journal-lib/src/journal_lib/config.py
def __post_init__(self):
    """Validate configuration after initialization."""
    # Ensure notes_dir is a Path object
    if isinstance(self.notes_dir, str):
        self.notes_dir = Path(self.notes_dir)

    # Clean up org list (remove empty strings and whitespace)
    self.github_orgs = [org.strip() for org in self.github_orgs if org.strip()]

    # If no default_repo is set, try to detect it from current directory
    if not self.default_repo:
        self.default_repo = self._detect_default_repo()

get_daily_note_path

get_daily_note_path(date: str | None = None) -> Path

Get file system path to daily note file for specified date.

Parameters:

Name Type Description Default
date str | None

Date in YYYY-MM-DD format, defaults to today if None

None

Returns:

Type Description
Path

Path object pointing to daily note file

Source code in packages/journal-lib/src/journal_lib/config.py
def get_daily_note_path(self, date: str | None = None) -> Path:
    """Get file system path to daily note file for specified date.

    Args:
        date: Date in YYYY-MM-DD format, defaults to today if None

    Returns:
        Path object pointing to daily note file
    """
    import re
    from datetime import datetime

    if date is None:
        date = datetime.now().strftime("%Y-%m-%d")

    # Security: Validate date format to prevent path traversal
    if not re.match(r"^\d{4}-\d{2}-\d{2}$", date):
        raise ValueError("Invalid date format. Expected YYYY-MM-DD")

    # Additional validation of date value
    try:
        datetime.strptime(date, "%Y-%m-%d")
    except ValueError as e:
        raise ValueError("Invalid date value") from e

    return self.notes_dir / "daily" / f"{date}.md"