Skip to content

Commit bf10f9e

Browse files
committed
Fix: Better handling of local log dir paths
1 parent 84c3e3a commit bf10f9e

7 files changed

Lines changed: 16 additions & 12 deletions

File tree

codeclash/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
pass
1010

1111

12-
CONFIG_DIR = Path(__file__).resolve().parent.parent / "configs"
12+
PACKAGE_DIR = Path(__file__).resolve().parent
13+
CONFIG_DIR = PACKAGE_DIR / "configs"

codeclash/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from pathlib import Path
22

3-
DIR_LOGS = Path("logs")
3+
from codeclash import PACKAGE_DIR
4+
5+
DIR_LOGS = Path("logs") # this is used also for parts of the paths in the environment
6+
LOCAL_LOG_DIR = PACKAGE_DIR / DIR_LOGS # this one is always relative to the location of this code
47
DIR_WORK = Path("/testbed")
58
FILE_RESULTS = "results.json"
69
GH_ORG = "emagedoc"

codeclash/ratings/elo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from tqdm import tqdm
77

8-
from codeclash.constants import DIR_LOGS, FILE_RESULTS
8+
from codeclash.constants import FILE_RESULTS, LOCAL_LOG_DIR
99

1010
K_FACTOR = 32 # ELO constant, changeable
1111

@@ -99,6 +99,6 @@ def main(log_dir: Path):
9999

100100
if __name__ == "__main__":
101101
parser = argparse.ArgumentParser()
102-
parser.add_argument("-d", "--log_dir", type=Path, help="Path to game logs (Default: logs/)", default=DIR_LOGS)
102+
parser.add_argument("-d", "--log_dir", type=Path, help="Path to game logs (Default: logs/)", default=LOCAL_LOG_DIR)
103103
args = parser.parse_args()
104104
main(args.log_dir)

codeclash/ratings/win_rate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from tqdm import tqdm
77

8-
from codeclash.constants import DIR_LOGS, RESULT_TIE
8+
from codeclash.constants import LOCAL_LOG_DIR, RESULT_TIE
99

1010

1111
@dataclass
@@ -88,6 +88,6 @@ def main(log_dir: Path):
8888

8989
if __name__ == "__main__":
9090
parser = argparse.ArgumentParser()
91-
parser.add_argument("-d", "--log_dir", type=Path, help="Path to game logs (Default: logs/)", default=DIR_LOGS)
91+
parser.add_argument("-d", "--log_dir", type=Path, help="Path to game logs (Default: logs/)", default=LOCAL_LOG_DIR)
9292
args = parser.parse_args()
9393
main(args.log_dir)

codeclash/utils/aws.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from logging import Logger
44
from pathlib import Path
55

6-
from codeclash.constants import DIR_LOGS
6+
from codeclash.constants import LOCAL_LOG_DIR
77

88

99
def is_running_in_aws_batch() -> bool:
@@ -81,7 +81,7 @@ def s3_log_sync(local_output_dir: Path, *, logger: Logger) -> None:
8181
# Construct S3 path: s3://bucket/prefix/logs/relative_path
8282
# where relative_path is local_output_dir relative to DIR_LOGS
8383
try:
84-
relative_path = local_output_dir.relative_to(DIR_LOGS)
84+
relative_path = local_output_dir.relative_to(LOCAL_LOG_DIR)
8585
except ValueError:
8686
# If local_output_dir is not under DIR_LOGS, use the full path
8787
relative_path = local_output_dir

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import yaml
77

88
from codeclash import CONFIG_DIR
9-
from codeclash.constants import DIR_LOGS
9+
from codeclash.constants import LOCAL_LOG_DIR
1010
from codeclash.tournaments.pvp import PvpTournament
1111
from codeclash.utils.yaml_utils import resolve_includes
1212

@@ -34,7 +34,7 @@ def main(
3434
suffix_part = f".{suffix}" if suffix else ""
3535
folder_name = f"PvpTournament.{config['game']['name']}.r{rounds}.s{sims}.p{p_num}.{p_list}{suffix_part}.{timestamp}"
3636
if output_dir is None:
37-
full_output_dir = DIR_LOGS / getpass.getuser() / folder_name
37+
full_output_dir = LOCAL_LOG_DIR / getpass.getuser() / folder_name
3838
else:
3939
full_output_dir = output_dir / folder_name
4040

main_single_player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import yaml
77

88
from codeclash import CONFIG_DIR
9-
from codeclash.constants import DIR_LOGS
9+
from codeclash.constants import LOCAL_LOG_DIR
1010
from codeclash.tournaments.single_player import SinglePlayerTraining
1111
from codeclash.utils.yaml_utils import resolve_includes
1212

@@ -27,7 +27,7 @@ def main(
2727
suffix_part = f".{suffix}" if suffix else ""
2828
folder_name = f"SinglePlayerTraining.{config['game']['name']}.{timestamp}{suffix_part}"
2929
if output_dir is None:
30-
full_output_dir = DIR_LOGS / getpass.getuser() / folder_name
30+
full_output_dir = LOCAL_LOG_DIR / getpass.getuser() / folder_name
3131
else:
3232
full_output_dir = output_dir / folder_name
3333

0 commit comments

Comments
 (0)