File size: 2,107 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
# 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.

"""CLI utilities for OpenEnv command-line interface."""

from pathlib import Path
from typing import List

from rich.console import Console

# Create a console instance for CLI output
console = Console()


def validate_env_structure(env_dir: Path, strict: bool = False) -> List[str]:
    """
    Validate that the directory follows OpenEnv environment structure.

    Args:
        env_dir: Path to environment directory
        strict: If True, enforce all optional requirements

    Returns:
        List of validation warnings (empty if all checks pass)

    Raises:
        FileNotFoundError: If required files are missing
    """
    warnings = []

    # Required files
    required_files = [
        "openenv.yaml",
        "__init__.py",
        "client.py",
        "models.py",
        "README.md",
    ]

    for file in required_files:
        if not (env_dir / file).exists():
            raise FileNotFoundError(f"Required file missing: {file}")

    # Required directories
    server_dir = env_dir / "server"
    if not server_dir.exists() or not server_dir.is_dir():
        raise FileNotFoundError("Required directory missing: server/")

    # Server directory required files
    server_required = [
        "server/__init__.py",
        "server/app.py",
        "server/Dockerfile",
    ]

    for file in server_required:
        if not (env_dir / file).exists():
            raise FileNotFoundError(f"Required file missing: {file}")

    # Check for dependency management (pyproject.toml required)
    has_pyproject = (env_dir / "pyproject.toml").exists()

    if not has_pyproject:
        raise FileNotFoundError(
            "No dependency specification found. 'pyproject.toml' is required."
        )

    # Warnings for recommended structure

    if not (env_dir / "outputs").exists():
        warnings.append("Recommended directory missing: outputs/")

    return warnings