Skip to content

Commit ef1ad48

Browse files
Merge pull request #3684 from boegel/update_build_option
add update_build_option function to update specific build options after initializing the EasyBuild configuration
2 parents b03612a + 3118cb4 commit ef1ad48

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

easybuild/tools/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,18 @@ def build_option(key, **kwargs):
558558
raise EasyBuildError(error_msg)
559559

560560

561+
def update_build_option(key, value):
562+
"""
563+
Update build option with specified name to given value.
564+
565+
WARNING: Use this with care, the build options are not expected to be changed during an EasyBuild session!
566+
"""
567+
# BuildOptions() is a (singleton) frozen dict, so this is less straightforward that it seems...
568+
build_options = BuildOptions()
569+
build_options._FrozenDict__dict[key] = value
570+
_log.warning("Build option '%s' was updated to: %s", key, build_option(key))
571+
572+
561573
def build_path():
562574
"""
563575
Return the build path

test/framework/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from easybuild.tools import run
4141
from easybuild.tools.build_log import EasyBuildError
4242
from easybuild.tools.config import build_option, build_path, get_build_log_path, get_log_filename, get_repositorypath
43-
from easybuild.tools.config import install_path, log_file_format, log_path, source_paths
43+
from easybuild.tools.config import install_path, log_file_format, log_path, source_paths, update_build_option
4444
from easybuild.tools.config import BuildOptions, ConfigurationVariables
4545
from easybuild.tools.config import DEFAULT_PATH_SUBDIRS, init_build_options
4646
from easybuild.tools.filetools import copy_dir, mkdir, write_file
@@ -677,6 +677,13 @@ def test_get_build_log_path(self):
677677
init_config(args=['--tmp-logdir=%s' % build_log_path])
678678
self.assertEqual(get_build_log_path(), build_log_path)
679679

680+
def test_update_build_option(self):
681+
"""Test updating of a build option."""
682+
self.assertEqual(build_option('banned_linked_shared_libs'), None)
683+
684+
update_build_option('banned_linked_shared_libs', '/usr/lib64/libssl.so.1.1')
685+
self.assertEqual(build_option('banned_linked_shared_libs'), '/usr/lib64/libssl.so.1.1')
686+
680687

681688
def suite():
682689
return TestLoaderFiltered().loadTestsFromTestCase(EasyBuildConfigTest, sys.argv[1:])

0 commit comments

Comments
 (0)