()
| 88 | |
| 89 | |
| 90 | def main() -> int: |
| 91 | if not LEETGPU_API_KEY: |
| 92 | logger.error("LEETGPU_API_KEY environment variable is required") |
| 93 | return 1 |
| 94 | |
| 95 | parser = argparse.ArgumentParser(description="Submit a solution via WebSocket API.") |
| 96 | parser.add_argument("challenge_path", type=Path, help="Path to the challenge directory") |
| 97 | parser.add_argument("--language", default="cuda", help="Language (default: cuda)") |
| 98 | parser.add_argument("--accelerator", default="T4", help="Accelerator name (default: T4)") |
| 99 | parser.add_argument( |
| 100 | "--action", default="run", choices=["run", "submit"], help="Action (run or submit)" |
| 101 | ) |
| 102 | args = parser.parse_args() |
| 103 | |
| 104 | challenge_py = args.challenge_path / "challenge.py" |
| 105 | if not challenge_py.exists(): |
| 106 | logger.error("No challenge.py found in %s", args.challenge_path) |
| 107 | return 1 |
| 108 | challenge_code = challenge_py.read_text() |
| 109 | |
| 110 | try: |
| 111 | file_name, content = find_solution_file(args.challenge_path, args.language) |
| 112 | except Exception as e: |
| 113 | logger.error("Failed to find solution file: %s", e) |
| 114 | return 1 |
| 115 | |
| 116 | # Convert http(s) URL to ws(s) URL |
| 117 | ws_url = SERVICE_URL.replace("https://", "wss://").replace("http://", "ws://") |
| 118 | ok = submit_solution( |
| 119 | ws_url=f"{ws_url.rstrip('/')}/api/v1/ws/submit", |
| 120 | api_key=LEETGPU_API_KEY, |
| 121 | challenge_code=challenge_code, |
| 122 | file_name=file_name, |
| 123 | content=content, |
| 124 | language=args.language, |
| 125 | accelerator=args.accelerator, |
| 126 | action=args.action, |
| 127 | public=False, |
| 128 | ) |
| 129 | return 0 if ok else 1 |
| 130 | |
| 131 | |
| 132 | if __name__ == "__main__": |
no test coverage detected