Skip to content

Commit

Permalink
Merge pull request #4512 from Flamefire/fix-dump-env-script
Browse files Browse the repository at this point in the history
Fix --dump-env-script with existing modules - Don't delete modules
  • Loading branch information
boegel committed Apr 26, 2024
2 parents 7eee9b1 + 45ad228 commit a9ef0d2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions easybuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions easybuild/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 40 additions & 1 deletion test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit a9ef0d2

Please sign in to comment.