Skip to content

Conversation

@xdelaruelle
Copy link
Contributor

Fix ModuleTool.load() to keep ModuleTool.mod_paths member in sync with MODULEPATH environment variable.

When purge mechanism was enabled in load(), restore_env() reset MODULEPATH but then ModuleTool.check_module_path() was called which set MODULEPATH back to the value kept in mod_paths member. This led to inconsistencies as loaded modules where purged but the MODULEPATH change made by a toolchain module was still there.

The proposed solution is to sync ModuleTool.mod_paths member with MODULEPATH right after environment reset. Thus ModuleTool.set_mod_paths() is called instead of ModuleTool.check_mod_paths().

Such fix requires that expected MODULEPATH changes are specified through the mod_paths argument of load(). So this PR also contains commits that fix external MODULEPATH change to transmit such change via mod_paths argument of load().

Fixes #4986
Fixes easybuilders/easybuild-easyconfigs#23675
Fixes easybuilders/easybuild-easyconfigs#17407
Fixes easybuilders/easybuild-easyconfigs#17368
Fixes easybuilders/easybuild-easyconfigs#23579

Create a test that demonstrates built module test issue with HMNS naming
scheme and Environment Modules.

Such issue occurs when built easyconfig has dependencies available in the
toolchain-specific modulepath but also in the Core modulepath but with
conflicting requirements (here ncurses 6.4 is required by
toolchain-specific gettext and util-linux modules whereas ncurses 6.3 is
required by Core gettext module).

Issue comes from the Core modulepath being put at the top priority in
the MODULEPATH environment variable. Thus wrong gettext module is loaded
(from Core modulepath).

Signed-off-by: Xavier Delaruelle <[email protected]>
Do not enable modulepath with a specific priority in
EasyBlock.load_fake_module() as this is useless:

* Support for path element priority in environment variable is only
  supported by Lmod

* As EasyBlock.load_fake_module() is always called with purge=True, so
  ModuleTool.load() is then run with purge enabled. Purge process unsets
  `__LMOD_Priority_MODULEPATH` environment variable, so the priority
  information is immediately lost.

Signed-off-by: Xavier Delaruelle <[email protected]>
Rely on EasyBlock.load_module() then ModuleTool.load() to enable
specific modulepath to use, rather locally calling
ModuleTool.prepend_module_path().

As load_fake_module() is always called with purge=True, it calls
load_module() then load() also with purge process enabled. Changing
modulepath from load_fake_module() then purging it in ModuleTool.load()
is problematic: it requires ModuleTool.mod_paths to be unsynced from
MODULEPATH environment variable to be able to set it back right after
the purge.

With this change, there is no more need for ModuleTool.mod_paths not to
be in sync with MODULEPATH.

Signed-off-by: Xavier Delaruelle <[email protected]>
Fix ModuleTool.load() to keep ModuleTool.mod_paths member in sync with
MODULEPATH environment variable.

When purge mecanism was enabled in load(), restore_env() reset
MODULEPATH but then ModuleTool.check_module_path() was called which set
MODULEPATH back to the value kept in mod_paths member. This led to
inconsistencies as loaded modules where purged but the MODULEPATH change
made by a toolchain module was still there.

Such inconsistency led to some build failure with Environment Modules
when using HMNS naming scheme: wrong modulepath order was achievied
leading to the load of wrong dependency modules. See listed issues
below.

The proposed solution is to sync ModuleTool.mod_paths member with
MODULEPATH right after environment reset. Thus
ModuleTool.set_mod_paths() is called instead of
ModuleTool.check_mod_paths().

Such fix requires that expected MODULEPATH changes are specified through
the mod_paths argument of load(). So previous commits have fixed
external MODULEPATH change to transmit such change via mod_paths
argument of load().

This commit also took the opportunity to fix lint warning on adjacent
code: restore_env() call is moved outside of else branch as the if
condition is throwing an exception.

Fixes easybuilders#4986
Fixes easybuilders/easybuild-easyconfigs#23675
Fixes easybuilders/easybuild-easyconfigs#17407
Fixes easybuilders/easybuild-easyconfigs#17368
Fixes easybuilders/easybuild-easyconfigs#23579

Signed-off-by: Xavier Delaruelle <[email protected]>
…alling set_mod_paths() after resetting environment in ModulesTool.load
Copy link
Member

@boegel boegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confident now that this is ready to merge.

@xdelaruelle Thanks a lot of the extensive effort on this!

@boegel boegel enabled auto-merge September 13, 2025 13:53
@boegel boegel merged commit d1631b4 into easybuilders:develop Sep 13, 2025
37 checks passed
@xdelaruelle xdelaruelle deleted the envmodules_hmns_build_2 branch September 13, 2025 14:38
@boegel boegel changed the title keep ModuleTool.mod_paths in sync with MODULEPATH in ModuleTool.load() keep ModuleTool.mod_paths in sync with $MODULEPATH in ModuleTool.load() Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment