-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate.py
More file actions
105 lines (92 loc) · 3.31 KB
/
validate.py
File metadata and controls
105 lines (92 loc) · 3.31 KB
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
#!/usr/bin/env python
"""Validate OpenEnv project setup."""
import sys
import yaml
from pathlib import Path
def validate_project():
"""Validate the OpenEnv RL project setup."""
print("[VALIDATION] Starting OpenEnv project validation...\n")
errors = []
warnings = []
# Check 1: openenv.yaml exists and is valid
print("[CHECK] openenv.yaml configuration...")
openenv_file = Path("openenv.yaml")
if not openenv_file.exists():
errors.append("Missing openenv.yaml")
else:
try:
with open(openenv_file) as f:
config = yaml.safe_load(f)
print(f" ✓ openenv.yaml found")
print(f" ✓ Environment: {config.get('name')}")
print(f" ✓ Tasks: {', '.join(config.get('tasks', {}).keys())}")
except Exception as e:
errors.append(f"Invalid YAML: {e}")
# Check 2: Required Python files exist
print("\n[CHECK] Required source files...")
required_files = ["main.py", "inference.py", "env.py", "tasks.py", "graders.py"]
for fname in required_files:
if Path(fname).exists():
print(f" ✓ {fname}")
else:
errors.append(f"Missing {fname}")
# Check 3: FastAPI endpoints
print("\n[CHECK] FastAPI endpoints...")
try:
from main import app
routes = [route.path for route in app.routes]
required_endpoints = ["/reset", "/step", "/state"]
for endpoint in required_endpoints:
if endpoint in routes:
print(f" ✓ {endpoint}")
else:
errors.append(f"Missing endpoint: {endpoint}")
except Exception as e:
warnings.append(f"Could not import main.py: {e}")
# Check 4: Environment class
print("\n[CHECK] Hospital environment...")
try:
from env import HospitalEnv
env = HospitalEnv()
state = env.reset()
print(f" ✓ HospitalEnv initialized")
print(f" ✓ Initial state: {state}")
except Exception as e:
errors.append(f"HospitalEnv error: {e}")
# Check 5: Requirements.txt
print("\n[CHECK] Dependencies...")
required_packages = ["fastapi", "openai", "python-dotenv", "openenv-core"]
with open("requirements.txt") as f:
requirements = f.read()
for pkg in required_packages:
if pkg in requirements:
print(f" ✓ {pkg}")
else:
warnings.append(f"Package {pkg} not in requirements.txt")
# Check 6: Docker setup
print("\n[CHECK] Docker configuration...")
if Path("Dockerfile").exists():
print(f" ✓ Dockerfile")
else:
errors.append("Missing Dockerfile")
if Path(".dockerignore").exists():
print(f" ✓ .dockerignore")
else:
warnings.append("Missing .dockerignore")
# Summary
print("\n" + "="*50)
if errors:
print(f"❌ VALIDATION FAILED ({len(errors)} error(s))")
for err in errors:
print(f" - {err}")
return False
else:
print(f"✅ VALIDATION PASSED")
if warnings:
print(f"⚠️ Warnings ({len(warnings)}):")
for warn in warnings:
print(f" - {warn}")
return True
if __name__ == "__main__":
success = validate_project()
sys.exit(0 if success else 1)