Classes
BuildContext
dataclass
Shared build context passed across build phases.
This context is created at the start of build() a…
BuildContext
dataclass Shared build context passed across build phases.
This context is created at the start of build() and passed to all phase* methods. It replaces local variables that were scattered throughout the 894-line build() method.
Lifecycle:
1. Created in _setup_build_context() at build start
2. Populated incrementally as phases execute
3. Used by all _phase_* methods for shared state
Categories:
- Core: site, stats, profile (required)
- Cache: cache, tracker (initialized in Phase 0)
- Build mode: incremental, verbose, quiet, strict, parallel
- Work items: pages_to_build, assets_to_process (determined in Phase 2)
- Incremental state: affected_tags, affected_sections, changed_page_paths
- Output: cli, progress_manager, reporter
Attributes
| Name | Type | Description |
|---|---|---|
site |
Site | None |
|
stats |
BuildStats | None |
|
profile |
BuildProfile | None |
|
cache |
BuildCache | None |
|
tracker |
DependencyTracker | None |
|
incremental |
bool |
|
verbose |
bool |
|
quiet |
bool |
|
strict |
bool |
|
parallel |
bool |
|
memory_optimized |
bool |
|
full_output |
bool |
|
profile_templates |
bool |
|
pages |
list[Page] | None |
|
pages_to_build |
list[Page] | None |
|
assets |
list[Asset] | None |
|
assets_to_process |
list[Asset] | None |
|
affected_tags |
set[str] |
|
affected_sections |
set[str] | None |
|
changed_page_paths |
set[Path] |
|
config_changed |
bool |
|
cli |
CLIOutput | None |
|
progress_manager |
LiveProgressManager | None |
|
reporter |
ProgressReporter | None |
|
build_start |
float |
|
_knowledge_graph |
Any |
|
_knowledge_graph_enabled |
bool |
|
_page_contents |
dict[str, str] |
|
_content_cache_lock |
Lock |
|
_accumulated_page_json |
list[tuple[Any, dict[str, Any]]] |
|
_accumulated_json_lock |
Lock |
Methods 12
knowledge_graph
property
Get knowledge graph (built lazily, cached for build duration).
The knowledge g…
knowledge_graph
property def knowledge_graph(self) -> KnowledgeGraph | None
Get knowledge graph (built lazily, cached for build duration).
The knowledge graph is expensive to build (~200-500ms for 773 pages). By caching it here, we avoid rebuilding it 3 times per build (post-processing, special pages, health check).
Returns
Built KnowledgeGraph instance, or None if disabled/unavailableKnowledgeGraph | None
—
content_cache_size
property
Get number of cached content entries.
content_cache_size
property def content_cache_size(self) -> int
Get number of cached content entries.
Returns
Number of files with cached contentint
—
has_cached_content
property
Check if content cache has any entries.
Validators can use this to decide whet…
has_cached_content
property def has_cached_content(self) -> bool
Check if content cache has any entries.
Validators can use this to decide whether to use cache or fallback.
Returns
True if cache has contentbool
—
has_accumulated_json
property
Check if accumulated JSON data exists.
Post-processing can use this to decide …
has_accumulated_json
property def has_accumulated_json(self) -> bool
Check if accumulated JSON data exists.
Post-processing can use this to decide whether to use accumulated data or fall back to computing from pages.
Returns
True if accumulated JSON data existsbool
—
clear_lazy_artifacts
Clear lazy-computed artifacts to free memory.
Call this at the end of a build …
clear_lazy_artifacts
def clear_lazy_artifacts(self) -> None
Clear lazy-computed artifacts to free memory.
Call this at the end of a build to release memory used by cached artifacts like the knowledge graph and content cache.
cache_content
Cache raw content during discovery phase (thread-safe).
Call this during conte…
cache_content
def cache_content(self, source_path: Path, content: str) -> None
Cache raw content during discovery phase (thread-safe).
Call this during content discovery to store file content for later use by validators. This eliminates redundant disk I/O during health checks.
Parameters 2
source_path |
Path |
Path to source file (used as cache key) |
content |
str |
Raw file content to cache |
get_content
Get cached content without disk I/O.
get_content
def get_content(self, source_path: Path) -> str | None
Get cached content without disk I/O.
Parameters 1
source_path |
Path |
Path to source file |
Returns
Cached content string, or None if not cachedstr | None
—
get_all_cached_contents
Get a copy of all cached contents for batch processing.
Returns a copy to avoi…
get_all_cached_contents
def get_all_cached_contents(self) -> dict[str, str]
Get a copy of all cached contents for batch processing.
Returns a copy to avoid thread safety issues when iterating.
Returns
Dictionary mapping source path strings to contentdict[str, str]
—
clear_content_cache
Clear content cache to free memory.
Call this after validation phase completes…
clear_content_cache
def clear_content_cache(self) -> None
Clear content cache to free memory.
Call this after validation phase completes to release memory used by cached file contents.
accumulate_page_json
Accumulate JSON data for a page during rendering (thread-safe).
Call this duri…
accumulate_page_json
def accumulate_page_json(self, json_path: Any, page_data: dict[str, Any]) -> None
Accumulate JSON data for a page during rendering (thread-safe).
Call this during rendering phase to store JSON data for later use in post-processing. This eliminates redundant computation and double iteration of pages.
Parameters 2
json_path |
Any |
Path where JSON file should be written |
page_data |
dict[str, Any] |
Pre-computed JSON data dictionary |
get_accumulated_json
Get all accumulated JSON data for post-processing.
Returns a copy to avoid thr…
get_accumulated_json
def get_accumulated_json(self) -> list[tuple[Any, dict[str, Any]]]
Get all accumulated JSON data for post-processing.
Returns a copy to avoid thread safety issues when iterating.
Returns
List of (json_path, page_data) tupleslist[tuple[Any, dict[str, Any]]]
—
clear_accumulated_json
Clear accumulated JSON data to free memory.
Call this after post-processing ph…
clear_accumulated_json
def clear_accumulated_json(self) -> None
Clear accumulated JSON data to free memory.
Call this after post-processing phase completes to release memory used by accumulated JSON data.
Internal Methods 1
_build_knowledge_graph
Build and cache knowledge graph.
_build_knowledge_graph
def _build_knowledge_graph(self) -> KnowledgeGraph | None
Build and cache knowledge graph.
Returns
Built KnowledgeGraph instance, or None if disabled/unavailableKnowledgeGraph | None
—