Skip to content

Add --priority option to prepend-path, append-path and use - #735

Merged
xdelaruelle merged 2 commits into
envmodules:mainfrom
xdelaruelle:issue185
Nov 9, 2026
Merged

xdelaruelle merged 2 commits into
envmodules:mainfrom
xdelaruelle:issue185

Conversation

@xdelaruelle

Copy link
Copy Markdown
Collaborator

Add a --priority option to the prepend-path and append-path modulefile commands and sub-commands, and to the use sub-command, to assign a priority to the added path elements. Prepended elements with the highest priority stay first in the path-like variable and appended elements with the highest priority stay last, whatever the modulefiles loaded afterward. Elements without priority are placed in between and keep their usual ordering, so existing modulefiles are not affected as long as no priority is set.

Priority values get the same meaning as on Lmod (0 means no priority, value bounded to 1000000). The option form is used rather than the trailing positional argument of Lmod, as these commands accept multiple path elements on Modules.

Priorities are recorded in the __MODULES_PRIORITY_<VAR> environment variable along with the name of the module setting them, so the ordering is kept across modulefile evaluations and the demands of a module are withdrawn when it is unloaded. A priority set on an element already in the variable is ignored unless path_entry_reorder is enabled, in which case it replaces the applying one and the element is moved, like the position of an element added several times is handled.

A priority on MODULEPATH changes the order modulepaths are searched, not the mechanisms reacting to modulepaths being enabled or disabled: a prioritized core modulepath keeps shadowing the branches enabled by a compiler module, while the modules loaded from these branches are still unloaded when the compiler module is.

The first commit adds a design note (doc/source/design/path-priority.rst) describing the ordering rule, the priority record, the interactions with the other features and the collection handling kept as future work.

Fixes #185

Describe how a priority can be assigned to the elements added to a
path-like variable with prepend-path and append-path, so that a given
directory persists at the first or last position of the variable
whatever the modules loaded afterward (issue envmodules#185).

Priority values get the same meaning than on Lmod, so people knowing
Lmod directly understand them: elements are grouped by priority, the
prepended elements with the highest priority come first and the
appended elements with the highest priority come last. Priority is
however set through a --priority option rather than a trailing
positional argument as on Lmod, since prepend-path and append-path
accept multiple path elements on Modules.

Each priority set on an element is recorded across evaluations in a
__MODULES_PRIORITY_<VAR> environment variable along with the name of
the module setting it, so the priority set by another module applies
again once this module is unloaded. The priority applying to an element
prioritized several times follows the path_entry_reorder configuration,
like the position of an element added several times does.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Introduce a --priority option on prepend-path and append-path
modulefile commands and sub-commands, and on the use sub-command, to
assign a priority to the added path elements. Elements of the path-like
variable are ordered by priority: prepended elements with the highest
priority stay first and appended elements with the highest priority
stay last, whatever the modulefiles loaded afterward. Elements without
priority are placed in between and keep their usual ordering, so
existing modulefiles are not affected as long as no priority is set.

Priority values get the same meaning than on Lmod. The option form is
used rather than the trailing positional argument of Lmod, as these
commands accept multiple path elements on Modules.

Each priority set on an element is recorded in the
__MODULES_PRIORITY_<VAR> environment variable along with the name of
the module setting it. A priority set on an element already in the
variable is ignored unless path_entry_reorder is enabled, in which case
it replaces the applying one and the element is moved, like the
position of an element added several times is handled. The priorities
set by a module are withdrawn when it is unloaded, so the priority
previously set by another module, if any, applies again: the element is
moved at once when path_entry_reorder is enabled, at the next addition
to the variable otherwise. Priority value is bounded to 1000000. The
record is cleared like the reference counter record by setenv, unsetenv
and pushenv and pruned when elements are removed from the variable.

A priority on MODULEPATH changes the order modulepaths are searched,
not the mechanisms reacting to modulepaths being enabled or disabled:
a prioritized core modulepath keeps shadowing the branches enabled by
a compiler module, while the modules loaded from these branches are
still unloaded when the compiler module is.

Fixes envmodules#185

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xdelaruelle
xdelaruelle merged commit 11631da into envmodules:main Nov 9, 2026
22 checks passed
@xdelaruelle
xdelaruelle deleted the issue185 branch November 9, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assigning priority weight on values to add to path-like variables

1 participant