MCPcopy Create free account
hub / github.com/AlphaGPU/leetgpu-challenges / load_challenge

Function load_challenge

scripts/update_challenges.py:73–125  ·  view source on GitHub ↗
(problem_dir: Path)

Source from the content-addressed store, hash-verified

71
72
73def load_challenge(problem_dir: Path) -> Dict:
74 logger.info("Loading %s", problem_dir)
75
76 problem_id = extract_id(problem_dir.name)
77
78 spec_path = problem_dir / "challenge.html"
79 if not spec_path.exists():
80 spec_path = problem_dir / "problem.html"
81 if not spec_path.exists():
82 raise FileNotFoundError(f"No spec file in {problem_dir}")
83
84 challenge_path = problem_dir / "challenge.py"
85 if not challenge_path.exists():
86 raise FileNotFoundError(f"No challenge.py in {problem_dir}")
87
88 challenges_dir = problem_dir.parent.parent
89 sys.path.insert(0, str(challenges_dir))
90
91 try:
92 spec = importlib.util.spec_from_file_location("challenge", challenge_path)
93 module = importlib.util.module_from_spec(spec)
94 spec.loader.exec_module(module)
95 challenge = module.Challenge()
96 title = challenge.name
97 access_tier = challenge.access_tier
98 finally:
99 sys.path.remove(str(challenges_dir))
100 if "challenge" in sys.modules:
101 del sys.modules["challenge"]
102
103 starter_code = []
104 starter_dir = problem_dir / "starter"
105 if starter_dir.exists():
106 for f in starter_dir.iterdir():
107 if f.is_file() and (lang := get_language(f.name)):
108 starter_code.append(
109 {
110 "language": lang,
111 "fileName": get_backend_filename(f.name),
112 "fileContent": f.read_text(),
113 }
114 )
115
116 return {
117 "id": problem_id,
118 "title": title,
119 "spec": spec_path.read_text(),
120 "challengeCode": challenge_path.read_text(),
121 "difficultyLevel": get_difficulty(problem_dir),
122 "accessTier": access_tier,
123 "accelerators": ACCELERATORS, # TODO: get from challenge.py or API
124 "starterCode": starter_code,
125 }
126
127
128def update_challenge(service_url: str, payload: Dict, api_key: str) -> bool:

Callers 1

mainFunction · 0.85

Calls 4

extract_idFunction · 0.85
get_languageFunction · 0.85
get_backend_filenameFunction · 0.85
get_difficultyFunction · 0.85

Tested by

no test coverage detected