Skip to content

Update order of entries in path environment variable #595

Closed

Description

@xdelaruelle

Currently when a prepend-path, append-path or module use target a path entry that is already defined in the environment variable, its value is not updated.

A configuration option may be introduced to update the order of entries, for instance on a prepend-path to move the path entry at the first position.

This is the behavior used by default on Lmod. And Lmod has LMOD_TMOD_PATH_RULE to set the behavior like on Modules.

This topic was approached long ago on #60.

Activity

  1. gsell commented on Oct 27, 2025

    @gsell
    Contributor

    I took a look at this issue. I noticed the following: In the getReferenceCountArray procedure, the counter is always 1 - even if, for example, a directory appears multiple times in MODULEPATH. In the for loop refcount($elt) is never set, so count will be always set to 1:

          foreach elt $eltlist {
             # no reference counter, means value has been set once
             if {![info exists refcount($elt)]} {
                set count 1
             # bad reference counter value is ignored
             } elseif {![string is digit -strict $refcount($elt)] ||\
                $refcount($elt) < 1} {
                reportDebug "Reference counter value for '$elt' in '$sharevar' is\
                   erroneous ($refcount($elt))"
                set count 1
             } else {
                set count $refcount($elt)
             }
             set countarr($elt) $count
          }
    
  2. xdelaruelle commented on Oct 27, 2025

    @xdelaruelle
    CollaboratorAuthor

    I took a look at this issue. I noticed the following: In the getReferenceCountArray procedure, the counter is always 1 - even if, for example, a directory appears multiple times in MODULEPATH. In the for loop refcount($elt) is never set, so count will be always set to 1:

    This is true if the reference counter variable (__MODULES_SHARE_<ENVVAR>) is not set . This variable is updated if an entry is added in duplicate mode.

  3. gsell commented on Oct 29, 2025

    @gsell
    Contributor

    Ok, understood!

  4. gsell commented on Oct 29, 2025

    @gsell
    Contributor

    I created a PR for this issue. This PR adds a config option lmod_path_rule (not sure whether this is a good name). Should this be applied for all path manipulations or MODULEPATH only? For now I implemented it in proc add-path for all paths.

    Tests for this change are still missing.

  5. xdelaruelle commented on Nov 2, 2025

    @xdelaruelle
    CollaboratorAuthor

    Good candidates for option name: update_path_order, path_entry_reorder

  6. gsell commented on Nov 21, 2025

    @gsell
    Contributor

    What is the correct behaviour in the following (edge-)case:

    $ module config path_entry_reorder 0
    $ module append-path --duplicates PATHVAR a
    $ module append-path --duplicates PATHVAR a
    $ module append-path --duplicates PATHVAR b
    $ module config path_entry_reorder 1
    $ module append-path PATHVAR a
    

    ? PATHVAR == {a:a:b:a} (precedence of duplicates) or PATHVAR == {b:a}

  7. xdelaruelle commented on Nov 21, 2025

    @xdelaruelle
    CollaboratorAuthor

    PATHVAR == {b:a}: last append-path call is not made with --duplicates option, so all occurences are merged and moved to the end of the list.

  8. added this to the 5.7.0 milestone on Jan 10, 2026
  9. added a commit that references this issue on Jan 18, 2026
    34b2f2c
  10. added a commit that references this issue on Jan 19, 2026
    1122fef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions