Skip to content

Commit bcd9186

Browse files
committed
placeholder implementation for serve command
1 parent 27b4aba commit bcd9186

File tree

3 files changed

+100
-3
lines changed

3 files changed

+100
-3
lines changed

src/openenv_cli/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import typer
1717

18-
from openenv_cli.commands import build, init, push, validate
18+
from openenv_cli.commands import build, init, push, serve, validate
1919

2020
# Create the main CLI app
2121
app = typer.Typer(
@@ -35,6 +35,9 @@
3535
app.command(name="push", help="Push an OpenEnv environment to Hugging Face Spaces or custom registry")(
3636
push.push
3737
)
38+
app.command(name="serve", help="Serve environments locally (TODO: Phase 4)")(
39+
serve.serve
40+
)
3841

3942

4043
# Entry point for setuptools

src/openenv_cli/commands/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
"""OpenEnv CLI commands."""
88

9-
from openenv_cli.commands import build, init, push, validate
9+
from . import build, init, push, serve, validate
1010

11-
__all__ = ["build", "init", "push", "validate"]
11+
__all__ = ["build", "init", "push", "serve", "validate"]

src/openenv_cli/commands/serve.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
"""Serve OpenEnv environments locally (TO BE IMPLEMENTED)."""
8+
9+
from __future__ import annotations
10+
11+
from pathlib import Path
12+
from typing import Annotated
13+
14+
import typer
15+
16+
from .._cli_utils import console
17+
18+
app = typer.Typer(help="Serve OpenEnv environments locally")
19+
20+
21+
@app.command()
22+
def 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 Docker
49+
- Support multiple deployment modes (local, notebook, cluster)
50+
- Auto-reload for development
51+
- Integration with environment's [project.scripts] entry point
52+
53+
For now, use Docker-based serving:
54+
1. Build the environment: openenv build
55+
2. Run the container: docker run -p 8000:8000 <image-name>
56+
57+
Or use uv directly:
58+
uv run --project . server --port 8000
59+
"""
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 path
79+
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.yaml
85+
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)

0 commit comments

Comments
 (0)