Skip to content

Commit a9ef0d2

Browse files
authored
Merge pull request #4512 from Flamefire/fix-dump-env-script
Fix --dump-env-script with existing modules - Don't delete modules
2 parents 7eee9b1 + 45ad228 commit a9ef0d2

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

easybuild/framework/easyblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,7 @@ def check_readiness_step(self):
23492349
self.log.info("No module %s found. Not skipping anything." % self.full_mod_name)
23502350

23512351
# remove existing module file under --force (but only if --skip is not used)
2352-
elif build_option('force') or build_option('rebuild'):
2352+
elif (build_option('force') or build_option('rebuild')) and not build_option('dump_env_script'):
23532353
self.remove_module_file()
23542354

23552355
def fetch_step(self, skip_checksums=False):

easybuild/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session
440440
dry_run_mode = options.dry_run or options.dry_run_short or options.missing_modules
441441

442442
keep_available_modules = any((
443-
forced, dry_run_mode, options.extended_dry_run, any_pr_option_set, options.copy_ec, options.inject_checksums,
444-
options.sanity_check_only, options.inject_checksums_to_json)
445-
)
443+
forced, dry_run_mode, any_pr_option_set, options.copy_ec, options.dump_env_script, options.extended_dry_run,
444+
options.inject_checksums, options.inject_checksums_to_json, options.sanity_check_only
445+
))
446446

447447
# skip modules that are already installed unless forced, or unless an option is used that warrants not skipping
448448
if not keep_available_modules:

easybuild/tools/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX):
278278
'debug',
279279
'debug_lmod',
280280
'dump_autopep8',
281+
'dump_env_script',
281282
'enforce_checksums',
282283
'experimental',
283284
'extended_dry_run',

test/framework/easyblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ def test_fetch_patches(self):
16851685
self.assertEqual(eb.patches[1]['level'], 4)
16861686
self.assertEqual(eb.patches[2]['name'], toy_patch)
16871687
self.assertEqual(eb.patches[2]['sourcepath'], 'foobar')
1688-
self.assertEqual(eb.patches[3]['name'], 'toy-0.0.tar.gz'),
1688+
self.assertEqual(eb.patches[3]['name'], 'toy-0.0.tar.gz')
16891689
self.assertEqual(eb.patches[3]['copy'], 'some/path')
16901690
self.assertEqual(eb.patches[4]['name'], toy_patch)
16911691
self.assertEqual(eb.patches[4]['level'], 0)

test/framework/options.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4522,7 +4522,7 @@ def test_github_new_update_pr(self):
45224522
res = [d for d in res if os.path.basename(d) != os.path.basename(git_working_dir)]
45234523
if len(res) == 1:
45244524
unstaged_file_full = os.path.join(res[0], unstaged_file)
4525-
self.assertNotExists(unstaged_file_full), "%s not found in %s" % (unstaged_file, res[0])
4525+
self.assertNotExists(unstaged_file_full)
45264526
else:
45274527
self.fail("Found copy of easybuild-easyconfigs working copy")
45284528

@@ -5249,6 +5249,45 @@ def test_dump_env_script(self):
52495249
])
52505250
self.assertEqual(out.strip(), expected_out)
52515251

5252+
def test_dump_env_script_existing_module(self):
5253+
toy_ec = 'toy-0.0.eb'
5254+
5255+
os.chdir(self.test_prefix)
5256+
self._run_mock_eb([toy_ec, '--force'], do_build=True)
5257+
env_script = os.path.join(self.test_prefix, os.path.splitext(toy_ec)[0] + '.env')
5258+
test_module = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0')
5259+
if get_module_syntax() == 'Lua':
5260+
test_module += '.lua'
5261+
self.assertExists(test_module)
5262+
self.assertNotExists(env_script)
5263+
5264+
args = [toy_ec, '--dump-env']
5265+
os.chdir(self.test_prefix)
5266+
self._run_mock_eb(args, do_build=True, raise_error=True)
5267+
self.assertExists(env_script)
5268+
self.assertExists(test_module)
5269+
module_content = read_file(test_module)
5270+
env_file_content = read_file(env_script)
5271+
5272+
error_msg = (r"Script\(s\) already exists, not overwriting them \(unless --force is used\): "
5273+
+ os.path.basename(env_script))
5274+
os.chdir(self.test_prefix)
5275+
self.assertErrorRegex(EasyBuildError, error_msg, self._run_mock_eb, args, do_build=True, raise_error=True)
5276+
self.assertExists(env_script)
5277+
self.assertExists(test_module)
5278+
# Unchanged module and env file
5279+
self.assertEqual(read_file(test_module), module_content)
5280+
self.assertEqual(read_file(env_script), env_file_content)
5281+
5282+
args.append('--force')
5283+
os.chdir(self.test_prefix)
5284+
self._run_mock_eb(args, do_build=True, raise_error=True)
5285+
self.assertExists(env_script)
5286+
self.assertExists(test_module)
5287+
# Unchanged module and env file
5288+
self.assertEqual(read_file(test_module), module_content)
5289+
self.assertEqual(read_file(env_script), env_file_content)
5290+
52525291
def test_stop(self):
52535292
"""Test use of --stop."""
52545293
args = ['toy-0.0.eb', '--force', '--stop=configure']

0 commit comments

Comments
 (0)