Skip to content

Commit 266cd6a

Browse files
committed
fixes in context and tests
1 parent 928d1f3 commit 266cd6a

11 files changed

+20
-12
lines changed

capsul/config/test/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_single_configuration(self):
3333
user_file = osp.join(self.tmp_dir, "user_conf.json")
3434
conf_dict = {
3535
"builtin": {
36+
"config_modules": ["spm", "matlab"],
3637
"database": "builtin",
3738
"persistent": True,
3839
"start_workers": default_engine_start_workers,
@@ -57,6 +58,7 @@ def test_single_configuration(self):
5758
json.dump(conf_dict, f)
5859
app_config = ApplicationConfiguration("single_conf", user_file=user_file)
5960
self.maxDiff = 2500
61+
6062
self.assertEqual(
6163
app_config.asdict(),
6264
{
@@ -80,6 +82,7 @@ def test_single_configuration(self):
8082
def test_config_as_dict(self):
8183
conf_dict = {
8284
"builtin": {
85+
"config_modules": ["spm", "matlab"],
8386
"database": "builtin",
8487
"persistent": True,
8588
"start_workers": default_engine_start_workers,
@@ -157,6 +160,7 @@ def test_config_merge(self):
157160
}
158161
merged_conf_dict = {
159162
"builtin": {
163+
"config_modules": ["spm", "matlab"],
160164
"database": "builtin",
161165
"persistent": True,
162166
"start_workers": default_engine_start_workers,

capsul/execution_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121

2222

2323
class ExecutionContext(Controller):
24-
python_modules: list[str]
25-
config_modules: list[str]
24+
python_modules: list[str] = field(type=list[str], default_factory=list)
25+
config_modules: list[str] = field(type=list[str], default_factory=list)
2626
dataset: OpenKeyDictController[Dataset]
2727

2828
def __init__(self, config=None, executable=None, activate_modules=True):
2929
super().__init__()
3030
if config:
31-
python_modules = config.get("python_modules", ())
31+
python_modules = config.get("python_modules", [])
3232
for m in python_modules:
3333
importlib.import_module(m)
34-
config_modules = config.get("config_modules", ())
34+
config_modules = config.get("config_modules", [])
3535
self.config_modules = config_modules
3636
for m in config_modules:
3737
# The following function loads the appropriate module

capsul/in_context/afni.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def set_env_from_config(execution_context):
3232
Set environment variables FSLDIR, FSL_CONFIG, FSL_PREFIX according to the
3333
execution context configuration.
3434
"""
35-
afni_mod = getattr(execution_context, "afni")
35+
afni_mod = getattr(execution_context, "afni", None)
3636
if afni_mod:
3737
if afni_mod.directory is not undefined:
3838
os.environ["AFNIPATH"] = afni_mod.directory

capsul/in_context/ants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def set_env_from_config(execution_context):
3232
Set environment variables FSLDIR, FSL_CONFIG, FSL_PREFIX according to the
3333
execution context configuration.
3434
"""
35-
ants_mod = getattr(execution_context, "ants")
35+
ants_mod = getattr(execution_context, "ants", None)
3636
if ants_mod:
3737
if ants_mod.directory is not undefined:
3838
os.environ["ANTSPATH"] = ants_mod.directory

capsul/in_context/freesurfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def set_env_from_config(execution_context):
3030
Set environment variables FSLDIR, FSL_CONFIG, FSL_PREFIX according to the
3131
execution context configuration.
3232
"""
33-
fs_mod = getattr(execution_context, "freesurfer")
33+
fs_mod = getattr(execution_context, "freesurfer", None)
3434
if fs_mod:
3535
if fs_mod.setup_script is not undefined:
3636
os.environ["FREESURFER_HOME"] = osp.dirname(fs_mod.setup_script)

capsul/in_context/fsl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def set_env_from_config(execution_context):
5151
Set environment variables FSLDIR, FSL_CONFIG, FSL_PREFIX according to the
5252
execution context configuration.
5353
"""
54-
fsl_mod = getattr(execution_context, "fsl")
54+
fsl_mod = getattr(execution_context, "fsl", None)
5555
if fsl_mod:
5656
if fsl_mod.directory is not undefined:
5757
os.environ["FSLDIR"] = fsl_mod.directory

capsul/in_context/matlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def set_env_from_config(execution_context):
1414
Set environment variables according to the
1515
execution context configuration.
1616
"""
17-
matlab_mod = getattr(execution_context, "matlab")
17+
matlab_mod = getattr(execution_context, "matlab", None)
1818
if matlab_mod:
1919
if matlab_mod.executable is not undefined:
2020
os.environ["MATLAB_EXECUTABLE"] = matlab_mod.executable

capsul/in_context/mrtrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def set_env_from_config(execution_context):
1919
Set environment variables according to the
2020
execution context configuration.
2121
"""
22-
mrtrix_mod = getattr(execution_context, "mrtrix")
22+
mrtrix_mod = getattr(execution_context, "mrtrix", None)
2323
if mrtrix_mod:
2424
if mrtrix_mod.directory is not undefined:
2525
os.environ["MRTRIXPATH"] = mrtrix_mod.directory

capsul/in_context/spm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def set_env_from_config(execution_context):
1616
Set environment variables according to the
1717
execution context configuration.
1818
"""
19-
spm_mod = getattr(execution_context, "spm")
19+
spm_mod = getattr(execution_context, "spm", None)
2020
if spm_mod:
2121
if spm_mod.directory is not undefined:
2222
os.environ["SPM_DIRECTORY"] = spm_mod.directory

capsul/test/test_fake_morphologist.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def test_fake_morphologist_config(self):
205205
}
206206
},
207207
"builtin": {
208+
"config_modules": ["spm", "matlab"],
208209
"database": "builtin",
209210
"persistent": True,
210211
"start_workers": default_engine_start_workers,
@@ -242,7 +243,7 @@ def test_fake_morphologist_config(self):
242243
#'config_modules': ['capsul.test.test_fake_morphologist'],
243244
},
244245
}
245-
print("\nconfig:", self.capsul.config.asdict(), "\n")
246+
# print("\nconfig:", self.capsul.config.asdict(), "\n")
246247
self.assertEqual(self.capsul.config.asdict(), expected_config)
247248

248249
engine = self.capsul.engine()
@@ -256,6 +257,8 @@ def test_fake_morphologist_config(self):
256257
context = engine.execution_context(morphologist)
257258
expected_context = {
258259
#'config_modules': ['capsul.test.test_fake_morphologist'],
260+
"config_modules": ["spm", "matlab"],
261+
"python_modules": [],
259262
"dataset": {
260263
"input": {
261264
"path": str(self.tmp / "bids"),

capsul/test/test_tiny_morphologist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ def test_tiny_morphologist_config(self):
499499
context = engine.execution_context(tiny_morphologist)
500500
expected_context = {
501501
"config_modules": ["capsul.test.test_tiny_morphologist"],
502+
"python_modules": [],
502503
"dataset": {
503504
"input": {
504505
"path": str(self.tmp / "bids"),

0 commit comments

Comments
 (0)