build_tools.pipeline_tui.core.state

Application state management for Pipeline TUI.

This module defines the state dataclasses that track pipeline configuration, job status, and UI state throughout the application lifecycle.

State Hierarchy:

  • PipelineState - Top-level application state - ExtractionConfig - Extractor settings (pyphen/nltk, options) - JobState - Current job execution status - UI state (current screen, last browsed directory, etc.)

Design Principles:

  • Immutable where possible (use dataclass frozen=True for config)

  • Centralized state prevents scattered UI state

  • State changes trigger UI updates via Textual reactivity

Classes

ExtractorType

Available syllable extractor types.

JobStatus

Pipeline job execution status.

ExtractionConfig

Configuration for a syllable extraction job.

JobState

State for a running or completed pipeline job.

PipelineState

Top-level application state for Pipeline TUI.

Module Contents

class build_tools.pipeline_tui.core.state.ExtractorType(*args, **kwds)[source]

Bases: enum.Enum

Available syllable extractor types.

PYPHEN
NLTK
class build_tools.pipeline_tui.core.state.JobStatus(*args, **kwds)[source]

Bases: enum.Enum

Pipeline job execution status.

IDLE
CONFIGURING
RUNNING
COMPLETED
FAILED
CANCELLED
class build_tools.pipeline_tui.core.state.ExtractionConfig[source]

Configuration for a syllable extraction job.

extractor_type

Which extractor to use (pyphen or nltk)

source_path

Source directory path (for browsing and as fallback)

selected_files

List of specific files to process. If empty, uses source_path with file_pattern.

output_dir

Output directory for results

language

Language code for pyphen (e.g., “en_US”, “de_DE”) or “auto” for automatic detection via langdetect

min_syllable_length

Minimum syllable length filter

max_syllable_length

Maximum syllable length filter

file_pattern

Glob pattern for input files (e.g., “*.txt”)

extractor_type: ExtractorType
source_path: pathlib.Path | None = None
selected_files: list[pathlib.Path] = []
output_dir: pathlib.Path | None = None
language: str = 'auto'
min_syllable_length: int = 2
max_syllable_length: int = 8
file_pattern: str = '*.txt'
property has_file_selection: bool

Check if specific files are selected (vs using directory scan).

is_valid()[source]

Check if configuration is valid for execution.

Returns:

Tuple of (is_valid, error_message). Error message is empty if valid.

Return type:

tuple[bool, str]

class build_tools.pipeline_tui.core.state.JobState[source]

State for a running or completed pipeline job.

status

Current job status

config

Configuration used for this job

start_time

When the job started

end_time

When the job ended (if completed/failed/cancelled)

current_stage

Current pipeline stage (extract/normalize/annotate)

progress_percent

Estimated progress (0-100)

log_messages

List of log messages from the job

output_path

Path to output directory (set after job starts)

error_message

Error message if job failed

status: JobStatus
config: ExtractionConfig | None = None
start_time: datetime.datetime | None = None
end_time: datetime.datetime | None = None
current_stage: str = ''
progress_percent: int = 0
log_messages: list[str] = []
output_path: pathlib.Path | None = None
error_message: str = ''
add_log(message)[source]

Add a log message with timestamp.

Parameters:

message (str) – Log message to add

duration_seconds()[source]

Get job duration in seconds.

Returns:

Duration in seconds, or None if job hasn’t started or is still running

Return type:

float | None

class build_tools.pipeline_tui.core.state.PipelineState[source]

Top-level application state for Pipeline TUI.

This dataclass holds all state for the application, including configuration, job status, and UI state.

config

Current extraction configuration

job

Current or most recent job state

last_source_dir

Last browsed source directory (for browser initial path)

last_output_dir

Last browsed output directory

run_normalize

Whether to run normalization after extraction

run_annotate

Whether to run annotation after normalization

config: ExtractionConfig
job: JobState
last_source_dir: pathlib.Path
last_output_dir: pathlib.Path
run_normalize: bool = True
run_annotate: bool = True
reset_job()[source]

Reset job state to idle, preserving configuration.

start_job()[source]

Start a new job with current configuration.

Creates a new JobState with RUNNING status and current timestamp.

complete_job(output_path)[source]

Mark job as completed successfully.

Parameters:

output_path (pathlib.Path) – Path to the output directory

fail_job(error)[source]

Mark job as failed with error message.

Parameters:

error (str) – Error message describing the failure