openenv/repl
1
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 the5# LICENSE file in the root directory of this source tree.6 7"""CLI utilities for OpenEnv command-line interface."""8 9from pathlib import Path10from typing import List11 12from rich.console import Console13 14# Create a console instance for CLI output15console = Console()16 17 18def validate_env_structure(env_dir: Path, strict: bool = False) -> List[str]:19 """20 Validate that the directory follows OpenEnv environment structure.21 22 Args:23 env_dir: Path to environment directory24 strict: If True, enforce all optional requirements25 26 Returns:27 List of validation warnings (empty if all checks pass)28 29 Raises:30 FileNotFoundError: If required files are missing31 """32 warnings = []33 34 # Required files35 required_files = [36 "openenv.yaml",37 "__init__.py",38 "client.py",39 "models.py",40 "README.md",41 ]42 43 for file in required_files:44 if not (env_dir / file).exists():45 raise FileNotFoundError(f"Required file missing: {file}")46 47 # Dockerfile: must exist in server/ or at env root48 has_root_dockerfile = (env_dir / "Dockerfile").exists()49 has_server_dockerfile = (env_dir / "server" / "Dockerfile").exists()50 51 if not has_root_dockerfile and not has_server_dockerfile:52 raise FileNotFoundError(53 "Required file missing: server/Dockerfile or Dockerfile at env root"54 )55 56 # When no root Dockerfile, require the traditional server/ layout57 if not has_root_dockerfile:58 server_dir = env_dir / "server"59 if not server_dir.exists() or not server_dir.is_dir():60 raise FileNotFoundError("Required directory missing: server/")61 62 for file in ["server/__init__.py", "server/app.py"]:63 if not (env_dir / file).exists():64 raise FileNotFoundError(f"Required file missing: {file}")65 66 # Check for dependency management (pyproject.toml required)67 has_pyproject = (env_dir / "pyproject.toml").exists()68 69 if not has_pyproject:70 raise FileNotFoundError(71 "No dependency specification found. 'pyproject.toml' is required."72 )73 74 # Warnings for recommended structure75 76 if not (env_dir / "outputs").exists():77 warnings.append("Recommended directory missing: outputs/")78 79 return warnings80 