5
5
import os
6
6
from datetime import datetime
7
7
from pathlib import Path
8
- from typing import NamedTuple , Dict , Union , Tuple
8
+ from typing import NamedTuple , Dict , Union , Tuple , Optional
9
9
10
10
import pkg_resources
11
11
import yaml
@@ -31,16 +31,28 @@ class HiveConfig(NamedTuple):
31
31
scenario_output_directory : Path = Path ("" )
32
32
33
33
@classmethod
34
- def build (cls , scenario_file_path : Path , config : Dict = None ) -> Union [Exception , HiveConfig ]:
34
+ def build (cls ,
35
+ scenario_file_path : Path ,
36
+ config : Dict = None ,
37
+ output_suffix : Optional [str ] = datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )
38
+ ) -> Union [Exception , HiveConfig ]:
39
+ """
40
+ builds a hive config by reading from a scenario file. optionally append additional key/value
41
+ pairs and modify the datetime convention for naming output directories.
42
+ :param scenario_file_path: path to the file to load as a HiveConfig
43
+ :param config: optional overrides to the default config values (Default: None)
44
+ :param output_suffix: directory name suffix to append to sim_name (by default, timestamp for now)
45
+ :return: a hive config or an error
46
+ """
35
47
return ConfigBuilder .build (
36
48
default_config = {},
37
49
required_config = (),
38
- config_constructor = lambda c : HiveConfig .from_dict (c , scenario_file_path ),
50
+ config_constructor = lambda c : HiveConfig .from_dict (c , scenario_file_path , output_suffix ),
39
51
config = config
40
52
)
41
53
42
54
@classmethod
43
- def from_dict (cls , d : Dict , scenario_file_path : Path ) -> Union [Exception , HiveConfig ]:
55
+ def from_dict (cls , d : Dict , scenario_file_path : Path , output_suffix : Optional [ str ] ) -> Union [Exception , HiveConfig ]:
44
56
# collect the global hive configuration
45
57
global_config = fs .global_hive_config_search ()
46
58
@@ -81,7 +93,7 @@ def from_dict(cls, d: Dict, scenario_file_path: Path) -> Union[Exception, HiveCo
81
93
nconfig = Network .build (conf .get ('network' ))
82
94
dconfig = DispatcherConfig .build (conf .get ('dispatcher' ))
83
95
84
- scenario_name = sconfig .sim_name + "_" + datetime . now (). strftime ( '%Y-%m-%d_%H-%M-%S' )
96
+ scenario_name = sconfig .sim_name + "_" + output_suffix if output_suffix is not None else sconfig . sim_name
85
97
scenario_output_directory = Path (global_config .output_base_directory ) / Path (scenario_name )
86
98
87
99
hive_config = HiveConfig (
0 commit comments