Skip to content

Commit ec9ac29

Browse files
committed
Merge branch 'main' into s2025
2 parents 84002c3 + f29414a commit ec9ac29

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

GEMstack/utils/settings.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
import json
2-
from ..knowledge import defaults
32
import copy
43
from typing import List,Union,Any
54

65
SETTINGS = 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)

main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
import sys
33

44
if __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")

0 commit comments

Comments
 (0)