Skip to content

Commit e2b20e2

Browse files
committed
Add push command to OpenEnv CLI for deploying environments to Hugging Face Spaces
- Introduced `openenv push` command to validate and upload OpenEnv environments. - Updated `README.md` and template files to include deployment instructions. - Enhanced `pyproject.toml` with new dependencies: `pyyaml` and `huggingface_hub`. - Modified import statements to support the new command structure. - Added tests for the `push` command to ensure functionality and validation.
1 parent d0fb4a2 commit e2b20e2

File tree

10 files changed

+896
-9
lines changed

10 files changed

+896
-9
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,66 @@ To use an environment:
143143

144144
See example scripts in `examples/` directory.
145145

146+
## CLI Commands
147+
148+
OpenEnv provides a command-line interface for managing environments:
149+
150+
### `openenv init`
151+
152+
Initialize a new OpenEnv environment:
153+
154+
```bash
155+
openenv init my_game_env
156+
openenv init my_env --output-dir /path/to/projects
157+
```
158+
159+
Creates a new directory with all necessary files based on the OpenEnv template.
160+
161+
### `openenv push`
162+
163+
Push an OpenEnv environment to Hugging Face Spaces:
164+
165+
```bash
166+
# From the environment directory (where openenv.yaml is located)
167+
openenv push
168+
169+
# With options
170+
openenv push --repo-id my-org/my-env --private
171+
openenv push --base-image ghcr.io/meta-pytorch/openenv-base:latest
172+
```
173+
174+
The `openenv push` command:
175+
1. Validates that the directory is an OpenEnv environment (checks for `openenv.yaml`)
176+
2. Prepares a custom build for Hugging Face Docker space (enables web interface)
177+
3. Uploads to Hugging Face (ensuring you're logged in)
178+
179+
**Prerequisites:**
180+
- Authenticate with Hugging Face: Set `HF_TOKEN` environment variable or the command will prompt for login
181+
182+
**Options:**
183+
- `--directory`, `-d`: Directory containing the OpenEnv environment (defaults to current directory)
184+
- `--repo-id`, `-r`: Repository ID in format 'username/repo-name' (defaults to 'username/env-name' from openenv.yaml)
185+
- `--base-image`, `-b`: Base Docker image to use (overrides Dockerfile FROM)
186+
- `--private`: Deploy the space as private (default: public)
187+
188+
After deployment, your space will be available at:
189+
`https://huggingface.co/spaces/<repo-id>`
190+
191+
The deployed space includes:
192+
- **Web Interface** at `/web` - Interactive UI for exploring the environment
193+
- **API Documentation** at `/docs` - Full OpenAPI/Swagger interface
194+
- **Health Check** at `/health` - Container health monitoring
195+
196+
### `openenv convert`
197+
198+
Convert an existing environment to OpenEnv format:
199+
200+
```bash
201+
openenv convert --env-path /path/to/env
202+
```
203+
204+
See the [convert command documentation](src/openenv_cli/commands/convert.py) for more details.
205+
146206
## Design Principles
147207

148208
1. **Separation of Concerns**: Clear client-server boundaries

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ dependencies = [
1414
"uvicorn>=0.24.0",
1515
"smolagents>=1.22.0,<2",
1616
"typer>=0.9.0",
17-
"rich>=13.0.0"
17+
"rich>=13.0.0",
18+
"pyyaml>=6.0",
19+
"huggingface_hub>=0.20.0"
1820
]
1921

2022
[project.scripts]

src/openenv_cli/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from openenv_cli.commands import convert
1919
from openenv_cli.commands import init
20+
from openenv_cli.commands import push
2021

2122
# Create the main CLI app
2223
app = typer.Typer(
@@ -28,6 +29,7 @@
2829
# Register commands
2930
app.command(name="init", help="Initialize a new OpenEnv environment")(init.init)
3031
app.add_typer(convert.app, name="convert", help="Convert an existing environment to OpenEnv format")
32+
app.command(name="push", help="Push an OpenEnv environment to Hugging Face Spaces")(push.push)
3133

3234

3335
# 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,7 +6,7 @@
66

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

9-
from openenv_cli.commands import convert, init
9+
from openenv_cli.commands import convert, init, push
1010

11-
__all__ = ["convert", "init"]
11+
__all__ = ["convert", "init", "push"]
1212

0 commit comments

Comments
 (0)