Spaces:
Sleeping
Sleeping
File size: 3,448 Bytes
e2812ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
"""
OpenEnv validate command.
This module provides the 'openenv validate' command to check if environments
are properly configured for multi-mode deployment.
"""
from pathlib import Path
import typer
from openenv.cli._validation import (
format_validation_report,
get_deployment_modes,
validate_multi_mode_deployment,
)
def validate(
env_path: str | None = typer.Argument(
None, help="Path to the environment directory (default: current directory)"
),
verbose: bool = typer.Option(
False, "--verbose", "-v", help="Show detailed information"
),
) -> None:
"""
Validate an environment for standardized structure and deployment readiness.
This command checks if an environment is properly configured with:
- Required files (pyproject.toml, openenv.yaml, server/app.py, etc.)
- Docker deployment support
- uv run server capability
- python -m module execution
Examples:
# Validate current directory (recommended)
$ cd my_env
$ openenv validate
# Validate with detailed output
$ openenv validate --verbose
# Validate specific environment
$ openenv validate envs/echo_env
"""
# Determine environment path (default to current directory)
if env_path is None:
env_path_obj = Path.cwd()
else:
env_path_obj = Path(env_path)
if not env_path_obj.exists():
typer.echo(f"Error: Path does not exist: {env_path_obj}", err=True)
raise typer.Exit(1)
if not env_path_obj.is_dir():
typer.echo(f"Error: Path is not a directory: {env_path_obj}", err=True)
raise typer.Exit(1)
# Check for openenv.yaml to confirm this is an environment directory
openenv_yaml = env_path_obj / "openenv.yaml"
if not openenv_yaml.exists():
typer.echo(
f"Error: Not an OpenEnv environment directory (missing openenv.yaml): {env_path_obj}",
err=True,
)
typer.echo(
"Hint: Run this command from the environment root directory or specify the path",
err=True,
)
raise typer.Exit(1)
env_name = env_path_obj.name
if env_name.endswith("_env"):
base_name = env_name[:-4]
else:
base_name = env_name
# Run validation
is_valid, issues = validate_multi_mode_deployment(env_path_obj)
# Show validation report
report = format_validation_report(base_name, is_valid, issues)
typer.echo(report)
# Show deployment modes if verbose
if verbose:
typer.echo("\nSupported deployment modes:")
modes = get_deployment_modes(env_path_obj)
for mode, supported in modes.items():
status = "[YES]" if supported else "[NO]"
typer.echo(f" {status} {mode}")
if is_valid:
typer.echo("\nUsage examples:")
typer.echo(f" cd {env_path_obj.name} && uv run server")
typer.echo(f" cd {env_path_obj.name} && openenv build")
typer.echo(f" cd {env_path_obj.name} && openenv push")
if not is_valid:
raise typer.Exit(1)
|