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

Class AbstractTournament

codeclash/tournaments/tournament.py:12–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class AbstractTournament:
13 def __init__(self, config: dict, *, name: str, output_dir: Path, **kwargs):
14 self.config: dict = config
15 self.name: str = name
16 self.tournament_id: str = f"{self.name}.{config['game']['name']}.{time.strftime('%y%m%d%H%M%S')}"
17 self._output_dir: Path = output_dir
18 self._metadata: dict = {
19 "name": self.name,
20 "tournament_id": self.tournament_id,
21 "config": self.config,
22 "created_timestamp": int(time.time()),
23 "aws": get_aws_metadata(),
24 }
25 self.logger = get_logger(self.name, log_path=self.local_output_dir / "tournament.log", emoji="🏆")
26 self._root_file_handler = add_root_file_handler(self.local_output_dir / "everything.log")
27
28 @property
29 def local_output_dir(self) -> Path:
30 if "PYTEST_CURRENT_TEST" in os.environ:
31 return Path("/tmp/codeclash") / self._output_dir.name
32 return self._output_dir.resolve()
33
34 def get_metadata(self) -> dict:
35 return self._metadata
36
37 def cleanup_handlers(self) -> None:
38 """Close and remove file handlers to prevent file descriptor leaks."""
39 # Close the root file handler
40 remove_file_handler(logging.getLogger(), self._root_file_handler)
41
42 # Close logger's file handlers
43 for handler in self.logger.handlers[:]: # Copy list to avoid modification during iteration
44 if isinstance(handler, logging.FileHandler):
45 self.logger.removeHandler(handler)
46 handler.close()
47
48 def _copy_game_log_to_agent(self, agent, round_num: int, log_output: str, dest_path: str = None) -> None:
49 """Copy round log to agent environment."""
50 try:
51 create_file_in_container(
52 container=agent.environment,
53 content=log_output,
54 dest_path=dest_path if dest_path else f"logs/round_{round_num}.log",
55 )
56 except Exception:
57 self.logger.error(f"Error creating round log in {agent.name}'s container: {traceback.format_exc()}")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected