Skip to content

Commit

Permalink
Error when frameworks installation script fails
Browse files Browse the repository at this point in the history
  • Loading branch information
PGijsbers committed Dec 31, 2024
1 parent b719142 commit ec36c66
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
17 changes: 11 additions & 6 deletions amlb/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,17 @@ def setup(self, mode: SetupMode):
self._mark_setup_start()

if hasattr(self.framework_module, "setup"):
self.framework_module.setup(
*self.framework_def.setup_args,
_shell_=False, # prevents #arg from being interpreted as comment
_live_output_=rconfig().setup.live_output,
_activity_timeout_=rconfig().setup.activity_timeout,
)
try:
self.framework_module.setup(
*self.framework_def.setup_args,
_shell_=False, # prevents #arg from being interpreted as comment
_live_output_=rconfig().setup.live_output,
_activity_timeout_=rconfig().setup.activity_timeout,
)
except Exception as e:
raise JobError(
f"Setup of framework {self.framework_name} failed."
) from e

if self.framework_def.setup_script is not None:
run_script(
Expand Down
2 changes: 1 addition & 1 deletion amlb/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def run_cmd(cmd, *args, **kwargs):
params[k] = kwargs[kk]
del kwargs[kk]
cmd_args = as_cmd_args(*args, **kwargs)
full_cmd = flatten([cmd]) + cmd_args
full_cmd = [os.environ["SHELL"], "-e"] + flatten([cmd]) + cmd_args
str_cmd = " ".join(full_cmd)
log.log(params.log_level, "Running cmd `%s`", str_cmd)
log.debug("Running cmd `%s` with input: %s", str_cmd, params.input_str)
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def load_default_resources(tmp_path):
os.path.join(default_dirs.root_dir, "resources", "config.yaml")
)
config_default_dirs = default_dirs
config_test = Namespace(
frameworks=Namespace(definition_file=["{root}/tests/resources/frameworks.yaml"])
)
# allowing config override from user_dir: useful to define custom benchmarks and frameworks for example.
config_user = Namespace()
# config listing properties set by command line
Expand All @@ -30,7 +33,7 @@ def load_default_resources(tmp_path):
config_args = Namespace({k: v for k, v in config_args if v is not None})
# merging all configuration files and saving to the global variable
resources.from_configs(
config_default, config_default_dirs, config_user, config_args
config_default, config_test, config_default_dirs, config_user, config_args
)


Expand Down
3 changes: 3 additions & 0 deletions tests/resources/frameworks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setup_fail:
description: "used for tests"
module: tests.resources.frameworks.setup_fail
16 changes: 16 additions & 0 deletions tests/unit/amlb/benchmarks/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from amlb import Benchmark, SetupMode, resources, DockerBenchmark, SingularityBenchmark
from amlb.job import JobError
from amlb.utils import Namespace


Expand Down Expand Up @@ -112,3 +113,18 @@ def test_singularity_image_name_as_docker(
as_docker_image=True,
)
assert result == expected


def test_benchmark_setup_errors_if_framework_does_not_install(
load_default_resources,
) -> None:
benchmark = Benchmark(
framework_name="setup_fail",
benchmark_name="test",
constraint_name="test",
job_history=None,
)

with pytest.raises(JobError) as exc_info:
benchmark.setup(SetupMode.force)
assert "setup" in str(exc_info.value)

0 comments on commit ec36c66

Please sign in to comment.