Skip to content

Create SiteLoader #1

Closed
Closed

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

Activity

  1. kjaymiller commented on Feb 19, 2026

    @kjaymiller
    ContributorAuthor

    a few considerations on this.

        def load_site(self) -> Site:
            """Load Site from pyproject.toml configuration."""

    I support this and think that will be the first inclusion for this API

        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."""

    Thinking about this now I don't think we should do anything of the sort but perhaps retrieve and object from the route_list or site_map (which I still think should be one thing)

        def reload_site(self) -> None:
            """Force reload Site from disk."""

    This should probably be a command that is accessible but not from the SiteLoader (or at least not like this)...

    Basically I'm thinking make site loader just the def load_site and keep it moving.

  2. linked a pull request that will close this issueadd config load and site #12on Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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