@@ -64,6 +64,7 @@ def __init__(
64
64
job_result_format : tp .Optional [str ] = None ,
65
65
scratch_dir : tp .Union [str , pathlib .Path , None ] = None ,
66
66
scratch_dir_persist : bool = False ,
67
+ plugin_packages : tp .List [str ] = None ,
67
68
dev_mode : bool = False ):
68
69
69
70
trac_version = _version .__version__
@@ -86,12 +87,13 @@ def __init__(
86
87
self ._log .info (f"TRAC D.A.P. Python Runtime { trac_version } " )
87
88
88
89
self ._sys_config = sys_config if isinstance (sys_config , _cfg .RuntimeConfig ) else None
89
- self ._sys_config_path = pathlib . Path ( sys_config ) if not self ._sys_config else None
90
+ self ._sys_config_path = sys_config if not self ._sys_config else None
90
91
self ._job_result_dir = job_result_dir
91
92
self ._job_result_format = job_result_format
92
93
self ._scratch_dir = scratch_dir
93
94
self ._scratch_dir_provided = True if scratch_dir is not None else False
94
95
self ._scratch_dir_persist = scratch_dir_persist
96
+ self ._plugin_packages = plugin_packages or []
95
97
self ._dev_mode = dev_mode
96
98
97
99
# Runtime control
@@ -102,6 +104,7 @@ def __init__(
102
104
self ._oneshot_job = None
103
105
104
106
# Top level resources
107
+ self ._config_mgr : tp .Optional [_cparse .ConfigManager ] = None
105
108
self ._models : tp .Optional [_models .ModelLoader ] = None
106
109
self ._storage : tp .Optional [_storage .StorageManager ] = None
107
110
@@ -141,30 +144,36 @@ def pre_start(self):
141
144
142
145
self ._prepare_scratch_dir ()
143
146
144
- # Plugin manager and static API impl are singletons
145
- # If these methods are called multiple times, the second and subsequent calls are ignored
147
+ # Plugin manager, static API and guard rails are singletons
148
+ # Calling these methods multiple times is safe (e.g. for embedded or testing scenarios)
149
+ # However, plugins are never un-registered for the lifetime of the processes
146
150
147
151
_plugins .PluginManager .register_core_plugins ()
152
+
153
+ for plugin_package in self ._plugin_packages :
154
+ _plugins .PluginManager .register_plugin_package (plugin_package )
155
+
148
156
_static_api .StaticApiImpl .register_impl ()
149
157
_guard .PythonGuardRails .protect_dangerous_functions ()
150
158
151
159
# Load sys config (or use embedded), config errors are detected before start()
152
160
# Job config can also be checked before start() by using load_job_config()
153
161
162
+ self ._config_mgr = _cparse .ConfigManager .for_root_config (self ._sys_config_path )
163
+
154
164
if self ._sys_config is None :
155
165
sys_config_dev_mode = _dev_mode .DEV_MODE_SYS_CONFIG if self ._dev_mode else None
156
- sys_config_parser = _cparse . ConfigParser ( _cfg . RuntimeConfig , sys_config_dev_mode )
157
- sys_config_raw = sys_config_parser . load_raw_config ( self . _sys_config_path , config_file_name = "system" )
158
- self . _sys_config = sys_config_parser . parse ( sys_config_raw , self . _sys_config_path )
166
+ self . _sys_config = self . _config_mgr . load_root_object (
167
+ _cfg . RuntimeConfig , sys_config_dev_mode ,
168
+ config_file_name = "system" )
159
169
else :
160
170
self ._log .info ("Using embedded system config" )
161
171
162
172
# Dev mode translation is controlled by the dev mode flag
163
173
# I.e. it can be applied to embedded configs
164
174
165
175
if self ._dev_mode :
166
- config_dir = self ._sys_config_path .parent if self ._sys_config_path is not None else None
167
- self ._sys_config = _dev_mode .DevModeTranslator .translate_sys_config (self ._sys_config , config_dir )
176
+ self ._sys_config = _dev_mode .DevModeTranslator .translate_sys_config (self ._sys_config , self ._config_mgr )
168
177
169
178
# Runtime API server is controlled by the sys config
170
179
@@ -311,20 +320,18 @@ def load_job_config(
311
320
312
321
if isinstance (job_config , _cfg .JobConfig ):
313
322
self ._log .info ("Using embedded job config" )
314
- job_config_path = None
315
323
316
324
else :
317
- job_config_path = job_config
318
325
job_config_dev_mode = _dev_mode .DEV_MODE_JOB_CONFIG if self ._dev_mode else None
319
- job_config_parser = _cparse .ConfigParser (_cfg .JobConfig , job_config_dev_mode )
320
- job_config_raw = job_config_parser .load_raw_config (job_config_path , config_file_name = "job" )
321
- job_config = job_config_parser .parse (job_config_raw , job_config_path )
326
+ job_config = self ._config_mgr .load_config_object (
327
+ job_config , _cfg .JobConfig ,
328
+ job_config_dev_mode ,
329
+ config_file_name = "job" )
322
330
323
331
if self ._dev_mode :
324
- config_dir = job_config_path .parent if job_config_path is not None else None
325
332
job_config = _dev_mode .DevModeTranslator .translate_job_config (
326
333
self ._sys_config , job_config ,
327
- self ._scratch_dir , config_dir ,
334
+ self ._scratch_dir , self . _config_mgr ,
328
335
model_class )
329
336
330
337
return job_config
0 commit comments