Skip to content

Commit

Permalink
fixes in context and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
denisri committed Nov 24, 2023
1 parent 928d1f3 commit 266cd6a
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions capsul/config/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
{
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions capsul/execution_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion capsul/in_context/afni.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion capsul/in_context/ants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion capsul/in_context/freesurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion capsul/in_context/fsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion capsul/in_context/matlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion capsul/in_context/mrtrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion capsul/in_context/spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion capsul/test/test_fake_morphologist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions capsul/test/test_tiny_morphologist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 266cd6a

Please sign in to comment.