From 266cd6a4348b727e74ee674e04129471e54ce784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Rivi=C3=A8re?= Date: Fri, 24 Nov 2023 18:22:47 +0100 Subject: [PATCH] fixes in context and tests --- capsul/config/test/test_config.py | 4 ++++ capsul/execution_context.py | 8 ++++---- capsul/in_context/afni.py | 2 +- capsul/in_context/ants.py | 2 +- capsul/in_context/freesurfer.py | 2 +- capsul/in_context/fsl.py | 2 +- capsul/in_context/matlab.py | 2 +- capsul/in_context/mrtrix.py | 2 +- capsul/in_context/spm.py | 2 +- capsul/test/test_fake_morphologist.py | 5 ++++- capsul/test/test_tiny_morphologist.py | 1 + 11 files changed, 20 insertions(+), 12 deletions(-) diff --git a/capsul/config/test/test_config.py b/capsul/config/test/test_config.py index cf3b1eb0c..e3c5a1e31 100644 --- a/capsul/config/test/test_config.py +++ b/capsul/config/test/test_config.py @@ -33,6 +33,7 @@ def test_single_configuration(self): user_file = osp.join(self.tmp_dir, "user_conf.json") conf_dict = { "builtin": { + "config_modules": ["spm", "matlab"], "database": "builtin", "persistent": True, "start_workers": default_engine_start_workers, @@ -57,6 +58,7 @@ def test_single_configuration(self): json.dump(conf_dict, f) app_config = ApplicationConfiguration("single_conf", user_file=user_file) self.maxDiff = 2500 + self.assertEqual( app_config.asdict(), { @@ -80,6 +82,7 @@ def test_single_configuration(self): def test_config_as_dict(self): conf_dict = { "builtin": { + "config_modules": ["spm", "matlab"], "database": "builtin", "persistent": True, "start_workers": default_engine_start_workers, @@ -157,6 +160,7 @@ def test_config_merge(self): } merged_conf_dict = { "builtin": { + "config_modules": ["spm", "matlab"], "database": "builtin", "persistent": True, "start_workers": default_engine_start_workers, diff --git a/capsul/execution_context.py b/capsul/execution_context.py index c8c3e46bc..bb68fe47f 100644 --- a/capsul/execution_context.py +++ b/capsul/execution_context.py @@ -21,17 +21,17 @@ class ExecutionContext(Controller): - python_modules: list[str] - config_modules: list[str] + python_modules: list[str] = field(type=list[str], default_factory=list) + config_modules: list[str] = field(type=list[str], default_factory=list) dataset: OpenKeyDictController[Dataset] def __init__(self, config=None, executable=None, activate_modules=True): super().__init__() if config: - python_modules = config.get("python_modules", ()) + python_modules = config.get("python_modules", []) for m in python_modules: importlib.import_module(m) - config_modules = config.get("config_modules", ()) + config_modules = config.get("config_modules", []) self.config_modules = config_modules for m in config_modules: # The following function loads the appropriate module diff --git a/capsul/in_context/afni.py b/capsul/in_context/afni.py index 076b51b22..acb4783df 100644 --- a/capsul/in_context/afni.py +++ b/capsul/in_context/afni.py @@ -32,7 +32,7 @@ def set_env_from_config(execution_context): Set environment variables FSLDIR, FSL_CONFIG, FSL_PREFIX according to the execution context configuration. """ - afni_mod = getattr(execution_context, "afni") + afni_mod = getattr(execution_context, "afni", None) if afni_mod: if afni_mod.directory is not undefined: os.environ["AFNIPATH"] = afni_mod.directory diff --git a/capsul/in_context/ants.py b/capsul/in_context/ants.py index 0b3078e42..060930b7e 100644 --- a/capsul/in_context/ants.py +++ b/capsul/in_context/ants.py @@ -32,7 +32,7 @@ def set_env_from_config(execution_context): Set environment variables FSLDIR, FSL_CONFIG, FSL_PREFIX according to the execution context configuration. """ - ants_mod = getattr(execution_context, "ants") + ants_mod = getattr(execution_context, "ants", None) if ants_mod: if ants_mod.directory is not undefined: os.environ["ANTSPATH"] = ants_mod.directory diff --git a/capsul/in_context/freesurfer.py b/capsul/in_context/freesurfer.py index 3e1577201..44e374769 100644 --- a/capsul/in_context/freesurfer.py +++ b/capsul/in_context/freesurfer.py @@ -30,7 +30,7 @@ def set_env_from_config(execution_context): Set environment variables FSLDIR, FSL_CONFIG, FSL_PREFIX according to the execution context configuration. """ - fs_mod = getattr(execution_context, "freesurfer") + fs_mod = getattr(execution_context, "freesurfer", None) if fs_mod: if fs_mod.setup_script is not undefined: os.environ["FREESURFER_HOME"] = osp.dirname(fs_mod.setup_script) diff --git a/capsul/in_context/fsl.py b/capsul/in_context/fsl.py index 08841f413..ab1b0057a 100644 --- a/capsul/in_context/fsl.py +++ b/capsul/in_context/fsl.py @@ -51,7 +51,7 @@ def set_env_from_config(execution_context): Set environment variables FSLDIR, FSL_CONFIG, FSL_PREFIX according to the execution context configuration. """ - fsl_mod = getattr(execution_context, "fsl") + fsl_mod = getattr(execution_context, "fsl", None) if fsl_mod: if fsl_mod.directory is not undefined: os.environ["FSLDIR"] = fsl_mod.directory diff --git a/capsul/in_context/matlab.py b/capsul/in_context/matlab.py index 28859ed9c..60bb70017 100644 --- a/capsul/in_context/matlab.py +++ b/capsul/in_context/matlab.py @@ -14,7 +14,7 @@ def set_env_from_config(execution_context): Set environment variables according to the execution context configuration. """ - matlab_mod = getattr(execution_context, "matlab") + matlab_mod = getattr(execution_context, "matlab", None) if matlab_mod: if matlab_mod.executable is not undefined: os.environ["MATLAB_EXECUTABLE"] = matlab_mod.executable diff --git a/capsul/in_context/mrtrix.py b/capsul/in_context/mrtrix.py index b3de978b5..c1b9f570c 100644 --- a/capsul/in_context/mrtrix.py +++ b/capsul/in_context/mrtrix.py @@ -19,7 +19,7 @@ def set_env_from_config(execution_context): Set environment variables according to the execution context configuration. """ - mrtrix_mod = getattr(execution_context, "mrtrix") + mrtrix_mod = getattr(execution_context, "mrtrix", None) if mrtrix_mod: if mrtrix_mod.directory is not undefined: os.environ["MRTRIXPATH"] = mrtrix_mod.directory diff --git a/capsul/in_context/spm.py b/capsul/in_context/spm.py index d0a00b11e..b1686fda0 100644 --- a/capsul/in_context/spm.py +++ b/capsul/in_context/spm.py @@ -16,7 +16,7 @@ def set_env_from_config(execution_context): Set environment variables according to the execution context configuration. """ - spm_mod = getattr(execution_context, "spm") + spm_mod = getattr(execution_context, "spm", None) if spm_mod: if spm_mod.directory is not undefined: os.environ["SPM_DIRECTORY"] = spm_mod.directory diff --git a/capsul/test/test_fake_morphologist.py b/capsul/test/test_fake_morphologist.py index 2b7ae91c2..10d0a11f5 100644 --- a/capsul/test/test_fake_morphologist.py +++ b/capsul/test/test_fake_morphologist.py @@ -205,6 +205,7 @@ def test_fake_morphologist_config(self): } }, "builtin": { + "config_modules": ["spm", "matlab"], "database": "builtin", "persistent": True, "start_workers": default_engine_start_workers, @@ -242,7 +243,7 @@ def test_fake_morphologist_config(self): #'config_modules': ['capsul.test.test_fake_morphologist'], }, } - print("\nconfig:", self.capsul.config.asdict(), "\n") + # print("\nconfig:", self.capsul.config.asdict(), "\n") self.assertEqual(self.capsul.config.asdict(), expected_config) engine = self.capsul.engine() @@ -256,6 +257,8 @@ def test_fake_morphologist_config(self): context = engine.execution_context(morphologist) expected_context = { #'config_modules': ['capsul.test.test_fake_morphologist'], + "config_modules": ["spm", "matlab"], + "python_modules": [], "dataset": { "input": { "path": str(self.tmp / "bids"), diff --git a/capsul/test/test_tiny_morphologist.py b/capsul/test/test_tiny_morphologist.py index 1434bd626..ea9c23fc8 100644 --- a/capsul/test/test_tiny_morphologist.py +++ b/capsul/test/test_tiny_morphologist.py @@ -499,6 +499,7 @@ def test_tiny_morphologist_config(self): context = engine.execution_context(tiny_morphologist) expected_context = { "config_modules": ["capsul.test.test_tiny_morphologist"], + "python_modules": [], "dataset": { "input": { "path": str(self.tmp / "bids"),