Skip to content

Commit f2913e1

Browse files
committed
Fix: Output files
1 parent 9ce52aa commit f2913e1

5 files changed

Lines changed: 16 additions & 18 deletions

File tree

codeclash/tournaments/pvp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
class PvpTournament(AbstractTournament):
20-
def __init__(self, config: dict, *, cleanup: bool = False, push: bool = False, output_dir: Path | None = None):
20+
def __init__(self, config: dict, *, output_dir: Path, cleanup: bool = False, push: bool = False):
2121
super().__init__(config, name="PvpTournament", output_dir=output_dir)
2222
self.cleanup_on_end = cleanup
2323
self.game: CodeGame = get_game(

codeclash/tournaments/single_player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
class SinglePlayerTraining(AbstractTournament):
22-
def __init__(self, config: dict, *, cleanup: bool = False, output_dir: Path | None = None):
22+
def __init__(self, config: dict, *, output_dir: Path, cleanup: bool = False):
2323
super().__init__(config, name="SinglePlayerTraining", output_dir=output_dir)
2424
self.cleanup_on_end = cleanup
2525
self.game: CodeGame = get_game(

codeclash/tournaments/tournament.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import getpass
21
import os
32
import time
43
import traceback
54
from pathlib import Path
65

7-
from codeclash.constants import DIR_LOGS
86
from codeclash.utils.environment import create_file_in_container
97
from codeclash.utils.log import get_logger
108

119

1210
class AbstractTournament:
13-
def __init__(self, config: dict, *, name: str, output_dir: Path | None = None, **kwargs):
11+
def __init__(self, config: dict, *, name: str, output_dir: Path, **kwargs):
1412
self.config: dict = config
1513
self.name: str = name
1614
self.tournament_id: str = f"{self.name}.{config['game']['name']}.{time.strftime('%y%m%d%H%M%S')}"
17-
self._custom_output_dir: Path | None = output_dir
15+
self._output_dir: Path = output_dir
1816
self._metadata: dict = {
1917
"name": self.name,
2018
"tournament_id": self.tournament_id,
@@ -25,15 +23,9 @@ def __init__(self, config: dict, *, name: str, output_dir: Path | None = None, *
2523

2624
@property
2725
def local_output_dir(self) -> Path:
28-
if self._custom_output_dir is not None:
29-
# Custom output directory provided, add timestamp to make it unique
30-
return (self._custom_output_dir / time.strftime("%y%m%d%H%M%S")).resolve()
31-
32-
# Default behavior
33-
base_dir = DIR_LOGS
3426
if "PYTEST_CURRENT_TEST" in os.environ:
35-
base_dir = Path("/tmp/codeclash")
36-
return (base_dir / getpass.getuser() / self.tournament_id).resolve()
27+
return Path("/tmp/codeclash") / self._output_dir.name
28+
return self._output_dir.resolve()
3729

3830
def get_metadata(self) -> dict:
3931
return self._metadata

main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import getpass
3+
import time
34
from pathlib import Path
45

56
import yaml
@@ -22,13 +23,15 @@ def main(
2223
preprocessed_yaml = resolve_includes(yaml_content, base_dir=CONFIG_DIR)
2324
config = yaml.safe_load(preprocessed_yaml)
2425

25-
folder_name = f"PvpTournament.{config['game']['name']}{suffix}"
26+
timestamp = time.strftime("%y%m%d%H%M%S")
27+
suffix_part = f".{suffix}" if suffix else ""
28+
folder_name = f"PvpTournament.{config['game']['name']}.{timestamp}{suffix_part}"
2629
if output_dir is None:
2730
full_output_dir = DIR_LOGS / getpass.getuser() / folder_name
2831
else:
2932
full_output_dir = output_dir / folder_name
3033

31-
tournament = PvpTournament(config, cleanup=cleanup, push=push, output_dir=full_output_dir)
34+
tournament = PvpTournament(config, output_dir=full_output_dir, cleanup=cleanup, push=push)
3235
tournament.run()
3336

3437

main_single_player.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import getpass
3+
import time
34
from pathlib import Path
45

56
import yaml
@@ -21,13 +22,15 @@ def main(
2122
preprocessed_yaml = resolve_includes(yaml_content, base_dir=CONFIG_DIR)
2223
config = yaml.safe_load(preprocessed_yaml)
2324

24-
folder_name = f"SinglePlayerTraining.{config['game']['name']}{suffix}"
25+
timestamp = time.strftime("%y%m%d%H%M%S")
26+
suffix_part = f".{suffix}" if suffix else ""
27+
folder_name = f"SinglePlayerTraining.{config['game']['name']}.{timestamp}{suffix_part}"
2528
if output_dir is None:
2629
full_output_dir = DIR_LOGS / getpass.getuser() / folder_name
2730
else:
2831
full_output_dir = output_dir / folder_name
2932

30-
training = SinglePlayerTraining(config, cleanup=cleanup, output_dir=full_output_dir)
33+
training = SinglePlayerTraining(config, output_dir=full_output_dir, cleanup=cleanup)
3134
training.run()
3235

3336

0 commit comments

Comments
 (0)