openenv/coding_env
21
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7"""Serve OpenEnv environments locally (TO BE IMPLEMENTED)."""8 9from __future__ import annotations10 11from pathlib import Path12from typing import Annotated13 14import typer15 16from .._cli_utils import console17 18app = typer.Typer(help="Serve OpenEnv environments locally")19 20 21@app.command()22def serve(23 env_path: Annotated[24 str | None,25 typer.Argument(26 help="Path to the environment directory (default: current directory)"27 ),28 ] = None,29 port: Annotated[30 int,31 typer.Option("--port", "-p", help="Port to serve on"),32 ] = 8000,33 host: Annotated[34 str,35 typer.Option("--host", help="Host to bind to"),36 ] = "0.0.0.0",37 reload: Annotated[38 bool,39 typer.Option("--reload", help="Enable auto-reload on code changes"),40 ] = False,41) -> None:42 """43 Serve an OpenEnv environment locally.44 45 TODO: This command is currently not implemented and has been deferred for later.46 47 Planned functionality:48 - Run environment server locally without Docker49 - Support multiple deployment modes (local, notebook, cluster)50 - Auto-reload for development51 - Integration with environment's [project.scripts] entry point52 53 For now, use Docker-based serving:54 1. Build the environment: openenv build55 2. Run the container: docker run -p 8000:8000 <image-name>56 57 Or use uv directly:58 uv run --project . server --port 800059 """60 console.print("[bold yellow]⚠ This command is not yet implemented[/bold yellow]\n")61 62 console.print(63 "The [bold cyan]openenv serve[/bold cyan] command has been deferred for later."64 )65 66 console.print("[bold]Alternative approaches:[/bold]\n")67 68 console.print("[cyan]Option 1: Docker-based serving (recommended)[/cyan]")69 console.print(" 1. Build the environment:")70 console.print(" [dim]$ openenv build[/dim]")71 console.print(" 2. Run the Docker container:")72 console.print(73 f" [dim]$ docker run -p {port}:{port} openenv-<env-name>:latest[/dim]\n"74 )75 76 console.print("[cyan]Option 2: Direct execution with uv[/cyan]")77 78 # Determine environment path79 if env_path is None:80 env_path_obj = Path.cwd()81 else:82 env_path_obj = Path(env_path)83 84 # Check for openenv.yaml85 openenv_yaml = env_path_obj / "openenv.yaml"86 if openenv_yaml.exists():87 console.print(" From your environment directory:")88 console.print(f" [dim]$ cd {env_path_obj}[/dim]")89 console.print(f" [dim]$ uv run --project . server --port {port}[/dim]\n")90 else:91 console.print(" From an environment directory with pyproject.toml:")92 console.print(f" [dim]$ uv run --project . server --port {port}[/dim]\n")93 94 raise typer.Exit(0)95 