Classes
BuildHandler
File system event handler that triggers site rebuild with debouncing.
Dev reload policy (source-ga…
BuildHandler
File system event handler that triggers site rebuild with debouncing.
Dev reload policy (source-gated):
- Only source edits (markdown/content, config, templates, theme assets) trigger reloads.
- CSS-only source edits send reload-css; any other source edits send full reload.
- We do NOT scan output directories for diffs in dev; this avoids dev-only churn (timestamps, site-wide JSON/TXT) from causing spurious reloads.
Features:
- Debounced rebuilds (0.3s delay to batch changes)
- Incremental builds for speed (5-10x faster)
- Parallel rendering
- Stale object reference prevention (clears ephemeral state)
- Build error recovery (errors don't crash server)
- Automatic cache invalidation for config/template changes
- Handles all file events: create, modify, delete, move/rename
Ignored files:
- Output directory (public/)
- Bengal state directory (.bengal/) - logs, cache, metrics
- Temp files (.tmp, ~, .swp, .swo)
- System files (.DS_Store, .git)
- Python cache (pycache, .pyc)
FileSystemEventHandlerMethods 4
on_created
Handle file creation events.
on_created
def on_created(self, event: FileSystemEvent) -> None
Handle file creation events.
Parameters 1
event |
FileSystemEvent |
File system event |
on_modified
Handle file modification events.
on_modified
def on_modified(self, event: FileSystemEvent) -> None
Handle file modification events.
Parameters 1
event |
FileSystemEvent |
File system event |
on_deleted
Handle file deletion events.
on_deleted
def on_deleted(self, event: FileSystemEvent) -> None
Handle file deletion events.
Parameters 1
event |
FileSystemEvent |
File system event |
on_moved
Handle file move/rename events.
on_moved
def on_moved(self, event: FileSystemEvent) -> None
Handle file move/rename events.
Parameters 1
event |
FileSystemEvent |
File system event with src_path and dest_path |
Internal Methods 6
__init__
Initialize the build handler.
__init__
def __init__(self, site: Any, host: str = 'localhost', port: int = 5173) -> None
Initialize the build handler.
Parameters 3
site |
Any |
Site instance |
host |
str |
Server host |
port |
int |
Server port |
_clear_ephemeral_state
Clear ephemeral state safely via Site API.
_clear_ephemeral_state
def _clear_ephemeral_state(self) -> None
Clear ephemeral state safely via Site API.
_should_regenerate_autodoc
Check if any changed file is in autodoc source directories.
_should_regenerate_autodoc
def _should_regenerate_autodoc(self, changed_paths: set[str]) -> bool
Check if any changed file is in autodoc source directories.
Parameters 1
changed_paths |
set[str] |
Set of changed file paths |
Returns
True if any changed file is a Python file in autodoc source directories,
or an OpenAPI spec filebool
—
_should_ignore_file
Check if file should be ignored (temp files, swap files, etc).
_should_ignore_file
def _should_ignore_file(self, file_path: str) -> bool
Check if file should be ignored (temp files, swap files, etc).
Parameters 1
file_path |
str |
Path to file |
Returns
True if file should be ignoredbool
—
_trigger_build
Execute the actual build (called after debounce delay).
This method:
1. Clears…
_trigger_build
def _trigger_build(self) -> None
Execute the actual build (called after debounce delay).
This method:
- Clears ephemeral state to prevent stale object references
- Runs an incremental + parallel build for speed
- Displays build statistics
- Notifies connected SSE clients to reload
_handle_file_event
Common handler for file system events with debouncing.
Multiple rapid file cha…
_handle_file_event
def _handle_file_event(self, event: FileSystemEvent, event_type: str) -> None
Common handler for file system events with debouncing.
Multiple rapid file changes are batched together and trigger a single rebuild after a short delay (DEBOUNCE_DELAY seconds).
Files in the output directory and matching ignore patterns are skipped to prevent infinite rebuild loops.
Parameters 2
event |
FileSystemEvent |
File system event |
event_type |
str |
Type of event (created, modified, deleted, moved) |