11import argparse
22import getpass
3+ import random
34import time
5+ import uuid
46from pathlib import Path
57
68import yaml
@@ -25,22 +27,32 @@ def main(
2527 preprocessed_yaml = resolve_includes (yaml_content , base_dir = CONFIG_DIR )
2628 config = yaml .safe_load (preprocessed_yaml )
2729
28- timestamp = time .strftime ("%y%m%d%H%M%S" )
29- rounds = config ["tournament" ]["rounds" ]
30- sims = config ["game" ]["sims_per_round" ]
30+ def get_output_path () -> Path :
31+ timestamp = time .strftime ("%y%m%d%H%M%S" )
32+ rounds = config ["tournament" ]["rounds" ]
33+ sims = config ["game" ]["sims_per_round" ]
3134
32- players = [p ["name" ] for p in config ["players" ]]
33- p_num = len (players )
34- p_list = "." .join (sorted (players ))
35- suffix_part = f".{ suffix } " if suffix else ""
36- folder_name = f"PvpTournament.{ config ['game' ]['name' ]} .r{ rounds } .s{ sims } .p{ p_num } .{ p_list } { suffix_part } .{ timestamp } "
37- if output_dir is None :
35+ players = [p ["name" ] for p in config ["players" ]]
36+ p_num = len (players )
37+ p_list = "." .join (sorted (players ))
38+ suffix_part = f".{ suffix } " if suffix else ""
39+ folder_name = (
40+ f"PvpTournament.{ config ['game' ]['name' ]} .r{ rounds } .s{ sims } .p{ p_num } .{ p_list } { suffix_part } .{ timestamp } "
41+ )
3842 if is_running_in_aws_batch ():
39- full_output_dir = LOCAL_LOG_DIR / "batch" / folder_name
43+ # Wait a random time to hopefully avoid collisions with the timestamp even without the uuid
44+ time .sleep (random .random () * 20 )
45+ _uuid = str (uuid .uuid4 ())
46+ folder_name += f".{ _uuid } -uuid"
47+ if output_dir is None :
48+ if is_running_in_aws_batch ():
49+ return LOCAL_LOG_DIR / "batch" / folder_name
50+ else :
51+ return LOCAL_LOG_DIR / getpass .getuser () / folder_name
4052 else :
41- full_output_dir = LOCAL_LOG_DIR / getpass . getuser () / folder_name
42- else :
43- full_output_dir = output_dir / folder_name
53+ return output_dir / folder_name
54+
55+ full_output_dir = get_output_path ()
4456
4557 tournament = PvpTournament (
4658 config , output_dir = full_output_dir , cleanup = cleanup , push = push , keep_containers = keep_containers
0 commit comments