import os import time import json from challenge_runtime import create_challenge REPOSITORY = os.getenv("BENCHMARK_REPOSITORY", "https://github.com/pallets/flask") NUM_BUGS = int(os.getenv("BENCHMARK_NUM_BUGS", "2")) DEPTH = int(os.getenv("BENCHMARK_DEPTH", "5")) REFACTORING = os.getenv("BENCHMARK_REFACTORING", "1") == "1" stage_events = [] started = time.monotonic() def callback(progress, message): stage_events.append({ "progress": progress, "message": message, "elapsed_seconds": round(time.monotonic() - started, 3), }) try: workspace = create_challenge( github_url=REPOSITORY, nesting_level=DEPTH, num_bugs=NUM_BUGS, refactoring_enabled=REFACTORING, debug_mode=True, progress_callback=callback, ) elapsed = round(time.monotonic() - started, 3) print(json.dumps({ "status": "success", "repository": REPOSITORY, "num_bugs": NUM_BUGS, "depth": DEPTH, "refactoring": REFACTORING, "workspace": workspace, "elapsed_seconds": elapsed, "events": stage_events, }, ensure_ascii=False, indent=2)) except Exception as exc: elapsed = round(time.monotonic() - started, 3) print(json.dumps({ "status": "failed", "repository": REPOSITORY, "num_bugs": NUM_BUGS, "depth": DEPTH, "refactoring": REFACTORING, "error_type": type(exc).__name__, "error": str(exc), "elapsed_seconds": elapsed, "events": stage_events, }, ensure_ascii=False, indent=2))