Skip to content

Commit 140892d

Browse files
author
Robert McLay
committed
Merging main onto IS780-cache branch
2 parents ec005a0 + a641e5d commit 140892d

9 files changed

Lines changed: 140 additions & 12 deletions

File tree

.github/workflows/docs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
with:
1313
python-version: 3.8
1414
- name: install sphinx
15-
run: pip install sphinx
15+
run: |
16+
cd docs
17+
pip install -r requirements.txt
1618
- name: Build documentation
1719
run: |
1820
cd docs

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ STANDALONE_PRGM := src/lmod.in.lua src/addto.in.lua
150150
STANDALONE_PRGM := $(patsubst %, $(srcdir)/%, $(STANDALONE_PRGM))
151151
SHELL_INIT := bash.in cmake csh.in ksh.in tcsh.in zsh.in sh.in perl R \
152152
env_modules_python.py.in lmod_bash_completions fish.in \
153-
lisp env_modules_ruby.rb.in rc.in
153+
lisp env_modules_ruby.rb.in rc.in nushell.in
154154
SHELL_INIT := $(patsubst %, $(srcdir)/init/%, $(SHELL_INIT))
155155
LMODRC_INIT := $(patsubst %, $(srcdir)/init/%, lmodrc.lua)
156156

README.new

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ Lmod 8.7+
250250
expand varT key-value pairs.
251251
W.I.P:
252252
* Issue #704: Support for nushell command generation added.
253+
* PR #784: merged in startup and docs for nushell.
253254
* Added conversion from old tm format to new with l_convertOldtm(tm) in src/MRC.lua
254255
* Issue #778: Only quit searching when there is no entry in v.dirT (in collectFileA())
255256
* Issue #780: In ModuleA:update, copy correct entry into new moduleA[#moduleA+1]

docs/requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
docutils<0.18
2-
sphinx==1.8.5
1+
docutils
2+
sphinx
3+
sphinxcontrib-mermaid

docs/source/030_installing.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ it must be defined before the z00_lmod.\* file is source.
310310
will be when z00_lmod.\* is run.
311311
312312
The ``profile`` file is the Lmod initialization script for the bash and zsh
313-
shells, the ``cshrc`` file is for tcsh and csh shells, and the ``profile.fish``
314-
file is for the fish shell, etc. Please copy or link the ``profile`` and ``cshrc``
315-
files to ``/etc/profile.d``, and optionally the fish file to ``/etc/fish/conf.d``::
313+
shells, the ``cshrc`` file is for tcsh and csh shells, the ``profile.fish``
314+
file is for the fish shell, and the ``nushell`` file is for the nushell shell.
315+
Please copy or link the ``profile`` and ``cshrc`` files to ``/etc/profile.d``,
316+
and optionally the fish file to ``/etc/fish/conf.d`` and the nushell file to
317+
the appropriate nushell configuration directory::
316318

317319
$ ln -s /opt/apps/lmod/lmod/init/profile /etc/profile.d/z00_lmod.sh
318320
$ ln -s /opt/apps/lmod/lmod/init/cshrc /etc/profile.d/z00_lmod.csh
@@ -491,6 +493,19 @@ A site might set::
491493

492494
$ ln -s /opt/apps/lmod/lmod/init/profile.fish /etc/fish/conf.d/z00_lmod.fish
493495

496+
Nushell:
497+
~~~~~~~~
498+
499+
Nushell users can use the special nushell module
500+
``init/nushell`` that can be loaded using nushell's overlay system.
501+
The nushell configuration file can be found at ``$nu.config-path``.
502+
For example, a user might add to their ``config.nu`` file::
503+
504+
overlay use /opt/apps/lmod/lmod/init/nushell
505+
506+
This provides the ``lmod-module``, ``lmod-ml``, ``lmod-clear-mt``, and ``lmod-clear``
507+
commands. Note that nushell requires using ``overlay use`` instead of ``source`` due to
508+
its module system and parse-time command resolution requirements.
494509

495510
.. _issues-with-bash:
496511

docs/source/443_structure.rst

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,43 @@ executing core logic to determine necessary environment changes, loading and
1717
evaluating modulefiles in a controlled sandbox, managing environment variables,
1818
and finally formatting the output as shell commands.
1919

20-
.. figure:: /_static/Lmod_Architecture.png
21-
:alt: Lmod High-Level Architecture Diagram
20+
.. mermaid::
2221
:align: center
22+
:alt: Lmod High-Level Architecture Diagram
2323

