Skip to content

Commit 904c5db

Browse files
authored
Merge pull request #144 from meta-pytorch/openenv_cli
2 parents fca4d4a + a75da3f commit 904c5db

File tree

22 files changed

+2488
-3
lines changed

22 files changed

+2488
-3
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ OpenEnv provides a standard for interacting with agentic execution environments
2323

2424
In addition to making it easier for researchers and RL framework writers, we also provide tools for environment creators making it easier for them to create richer environments and make them available over familar protocols like HTTP and packaged using canonical technologies like docker. Environment creators can use the OpenEnv framework to create environments that are isolated, secure, and easy to deploy and use.
2525

26+
The OpenEnv CLI (`openenv`) provides commands to initialize new environments and deploy them to Hugging Face Spaces.
27+
2628
> ⚠️ **Early Development Warning** OpenEnv is currently in an experimental
2729
> stage. You should expect bugs, incomplete features, and APIs that may change
2830
> in future versions. The project welcomes bugfixes, but to make sure things are
@@ -117,14 +119,21 @@ Type-safe data structures:
117119

118120
### For Environment Creators
119121

120-
When building a new environment, create the following structure:
122+
Use the CLI to quickly scaffold a new environment:
123+
124+
```bash
125+
openenv init my_env
126+
```
127+
128+
This creates the following structure:
121129

122130
```
123-
src/envs/your_env/
131+
my_env/
124132
├── __init__.py # Export YourAction, YourObservation, YourEnv
125133
├── models.py # Define Action, Observation, State dataclasses
126134
├── client.py # Implement YourEnv(HTTPEnvClient)
127135
├── README.md # Document your environment
136+
├── openenv.yaml # Environment manifest
128137
└── server/
129138
├── your_environment.py # Implement YourEnvironment(Environment)
130139
├── app.py # Create FastAPI app
@@ -143,6 +152,26 @@ To use an environment:
143152

144153
See example scripts in `examples/` directory.
145154

155+
## CLI Commands
156+
157+
The OpenEnv CLI provides commands to manage environments:
158+
159+
- **`openenv init <env_name>`** - Initialize a new environment from template
160+
- **`openenv push [--repo-id <repo>] [--private]`** - Deploy environment to Hugging Face Spaces
161+
162+
### Quick Start
163+
164+
```bash
165+
# Create a new environment
166+
openenv init my_game_env
167+
168+
# Deploy to Hugging Face (will prompt for login if needed)
169+
cd my_game_env
170+
openenv push
171+
```
172+
173+
For detailed options: `openenv init --help` and `openenv push --help`.
174+
146175
## Design Principles
147176

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

pyproject.toml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,35 @@ dependencies = [
1212
"requests>=2.25.0",
1313
"fastapi>=0.104.0",
1414
"uvicorn>=0.24.0",
15-
"smolagents>=1.22.0,<2"
15+
"smolagents>=1.22.0,<2",
16+
"typer>=0.9.0",
17+
"rich>=13.0.0",
18+
"pyyaml>=6.0",
19+
"huggingface_hub>=0.20.0"
1620
]
1721

22+
[project.scripts]
23+
openenv = "openenv_cli.__main__:main"
24+
1825
[tool.setuptools]
1926
package-dir = {"" = "src"}
2027

2128
[tool.setuptools.packages.find]
2229
where = ["src"]
30+
31+
[tool.coverage.run]
32+
omit = [
33+
"openenv_cli/templates/**",
34+
"**/templates/**",
35+
"openenv_cli/__main__.py",
36+
]
37+
38+
[tool.coverage.report]
39+
exclude_lines = [
40+
"pragma: no cover",
41+
"def __repr__",
42+
"raise AssertionError",
43+
"raise NotImplementedError",
44+
"if __name__ == .__main__.:",
45+
"if TYPE_CHECKING:",
46+
]

src/openenv_cli/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
"""OpenEnv CLI package."""
8+
9+
__version__ = "0.1.0"
10+

src/openenv_cli/__main__.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
"""
8+
OpenEnv CLI entry point.
9+
10+
This module provides the main entry point for the OpenEnv command-line interface,
11+
following the Hugging Face CLI pattern.
12+
"""
13+
14+
import sys
15+
16+
import typer
17+
18+
from openenv_cli.commands import init
19+
from openenv_cli.commands import push
20+
21+
# Create the main CLI app
22+
app = typer.Typer(
23+
name="openenv",
24+
help="OpenEnv - An e2e framework for creating, deploying and using isolated execution environments for agentic RL training",
25+
no_args_is_help=True,
26+
)
27+
28+
# Register commands
29+
app.command(name="init", help="Initialize a new OpenEnv environment")(init.init)
30+
app.command(name="push", help="Push an OpenEnv environment to Hugging Face Spaces")(push.push)
31+
32+
33+
# Entry point for setuptools
34+
def main() -> None:
35+
"""Main entry point for the CLI."""
36+
try:
37+
app()
38+
except KeyboardInterrupt:
39+
print("\nOperation cancelled by user.")
40+
sys.exit(130)
41+
except Exception as e:
42+
print(f"Error: {e}", file=sys.stderr)
43+
sys.exit(1)
44+
45+
46+
if __name__ == "__main__":
47+
main()

src/openenv_cli/_cli_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
"""CLI utilities for OpenEnv command-line interface."""
8+
9+
from rich.console import Console
10+
11+
# Create a console instance for CLI output
12+
console = Console()
13+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
"""OpenEnv CLI commands."""
8+
9+
from openenv_cli.commands import init, push
10+
11+
__all__ = ["init", "push"]
12+

0 commit comments

Comments
 (0)