Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ dependencies = [
"fastapi>=0.104.0",
"uvicorn>=0.24.0",
"smolagents>=1.22.0,<2",
"huggingface_hub>=0.20.0"
"huggingface_hub>=0.20.0",
"rich>=13.0.0",
]

[tool.setuptools]
Expand Down
42 changes: 32 additions & 10 deletions src/openenv_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
import argparse
import sys

from rich.console import Console
from rich.traceback import install

from .commands.push import push_environment


console = Console()
install(show_locals=False)


def main():
"""Main entry point for OpenEnv CLI."""
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -59,20 +66,35 @@ def main():
args = parser.parse_args()

if args.command == "push":
if args.dry_run:
status_message = f"[bold yellow]Preparing dry run for '{args.env_name}'...[/bold yellow]"
else:
status_message = f"[bold cyan]Pushing environment '{args.env_name}'...[/bold cyan]"

try:
push_environment(
env_name=args.env_name,
namespace=args.namespace,
space_name=args.space_name,
private=args.private,
base_image=args.base_image,
dry_run=args.dry_run,
)
with console.status(status_message):
push_environment(
env_name=args.env_name,
namespace=args.namespace,
space_name=args.space_name,
private=args.private,
base_image=args.base_image,
dry_run=args.dry_run,
)

if args.dry_run:
console.print(
f"[bold yellow]Dry run complete for '{args.env_name}'.[/bold yellow]"
)
else:
console.print(
f"[bold green]Successfully pushed '{args.env_name}'.[/bold green]"
)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
console.print(f"[bold red]Error:[/bold red] {e}", highlight=False, soft_wrap=True)
sys.exit(1)
else:
parser.print_help()
console.print(parser.format_help())
sys.exit(1)


Expand Down
17 changes: 3 additions & 14 deletions src/openenv_cli/commands/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

"""Push command for deploying environments to HuggingFace Spaces."""

from pathlib import Path
from typing import Optional

from huggingface_hub import HfApi
Expand All @@ -18,7 +17,7 @@
prepare_dockerfile,
prepare_readme,
)
from ..core.space import space_exists, create_space, get_space_repo_id
from ..core.space import create_space, get_space_repo_id
from ..core.uploader import upload_to_space
from ..utils.env_loader import validate_environment

Expand Down Expand Up @@ -47,7 +46,7 @@ def push_environment(
validate_environment(env_name)

# Authenticate with HuggingFace
username, token = ensure_authenticated()
_, token = ensure_authenticated()

# Determine target space repo ID
repo_id = get_space_repo_id(env_name, namespace=namespace, space_name=space_name)
Expand All @@ -56,11 +55,7 @@ def push_environment(
api = HfApi(token=token)

# Check if space exists, create if needed
if not space_exists(api, repo_id):
create_space(api, repo_id, private=private)
else:
print(f"Space {repo_id} already exists, will update it")

create_space(api, repo_id, private=private)
# Set default base image if not provided
if base_image is None:
base_image = "ghcr.io/meta-pytorch/openenv-base:latest"
Expand All @@ -78,15 +73,9 @@ def push_environment(
# Prepare README
prepare_readme(env_name, staging_dir)

if dry_run:
print(f"Dry run: Files prepared in {staging_dir}")
print(f"Would upload to: https://huggingface.co/spaces/{repo_id}")

# Upload to space (skip if dry run)
if not dry_run:
print(f"Uploading to space: {repo_id}")
upload_to_space(api, repo_id, staging_dir, token)
print(f"✅ Successfully pushed {env_name} to https://huggingface.co/spaces/{repo_id}")

finally:
# Cleanup staging directory after upload or dry run
Expand Down