Skip to content

Commit 611d671

Browse files
committed
hide backup module file when using Lmod 6.x (fixes #9302)
1 parent dd72827 commit 611d671

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

easybuild/framework/easyblock.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
from easybuild.tools.module_generator import ModuleGeneratorLua, ModuleGeneratorTcl, module_generator, dependencies_for
8787
from easybuild.tools.module_naming_scheme.utilities import det_full_ec_version
8888
from easybuild.tools.modules import ROOT_ENV_VAR_NAME_PREFIX, VERSION_ENV_VAR_NAME_PREFIX, DEVEL_ENV_VAR_NAME_PREFIX
89-
from easybuild.tools.modules import curr_module_paths, invalidate_module_caches_for, get_software_root
89+
from easybuild.tools.modules import Lmod, curr_module_paths, invalidate_module_caches_for, get_software_root
9090
from easybuild.tools.modules import get_software_root_env_var_name, get_software_version_env_var_name
9191
from easybuild.tools.package.utilities import package
9292
from easybuild.tools.py2vs3 import extract_method_name, string_type
@@ -1674,6 +1674,11 @@ def check_readiness_step(self):
16741674
# which is better than hiding them (since --show-hidden still reveals them)
16751675
hidden = isinstance(self.module_generator, ModuleGeneratorTcl)
16761676

1677+
# with old Lmod versions, the backup module should also be hidden when using Lua syntax;
1678+
# see https://github.com/easybuilders/easybuild-easyconfigs/issues/9302
1679+
if isinstance(self.module_generator, ModuleGeneratorLua) and isinstance(self.modules_tool, Lmod):
1680+
hidden = LooseVersion(self.modules_tool.version) < LooseVersion('7.0.0')
1681+
16771682
self.mod_file_backup = back_up_file(self.mod_filepath, hidden=hidden, strip_fn=strip_fn)
16781683
print_msg("backup of existing module file stored at %s" % self.mod_file_backup, log=self.log)
16791684

test/framework/toy_build.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from easybuild.tools.build_log import EasyBuildError
5050
from easybuild.tools.config import get_module_syntax, get_repositorypath
5151
from easybuild.tools.environment import modify_env
52-
from easybuild.tools.filetools import adjust_permissions, mkdir, read_file, remove_file, which, write_file
52+
from easybuild.tools.filetools import adjust_permissions, mkdir, read_file, remove_dir, remove_file, which, write_file
5353
from easybuild.tools.module_generator import ModuleGeneratorTcl
5454
from easybuild.tools.modules import Lmod
5555
from easybuild.tools.py2vs3 import string_type
@@ -1533,19 +1533,27 @@ def test_backup_modules(self):
15331533
self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout))
15341534
self.assertEqual(stderr, '')
15351535

1536-
# Test also with lua syntax if Lmod is available. In particular, that the backup is not hidden
1536+
# Test also with Lua syntax if Lmod is available.
1537+
# In particular, that the backup is not hidden (except when using Lmod < 7.0)
15371538
if isinstance(self.modtool, Lmod):
15381539
args = common_args + ['--module-syntax=Lua', '--backup-modules']
15391540

1540-
toy_mod_dir = os.path.join(self.test_installpath, 'modules', 'all', 'toy')
1541-
toy_mod_fn = '0.0-deps'
1541+
remove_dir(toy_mod_dir)
15421542
toy_mod = os.path.join(toy_mod_dir, toy_mod_fn + '.lua')
15431543

1544+
# initial installation of Lua module file
15441545
self.eb_main(args, do_build=True, raise_error=True)
15451546
self.assertTrue(os.path.exists(toy_mod))
1546-
lua_toy_mods = glob.glob(os.path.join(toy_mod_dir, '*.lua'))
1547+
lua_toy_mods = glob.glob(os.path.join(toy_mod_dir, '*.lua*'))
15471548
self.assertEqual(len(lua_toy_mods), 1)
1549+
self.assertEqual(os.path.basename(toy_mod), os.path.basename(lua_toy_mods[0]))
1550+
# no backups yet
1551+
toy_mod_backups = glob.glob(os.path.join(toy_mod_dir, toy_mod_fn + '.bak_*'))
1552+
self.assertEqual(len(toy_mod_backups), 0)
1553+
hidden_toy_mod_backups = glob.glob(os.path.join(toy_mod_dir, '.' + toy_mod_fn + '.bak_*'))
1554+
self.assertEqual(len(hidden_toy_mod_backups), 0)
15481555

