MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / load_policy_module

Function load_policy_module

codeclash/arenas/scml/runtime/run_scml.py:36–53  ·  view source on GitHub ↗
(player_name: str, path: str)

Source from the content-addressed store, hash-verified

34
35
36def load_policy_module(player_name: str, path: str):
37 agent_dir = str(Path(path).resolve().parent)
38 inserted_agent_dir = agent_dir not in sys.path
39 if inserted_agent_dir:
40 sys.path.insert(0, agent_dir)
41 module_name = f"codeclash_scml_{safe_class_name(player_name).lower()}"
42 spec = importlib.util.spec_from_file_location(module_name, path)
43 if spec is None or spec.loader is None:
44 raise RuntimeError(f"Could not load module spec from {path}")
45 module = importlib.util.module_from_spec(spec)
46 try:
47 spec.loader.exec_module(module)
48 finally:
49 if inserted_agent_dir:
50 sys.path.remove(agent_dir)
51 if not hasattr(module, "decide") or not callable(module.decide):
52 raise RuntimeError(f"{path} must define a callable decide(observation)")
53 return module
54
55
56def to_plain(value):

Callers 1

policy_workerFunction · 0.70

Calls 1

safe_class_nameFunction · 0.85

Tested by

no test coverage detected