From 3235701542b30f34497262e7662ab8e332d9307d Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Fri, 10 Jan 2020 13:47:46 +0100 Subject: [PATCH] support use of %(startdir)s template in easyconfig files (WIP) --- easybuild/framework/easyblock.py | 5 +++ easybuild/framework/easyconfig/templates.py | 3 +- test/framework/easyconfig.py | 48 +++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/easybuild/framework/easyblock.py b/easybuild/framework/easyblock.py index 256a9eeb18..8c29da23fc 100644 --- a/easybuild/framework/easyblock.py +++ b/easybuild/framework/easyblock.py @@ -1489,6 +1489,11 @@ def skip_extensions(self): # MISCELLANEOUS UTILITY FUNCTIONS # + @property + def startdir(self): + """Alias for self.start_dir.""" + return self.start_dir + @property def start_dir(self): """Start directory in build directory""" diff --git a/easybuild/framework/easyconfig/templates.py b/easybuild/framework/easyconfig/templates.py index f024866fd7..86e1fb2bf0 100644 --- a/easybuild/framework/easyconfig/templates.py +++ b/easybuild/framework/easyconfig/templates.py @@ -71,8 +71,9 @@ ] # values taken from the EasyBlock before each step TEMPLATE_NAMES_EASYBLOCK_RUN_STEP = [ - ('installdir', "Installation directory"), ('builddir', "Build directory"), + ('installdir', "Installation directory"), + ('startdir', "Start directory (directory corresponding to unpacked source)"), ] # software names for which to define ver and shortver templates TEMPLATE_SOFTWARE_VERSIONS = [ diff --git a/test/framework/easyconfig.py b/test/framework/easyconfig.py index f362632e36..875cde1bde 100644 --- a/test/framework/easyconfig.py +++ b/test/framework/easyconfig.py @@ -1004,6 +1004,54 @@ def test_templating(self): eb['description'] = "test easyconfig % %% %s% %%% %(name)s %%(name)s %%%(name)s %%%%(name)s" self.assertEqual(eb['description'], "test easyconfig % %% %s% %%% PI %(name)s %PI %%(name)s") + def test_dir_templates(self): + """Test *dir template values.""" + + test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs', 'test_ecs') + toy_ec_file = os.path.join(test_ecs_dir, 't', 'toy', 'toy-0.0.eb') + + ec = EasyConfig(toy_ec_file, validate=False) + toy_easyblock = get_easyblock_class(None, ec.name) + toy_eb = toy_easyblock(ec) + + # initially the *dir templates are not defined yet + for key in ['builddir', 'installdir', 'startdir']: + self.assertFalse(key in toy_eb.cfg.template_values) + + # after 'ready' step which calls make_builddir, both builddir and installdir templates are defined + toy_eb.run_step('ready', [lambda x: x.make_builddir]) + builddir_tmpl = toy_eb.cfg.template_values['builddir'] + expected_builddir = os.path.join(self.test_buildpath, 'toy', '0.0', 'system-system') + self.assertTrue(os.path.samefile(builddir_tmpl, expected_builddir)) + self.assertTrue(os.path.samefile(builddir_tmpl, toy_eb.builddir)) + + toy_eb.make_installdir() + expected_installdir = os.path.join(self.test_installpath, 'software', 'toy', '0.0') + installdir_tmpl = toy_eb.cfg.template_values['installdir'] + self.assertTrue(os.path.samefile(installdir_tmpl, expected_installdir)) + self.assertTrue(os.path.samefile(installdir_tmpl, toy_eb.installdir)) + + # startdir template is not defined yet (only after prepare_step), will have 'None' as value for now + self.assertEqual(toy_eb.cfg.template_values['startdir'], 'None') + + toy_eb.run_step('fetch', [lambda x: x.fetch_step]) + toy_eb.run_step('extract', [lambda x: x.extract_step]) + toy_eb.run_step('prepare', [lambda x: x.prepare_step]) + toy_eb.update_config_template_run_step() + + builddir_tmpl = toy_eb.cfg.template_values['builddir'] + self.assertTrue(os.path.samefile(builddir_tmpl, expected_builddir)) + self.assertTrue(os.path.samefile(builddir_tmpl, toy_eb.builddir)) + + installdir_tmpl = toy_eb.cfg.template_values['installdir'] + self.assertTrue(os.path.samefile(installdir_tmpl, expected_installdir)) + self.assertTrue(os.path.samefile(installdir_tmpl, toy_eb.installdir)) + + startdir_tmpl = toy_eb.cfg.template_values['startdir'] + expected_startdir = os.path.join(toy_eb.builddir, 'toy-0.0') + self.assertTrue(os.path.samefile(startdir_tmpl, expected_startdir)) + self.assertTrue(os.path.samefile(startdir_tmpl, toy_eb.startdir)) + def test_templating_doc(self): """test templating documentation""" doc = avail_easyconfig_templates()