Skip to content

Create SiteLoader #1

@kjaymiller

Description

@kjaymiller

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 Site
  • split_module_site(module_site: str) - parses "module:site" format
  • Loads from dynamically imported Python modules

TUI Implementation (render_engine_tui.site_loader)

  • SiteLoader class 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

  1. Single Source of Truth: One implementation for all tools
  2. Better Error Handling: TUI's implementation has comprehensive error messages
  3. Caching: Built-in caching reduces redundant imports
  4. Testing: Easier to test one implementation
  5. Future Tools: New tools can use the same loader

Migration Path

  1. Move SiteLoader from TUI to API package
  2. Add split_module_site() helper from CLI
  3. Update CLI to use render_engine_api.site_loader.SiteLoader
  4. Update TUI to import from API instead of local implementation
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions