-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Issue: Consolidate Site Loading Logic into API
Summary
Both the CLI and TUI implement their own site loading mechanisms. This logic should be consolidated into a shared API module to ensure consistency and reduce duplication.
Current State
CLI Implementation (render_engine_cli.utils)
get_site(import_path: str, site: str, reload: bool)- imports module and returns Sitesplit_module_site(module_site: str)- parses "module:site" format- Loads from dynamically imported Python modules
TUI Implementation (render_engine_tui.site_loader)
SiteLoaderclass with caching- Reads from
pyproject.toml[tool.render-engine.cli]section - Provides
load_site(),get_collections(),get_collection(),reload_site() - More robust error handling with detailed exceptions
Proposed API
Create render_engine_api.site_loader with:
class SiteLoader:
"""Unified site loading for CLI, TUI, and other tools."""
def __init__(self, project_root: Optional[Path] = None):
"""Initialize from project root or cwd."""
def load_site(self) -> Site:
"""Load Site from pyproject.toml configuration."""
def get_collections(self) -> Dict[str, Collection]:
"""Get all Collections from the Site."""
def get_collection(self, slug: str) -> Optional[Collection]:
"""Get a specific Collection by slug."""
def reload_site(self) -> None:
"""Force reload Site from disk."""Benefits
- Single Source of Truth: One implementation for all tools
- Better Error Handling: TUI's implementation has comprehensive error messages
- Caching: Built-in caching reduces redundant imports
- Testing: Easier to test one implementation
- Future Tools: New tools can use the same loader
Migration Path
- Move
SiteLoaderfrom TUI to API package - Add
split_module_site()helper from CLI - Update CLI to use
render_engine_api.site_loader.SiteLoader - Update TUI to import from API instead of local implementation
- Add tests in API package
Dependencies
- Must support both "module:site" string format (CLI) and pyproject.toml reading (TUI)
- Should handle both absolute and relative imports
- Need proper sys.path manipulation for project imports
Related Issues
- configuration management via toml #2: Configuration Management API
- CREATE: Collection Adapter #3: Collection Operations API
Metadata
Metadata
Assignees
Labels
No labels