Team Ai
Apppublic

openenv/echo_env

sourceHugging Faceupdated 1d agoView on Hugging Face
6likes
serve.py91 linesDownload Raw Back to commands
1# SPDX-License-Identifier: BSD-3-Clause2 3"""Serve OpenEnv environments locally (TO BE IMPLEMENTED)."""4 5from __future__ import annotations6 7from pathlib import Path8from typing import Annotated9 10import typer11 12from .._cli_utils import console13 14app = typer.Typer(help="Serve OpenEnv environments locally")15 16 17@app.command()18def serve(19    env_path: Annotated[20        str | None,21        typer.Argument(22            help="Path to the environment directory (default: current directory)"23        ),24    ] = None,25    port: Annotated[26        int,27        typer.Option("--port", "-p", help="Port to serve on"),28    ] = 8000,29    host: Annotated[30        str,31        typer.Option("--host", help="Host to bind to"),32    ] = "0.0.0.0",33    reload: Annotated[34        bool,35        typer.Option("--reload", help="Enable auto-reload on code changes"),36    ] = False,37) -> None:38    """39    Serve an OpenEnv environment locally.40 41    TODO: This command is currently not implemented and has been deferred for later.42 43    Planned functionality:44    - Run environment server locally without Docker45    - Support multiple deployment modes (local, notebook, cluster)46    - Auto-reload for development47    - Integration with environment's [project.scripts] entry point48 49    For now, use Docker-based serving:50        1. Build the environment: openenv build51        2. Run the container: docker run -p 8000:8000 <image-name>52 53    Or use uv directly:54        uv run --project . server --port 800055    """56    console.print("[bold yellow]⚠ This command is not yet implemented[/bold yellow]\n")57 58    console.print(59        "The [bold cyan]openenv serve[/bold cyan] command has been deferred for later."60    )61 62    console.print("[bold]Alternative approaches:[/bold]\n")63 64    console.print("[cyan]Option 1: Docker-based serving (recommended)[/cyan]")65    console.print("  1. Build the environment:")66    console.print("     [dim]$ openenv build[/dim]")67    console.print("  2. Run the Docker container:")68    console.print(69        f"     [dim]$ docker run -p {port}:{port} openenv-<env-name>:latest[/dim]\n"70    )71 72    console.print("[cyan]Option 2: Direct execution with uv[/cyan]")73 74    # Determine environment path75    if env_path is None:76        env_path_obj = Path.cwd()77    else:78        env_path_obj = Path(env_path)79 80    # Check for openenv.yaml81    openenv_yaml = env_path_obj / "openenv.yaml"82    if openenv_yaml.exists():83        console.print("  From your environment directory:")84        console.print(f"     [dim]$ cd {env_path_obj}[/dim]")85        console.print(f"     [dim]$ uv run --project . server --port {port}[/dim]\n")86    else:87        console.print("  From an environment directory with pyproject.toml:")88        console.print(f"     [dim]$ uv run --project . server --port {port}[/dim]\n")89 90    raise typer.Exit(1)91