24-
(Conceptual Diagram - A real diagram would be created and referenced here)
24+
graph TD
25+
subgraph "User's Shell"
26+
A["User Command<br/>(e.g., 'module load gcc')"]
27+
end
28+
29+
A --> B["1. Command Line Parser<br/>'lmod.in.lua'<br/>Interprets the command and its arguments"];
30+
31+
B --> C["2. Core Logic (MCP)<br/>'MainControl.lua'<br/>Orchestrates the loading process"];
32+
33+
C -- "Request to find module" --> D["3. Module File Loader<br/>'Hub.lua'<br/>Resolves module name to a file path"];
34+
35+
D -- "Located at" --> E["Modulefile<br/>(e.g., '/path/to/gcc.lua')"];
36+
37+
E -- "Passes Lua code to" --> F;
38+
39+
subgraph "4. Sandbox Environment ('sandbox.lua')"
40+
direction LR
41+
F["Modulefile Code<br/>(e.g., 'prepend_path(...)')"] --> G["Lmod API<br/>'modfuncs.lua'"];
42+
end
43+
44+
G -- "Instructs MCP to record changes" --> H;
45+
46+
subgraph "5. Environment Variable Manager"
47+
H["'varT' (Variable Table)<br/>A list of all proposed environment<br/>changes is built and managed by the MCP"];
48+
end
49+
50+
H -- "Final list of changes (varT) passed to" --> I["6. Output Formatter<br/>'shells/*.lua'<br/>Translates 'varT' into shell-specific code"];
51+
52+
I -- "Generates" --> J;
53+
54+
subgraph "User's Shell"
55+
J["Shell Commands<br/>(e.g., 'export PATH=...')<br/>Printed to standard output"];
56+
end
2557

2658
Key Architectural Components:
2759
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# Add any Sphinx extension module names here, as strings. They can be
3030
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3131
# ones.
32-
extensions = []
32+
extensions = ['sphinxcontrib.mermaid']
3333

3434
# Add any paths that contain templates here, relative to this directory.
3535
templates_path = ['_templates']

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ found.
4848

4949
Packages can be loaded and unloaded cleanly through the module
5050
system. All the popular shells are supported: bash, ksh, rc, csh, tcsh,
51-
fish, zsh. Also available for perl, python, lisp, cmake, and R.
51+
fish, zsh, nushell. Also available for perl, python, lisp, cmake, and R.
5252

5353
It is also very easy to switch between different versions of a package
5454
or remove it.

init/nushell.in

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
export-env {
2+
$env.LMOD_ROOT = "@lmod_root@"
3+
$env.LMOD_PKG = "@PKG@"
4+
$env.LMOD_DIR = "@PKG@/libexec"
5+
$env.LMOD_CMD = "@PKG@/libexec/lmod"
6+
$env.MODULESHOME = "@PKG@"
7+
$env.LMOD_SETTARG_FULL_SUPPORT = "@lmod_settarg_full_support@"
8+
$env.LMOD_VERSION = "@lmod_version@"
9+
}
10+
11+
def --env lmod-eval [script: string] {
12+
# Split the lmod output into environment assignments and regular output
13+
let lines = ($script | lines)
14+
15+
# Filter out environment variable assignments and regular output
16+
let env_lines = ($lines | where { |line| $line starts-with '$env.' })
17+
let output_lines = ($lines | where { |line| not ($line starts-with '$env.') })
18+
19+
# Show regular output to user
20+
$output_lines | each { |line| print $line }
21+
22+
# Execute environment assignments by parsing and applying them manually
23+
for env_line in $env_lines {
24+
if ($env_line | str contains " = ") {
25+
let split_result = ($env_line | split column " = " var_name var_value)
26+
let var_name = ($split_result.var_name.0 | str replace '$env.' '')
27+
let var_value = ($split_result.var_value.0 | str trim --char ';' | str trim)
28+
29+
# Handle different value types
30+
if ($var_value | str starts-with 'r#') and ($var_value | str ends-with '#') {
31+
# Raw string value - extract the content
32+
let content = ($var_value | str substring 3..(-2))
33+
load-env {$var_name: $content}
34+
} else if ($var_value | str starts-with '[') and ($var_value | str ends-with ']') {
35+
# Array/list value - convert raw strings to regular strings then parse
36+
let clean_array = ($var_value | str replace --all "r#'" "'" | str replace --all "'#" "'")
37+
try {
38+
let array_val = ($clean_array | from nuon)
39+
load-env {$var_name: $array_val}
40+
} catch {
41+
# If NUON parsing fails, treat as a simple string
42+
load-env {$var_name: $var_value}
43+
}
44+
} else {
45+
# Regular value - might be quoted string
46+
let clean_value = ($var_value | str trim --char "'" | str trim --char '"')
47+
load-env {$var_name: $clean_value}
48+
}
49+
}
50+
}
51+
}
52+
53+
export def --wrapped --env lmod-module [...args] {
54+
lmod-eval (^@PKG@/libexec/lmod nushell ...$args)
55+
if ($env.LMOD_SETTARG_CMD? | default ":") != ":" {
56+
lmod-eval (^$env.LMOD_SETTARG_CMD -s nushell)
57+
}
58+
}
59+
60+
export def --wrapped --env lmod-ml [...args] {
61+
lmod-eval (^@PKG@/libexec/ml_cmd ...$args)
62+
}
63+
64+
export def --env lmod-clear-mt [] {
65+
lmod-eval (^@PKG@/libexec/clearLMOD_cmd --shell nushell --simple)
66+
}
67+
68+
export def --wrapped --env lmod-clear [...args] {
69+
lmod-eval (^@PKG@/libexec/lmod nushell --force purge)
70+
lmod-eval (^@PKG@/libexec/clearLMOD_cmd --shell nushell --full ...$args)
71+
}
72+
73+
export def --wrapped --env lmod-settarg [...args] {
74+
if ($env.LMOD_SETTARG_CMD? | default ":") != ":" {
75+
lmod-eval (^$env.LMOD_SETTARG_CMD -s nushell ...$args)
76+
}
77+
}

0 commit comments

Comments
 (0)