1556+
# 2nd installation: backup module is created
15491557
self.mock_stderr(True)
15501558
self.mock_stdout(True)
15511559
self.eb_main(args, do_build=True, raise_error=True, verbose=True)
@@ -1555,18 +1563,35 @@ def test_backup_modules(self):
15551563
self.mock_stdout(False)
15561564

15571565
self.assertTrue(os.path.exists(toy_mod))
1566+
lua_toy_mods = glob.glob(os.path.join(toy_mod_dir, '*.lua*'))
1567+
self.assertEqual(len(lua_toy_mods), 1)
1568+
self.assertEqual(os.path.basename(toy_mod), os.path.basename(lua_toy_mods[0]))
1569+
1570+
# backup module is only hidden for old Lmod versions
1571+
lmod_version = os.getenv('LMOD_VERSION', 'NOT_FOUND')
1572+
if LooseVersion(lmod_version) < LooseVersion('7.0.0'):
1573+
backups_visible, backups_hidden = 0, 1
1574+
toy_mod_bak = r".*/toy/\.0\.0-deps\.bak_[0-9]+_[0-9]+"
1575+
else:
1576+
backups_visible, backups_hidden = 1, 0
1577+
toy_mod_bak = r".*/toy/0\.0-deps\.bak_[0-9]+_[0-9]+"
1578+
15581579
toy_mod_backups = glob.glob(os.path.join(toy_mod_dir, toy_mod_fn + '.bak_*'))
1559-
self.assertEqual(len(toy_mod_backups), 1)
1560-
first_toy_lua_mod_backup = toy_mod_backups[0]
1580+
self.assertEqual(len(toy_mod_backups), backups_visible)
1581+
hidden_toy_mod_backups = glob.glob(os.path.join(toy_mod_dir, '.' + toy_mod_fn + '.bak_*'))
1582+
self.assertEqual(len(hidden_toy_mod_backups), backups_hidden)
1583+
1584+
first_toy_lua_mod_backup = (toy_mod_backups or hidden_toy_mod_backups)[0]
15611585
self.assertTrue('.bak_' in os.path.basename(first_toy_lua_mod_backup))
1562-
self.assertFalse(os.path.basename(first_toy_lua_mod_backup).startswith('.'))
15631586

1564-
toy_mod_bak = r".*/toy/0\.0-deps\.bak_[0-9]+_[0-9]+"
1587+
# check messages in stdout/stderr
15651588
regex = re.compile("^== backup of existing module file stored at %s" % toy_mod_bak, re.M)
15661589
self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout))
15671590
regex = re.compile("^== comparing module file with backup %s; no differences found$" % toy_mod_bak, re.M)
15681591
self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout))
1592+
self.assertEqual(stderr, '')
15691593

1594+
# tweak existing module file so we can verify diff of installed module with backup in stdout
15701595
write_file(toy_mod, "some difference\n", append=True)
15711596

15721597
self.mock_stderr(True)
@@ -1577,8 +1602,18 @@ def test_backup_modules(self):
15771602
self.mock_stderr(False)
15781603
self.mock_stdout(False)
15791604

1605+
if LooseVersion(lmod_version) < LooseVersion('7.0.0'):
1606+
backups_hidden += 1
1607+
else:
1608+
backups_visible += 1
1609+
1610+
lua_toy_mods = glob.glob(os.path.join(toy_mod_dir, '*.lua*'))
1611+
self.assertEqual(len(lua_toy_mods), 1)
1612+
self.assertEqual(os.path.basename(toy_mod), os.path.basename(lua_toy_mods[0]))
15801613
toy_mod_backups = glob.glob(os.path.join(toy_mod_dir, toy_mod_fn + '.bak_*'))
1581-
self.assertEqual(len(toy_mod_backups), 2)
1614+
self.assertEqual(len(toy_mod_backups), backups_visible)
1615+
hidden_toy_mod_backups = glob.glob(os.path.join(toy_mod_dir, '.' + toy_mod_fn + '.bak_*'))
1616+
self.assertEqual(len(hidden_toy_mod_backups), backups_hidden)
15821617

15831618
regex = re.compile("^== backup of existing module file stored at %s" % toy_mod_bak, re.M)
15841619
self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout))

0 commit comments

Comments
 (0)