import os import sys import json import yaml # PyYAML is needed, usually in these environments from pathlib import Path def validate(): cwd = Path.cwd() errors = [] warnings = [] print(f"šŸ” Validating OpenEnv Submission at {cwd}\n") # 1. README.md Meta Check readme_path = cwd / "README.md" if not readme_path.exists(): errors.append("āŒ Missing README.md") else: content = readme_path.read_text(encoding="utf-8") if "---" not in content or "sdk: docker" not in content: errors.append("āŒ README.md's YAML frontmatter is missing or incorrect (needs 'sdk: docker')") else: print("āœ… README.md metadata found.") # 2. openenv.yaml Check openenv_path = cwd / "openenv.yaml" if not openenv_path.exists(): errors.append("āŒ Missing openenv.yaml") else: try: with open(openenv_path, "r") as f: cfg = yaml.safe_load(f) required_keys = ["name", "version", "tasks", "action_space", "observation_space", "deploy"] for k in required_keys: if k not in cfg: errors.append(f"āŒ openenv.yaml is missing required key: {k}") if len(cfg.get("tasks", [])) < 3: warnings.append("āš ļø OpenEnv recommends at least 3 tasks (easy, medium, hard).") print("āœ… openenv.yaml follows spec.") except Exception as e: errors.append(f"āŒ Failed to parse openenv.yaml: {e}") # 3. Dockerfile Check docker_path = cwd / "Dockerfile" if not docker_path.exists(): errors.append("āŒ Missing Dockerfile (Mandatory for HF Space docker SDK)") else: print("āœ… Dockerfile exists.") # 4. inference.py Check inference_path = cwd / "inference.py" if not inference_path.exists(): errors.append("āŒ Missing inference.py in root directory.") else: content = inference_path.read_text(encoding="utf-8") # Mandatory logs check for tag in ["[START]", "[STEP]", "[END]"]: if tag not in content: errors.append(f"āŒ Structured logging tag '{tag}' not found in inference.py") # Mandatory variables check for var in ["API_BASE_URL", "MODEL_NAME", "HF_TOKEN"]: if var not in content: errors.append(f"āŒ Mandatory variable/env check for '{var}' not found in inference.py") # OpenAI client check if "OpenAI" not in content or "client.chat.completions.create" not in content: errors.append("āŒ inference.py must use OpenAI client for LLM calls.") print("āœ… inference.py follows mandatory rules.") # 5. Requirement Check req_path = cwd / "requirements.txt" if not req_path.exists(): errors.append("āŒ Missing requirements.txt") else: print("āœ… requirements.txt exists.") # Result Summary print("\n--- Validation Summary ---") if errors: for e in errors: print(e) print("\nāŒ FAILED: Please fix errors before submitting.") sys.exit(1) else: if warnings: for w in warnings: print(w) print("\nāœ… PASSED: Project matches Scalar Hackathon OpenEnv requirements.") print("šŸš€ Ready for submission!") if __name__ == "__main__": validate()