File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import json
2- from ..knowledge import defaults
32import copy
43from typing import List ,Union ,Any
54
65SETTINGS = None
76
8- def load_settings ():
7+ def load_settings (settings_file : str = None ):
98 """Loads the settings object for the first time.
109
11- Order of operations is to look into defaults.SETTINGS, and then
12- look through the command line arguments to determine whether the user has
13- overridden any settings using --KEY=VALUE.
10+ Order of operations is:
11+ - If settings_file is given, load it.
12+ - Otherwise, get the settings from defaults.SETTINGS
13+ - Look through the command line arguments to determine whether the user has
14+ overridden any settings using --KEY=VALUE.
1415 """
1516 global SETTINGS
1617 if SETTINGS is not None :
1718 return
1819 import os
1920 import sys
20- SETTINGS = copy .deepcopy (defaults .SETTINGS )
21+ if settings_file is not None :
22+ from .config import load_config_recursive
23+ import os
24+ print ("**************************************************************" )
25+ print ("Loading global settings from" ,settings_file )
26+ print ("**************************************************************" )
27+ SETTINGS = load_config_recursive (os .path .abspath (settings_file ))
28+ else :
29+ from ..knowledge import defaults
30+ SETTINGS = copy .deepcopy (defaults .SETTINGS )
2131 for arg in sys .argv :
2232 if arg .startswith ('--' ):
2333 k ,v = arg .split ('=' ,1 )
Original file line number Diff line number Diff line change 22import sys
33
44if __name__ == '__main__' :
5+ #check for settings override
6+ for arg in sys .argv [1 :]:
7+ if arg .startswith ('--settings=' ):
8+ settings .load_settings (arg [11 :])
9+ break
10+ #get launch file
511 launch_file = None
612 for arg in sys .argv [1 :]:
713 if arg .startswith ('--run=' ):
8- launch_file = arg [9 :]
14+ launch_file = arg [6 :]
915 break
1016 elif not arg .startswith ('--' ):
1117 launch_file = arg
1218 break
1319 if launch_file is None :
1420 runconfig = settings .get ('run' ,None )
1521 if runconfig is None :
16- print ("Usage: python3 [--key1=value1 --key2=value2] LAUNCH_FILE.yaml" )
17- print (" Current settings are found in knowledge/defaults/current.yaml" )
22+ print ("Usage: python3 [--key1=value1 --key2=value2] [--settings=SETTINGS_OVERRIDE.yaml] LAUNCH_FILE.yaml" )
23+ print (" Default settings are found in knowledge/defaults/current.yaml" )
1824 exit (1 )
1925 else :
2026 print ("Using default run configuration in knowledge/defaults/current.yaml" )
You can’t perform that action at this time.
0 commit comments