Skip to content

Add modulepath-ignore command to filter out modulepath content - #682

Merged
xdelaruelle merged 11 commits into
envmodules:mainfrom
xdelaruelle:issue562
Aug 22, 2026
Merged

Add modulepath-ignore command to filter out modulepath content#682
xdelaruelle merged 11 commits into
envmodules:mainfrom
xdelaruelle:issue562

Conversation

@xdelaruelle

@xdelaruelle xdelaruelle commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Add the modulepath-ignore modulefile command to define, from rc files, gitignore-style patterns describing modulepath content to ignore when searching for modulefiles. Ignored files and directories are handled as if they do not exist: they are not checked, not walked down, not reported and not recorded in modulepath cache file. This solves the cachebuild time and memory issue observed when a modulepath contains a very large amount of non-modulefiles.

Patterns follow the same syntax and behavior as git with .gitignore files (negation, anchoring, **, character ranges, directory-only trailing slash). They are anchored to the directory of the rc file defining them; global and user rc files define global patterns applying to every modulepath.

To have patterns in place when modulepath content is walked through, rc file evaluation moves from the getModules consolidation phase to the walk procedure itself, which becomes depth-first: rc files of a directory are evaluated and recorded as soon as its content is fetched. The ignored_dirs option check and the historical backup file skip are integrated into the path ignore matcher.

The modulepath_ignore configuration option (enabled by default) and the --no-modulepath-ignore command line switch control whether pattern definitions are applied.

Design notes are provided in doc/source/design/modulepath-ignore.rst.

Fixes #562

Design notes for the modulepath-ignore modulefile command introduced
to solve issue envmodules#562.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Modulepath directories may contain files that are not modulefiles,
like helper scripts sourced by modulefiles or software installation
files when modulefiles are mixed with the software trees they
describe. These files are read to check if they are valid modulefiles
and recorded in cache files, which makes cachebuild take a huge
amount of time and memory when they are numerous.

Add the modulepath-ignore modulefile command to define from rc files
gitignore-style patterns describing modulepath content to ignore when
searching for modulefiles. Ignored files and directories are handled
as if they do not exist: they are not checked, not walked down, not
reported and not recorded in cache files.

Rc file evaluation entirely moves from getModules consolidation phase
to the modulepath walk procedure, so that the patterns rc files
define apply to the elements walked next. Walk becomes depth-first
with directory content processed in lexical order to preserve the rc
file evaluation order that module resolution and symbol definition
results depend on. Rc files recorded in cache are evaluated at walk
start, as their patterns may apply to the walked down limited access
elements.

Also add the modulepath_ignore configuration option, enabled by
default, and the --no-modulepath-ignore command line switch to
control whether pattern definitions are applied.

Fixes envmodules#562

Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Both modulepath walk procedures applied the ignored_dirs configuration
option check side by side with the isPathIgnored call. Move this check
into isPathIgnored as an early test made prior applying patterns, so
the behavior of this option is preserved: negated patterns cannot
re-include a matching directory and directories keep being ignored
when modulepath_ignore option is disabled.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Both modulepath walk procedures skipped backup or version control
files (*~, *,v and #*#) with a specific switch pattern set side by
side with the isPathIgnored call. Move this check into isPathIgnored
as an early test made prior applying patterns, like the ignored_dirs
option check: negated patterns cannot re-include these files and they
keep being ignored when modulepath_ignore option is disabled.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Rc files of a directory were evaluated when reached in the walked
element list, right after the directory content fetch that returns
them first. Evaluate and record them at fetch time instead, prior the
element list trimming made for the stop_mod optimization: the hiding
or ignore rules they may define are then in place for this trimming,
which does not need to source rc files on its own anymore.

Fetched directory content is turned into an array: rc files are
directly looked up by name in it then withdrawn once evaluated and
recorded, which lifts the need to get them first in the list returned
by getFilesInDirectory (Tcl implementation of this procedure is set
back to its original form). Remaining element paths, sorted in
lexical order, are transmitted to trimElemListForStopmod, which now
returns the trimmed list, and are then inserted in the walked list
right after current position: depth-first insertion is what matters
to evaluate the rc files of a sub-directory prior those of
directories lying next or deeper. Only the rc files that are not part
of a fetched directory content flow through the walked list and get
handled by the walk loop (modulepath root rc file from the initial
listing, limited access rc files from a cache file listing).

Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
@xdelaruelle
xdelaruelle merged commit ed28409 into envmodules:main Aug 22, 2026
20 checks passed
@xdelaruelle
xdelaruelle deleted the issue562 branch August 22, 2026 13:08
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.

Improve cache mechanism when modulepath contains a large amount of non-modulefiles

1 participant