diff --git a/easybuild/framework/easyblock.py b/easybuild/framework/easyblock.py index b17806b7c2..33110c61dd 100644 --- a/easybuild/framework/easyblock.py +++ b/easybuild/framework/easyblock.py @@ -2349,7 +2349,7 @@ def check_readiness_step(self): self.log.info("No module %s found. Not skipping anything." % self.full_mod_name) # remove existing module file under --force (but only if --skip is not used) - elif build_option('force') or build_option('rebuild'): + elif (build_option('force') or build_option('rebuild')) and not build_option('dump_env_script'): self.remove_module_file() def fetch_step(self, skip_checksums=False): diff --git a/easybuild/main.py b/easybuild/main.py index df5f23a460..42bd83dff5 100644 --- a/easybuild/main.py +++ b/easybuild/main.py @@ -440,9 +440,9 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session dry_run_mode = options.dry_run or options.dry_run_short or options.missing_modules keep_available_modules = any(( - forced, dry_run_mode, options.extended_dry_run, any_pr_option_set, options.copy_ec, options.inject_checksums, - options.sanity_check_only, options.inject_checksums_to_json) - ) + forced, dry_run_mode, any_pr_option_set, options.copy_ec, options.dump_env_script, options.extended_dry_run, + options.inject_checksums, options.inject_checksums_to_json, options.sanity_check_only + )) # skip modules that are already installed unless forced, or unless an option is used that warrants not skipping if not keep_available_modules: diff --git a/easybuild/tools/config.py b/easybuild/tools/config.py index 3a5cbecb55..6bec64764c 100644 --- a/easybuild/tools/config.py +++ b/easybuild/tools/config.py @@ -278,6 +278,7 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX): 'debug', 'debug_lmod', 'dump_autopep8', + 'dump_env_script', 'enforce_checksums', 'experimental', 'extended_dry_run', diff --git a/test/framework/easyblock.py b/test/framework/easyblock.py index 7ab5674b97..19218eca6a 100644 --- a/test/framework/easyblock.py +++ b/test/framework/easyblock.py @@ -1685,7 +1685,7 @@ def test_fetch_patches(self): self.assertEqual(eb.patches[1]['level'], 4) self.assertEqual(eb.patches[2]['name'], toy_patch) self.assertEqual(eb.patches[2]['sourcepath'], 'foobar') - self.assertEqual(eb.patches[3]['name'], 'toy-0.0.tar.gz'), + self.assertEqual(eb.patches[3]['name'], 'toy-0.0.tar.gz') self.assertEqual(eb.patches[3]['copy'], 'some/path') self.assertEqual(eb.patches[4]['name'], toy_patch) self.assertEqual(eb.patches[4]['level'], 0) diff --git a/test/framework/options.py b/test/framework/options.py index b2f3da43c1..3deaf8cf9c 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -4522,7 +4522,7 @@ def test_github_new_update_pr(self): res = [d for d in res if os.path.basename(d) != os.path.basename(git_working_dir)] if len(res) == 1: unstaged_file_full = os.path.join(res[0], unstaged_file) - self.assertNotExists(unstaged_file_full), "%s not found in %s" % (unstaged_file, res[0]) + self.assertNotExists(unstaged_file_full) else: self.fail("Found copy of easybuild-easyconfigs working copy") @@ -5249,6 +5249,45 @@ def test_dump_env_script(self): ]) self.assertEqual(out.strip(), expected_out) + def test_dump_env_script_existing_module(self): + toy_ec = 'toy-0.0.eb' + + os.chdir(self.test_prefix) + self._run_mock_eb([toy_ec, '--force'], do_build=True) + env_script = os.path.join(self.test_prefix, os.path.splitext(toy_ec)[0] + '.env') + test_module = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0') + if get_module_syntax() == 'Lua': + test_module += '.lua' + self.assertExists(test_module) + self.assertNotExists(env_script) + + args = [toy_ec, '--dump-env'] + os.chdir(self.test_prefix) + self._run_mock_eb(args, do_build=True, raise_error=True) + self.assertExists(env_script) + self.assertExists(test_module) + module_content = read_file(test_module) + env_file_content = read_file(env_script) + + error_msg = (r"Script\(s\) already exists, not overwriting them \(unless --force is used\): " + + os.path.basename(env_script)) + os.chdir(self.test_prefix) + self.assertErrorRegex(EasyBuildError, error_msg, self._run_mock_eb, args, do_build=True, raise_error=True) + self.assertExists(env_script) + self.assertExists(test_module) + # Unchanged module and env file + self.assertEqual(read_file(test_module), module_content) + self.assertEqual(read_file(env_script), env_file_content) + + args.append('--force') + os.chdir(self.test_prefix) + self._run_mock_eb(args, do_build=True, raise_error=True) + self.assertExists(env_script) + self.assertExists(test_module) + # Unchanged module and env file + self.assertEqual(read_file(test_module), module_content) + self.assertEqual(read_file(env_script), env_file_content) + def test_stop(self): """Test use of --stop.""" args = ['toy-0.0.eb', '--force', '--stop=configure']