-
Notifications
You must be signed in to change notification settings - Fork 41
add a guide for creating custom uenv environments #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
619fe9d
add a guide for creating custom uenv environments
bcumming b66dbe9
fix spelling
bcumming 91c0218
add more general bashrc advice
bcumming 6ac86eb
remove wip text
bcumming fab2a1d
fix spelling
bcumming ef6c993
Merge branch 'main' into uenv-bashrc
bcumming c6915e0
Update docs/guides/terminal.md
bcumming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -601,3 +601,66 @@ uenv image find @'*'%gh200 | |
|
|
||
| !!! note | ||
| The wild card `*` used for "all systems" must always be escaped in single quotes: `@'*'`. | ||
|
|
||
| [](){#ref-uenv-customenv} | ||
| ## Custom environments | ||
|
|
||
| !!! warning "[Keep bashrc clean][ref-guides-terminal-bashrc]" | ||
bcumming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| It is common practice to add `module` commands to `~.bashrc`, for example | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add somewhere that this practice of customization of programming environment through .bashrc is discouraged by CSCS. It is better to keep .bashrc "clean" and do all customizations in the separate script like presented below. |
||
| ```bash title="~/.bashrc" | ||
| # make my custom modules available | ||
| module use $STORE/myenv/modules | ||
| # load the modules that I always want in the environment | ||
| module load ncview | ||
| ``` | ||
|
|
||
| This will make custom modules available, and load `ncview`, every time you log in. | ||
| It is not possible to do the equivalent with `uenv start`, for example: | ||
| ```bash title="~/.bashrc" | ||
| # start the uenv that I always use | ||
| uenv start prgenv-gnu/24.11:v2 --view=default | ||
| # ERROR: the following lines will not be executed | ||
| module use $STORE/myenv/modules | ||
| module load ncview | ||
| ``` | ||
|
|
||
| !!! question "Why can't I use `uenv start` in `~/.bashrc`?" | ||
| The `module` command uses some "clever" tricks to modify the environment variables in your current shell. | ||
| For example, `module load ncview` will modify the value of environment variables like `PATH`, `LD_LIBRARY_PATH`, and `PKG_CONFIG_PATH`. | ||
|
|
||
| The `uenv start` command loads a uenv, and __starts a new shell__, ready for you to enter commands. | ||
| This means that lines in the `.bashrc` that follow the command are never executed. | ||
|
|
||
| Things are further complicated because if `uenv start` is executed inside `~/.bashrc`, the shell is not a tty shell. | ||
|
|
||
| It is possible to create a custom command that will start a new shell with a uenv loaded, with additional customizations to the environment (e.g. loading modules and setting environment variables). | ||
|
|
||
| The first step is to create a script that performs the the customization steps to perform once the uenv has been loaded. | ||
| Here is an example for an environment called `myenv`: | ||
|
|
||
| ```bash title="~/.myenvrc" | ||
| # always add this line | ||
| source ~/.bashrc | ||
|
|
||
| # then add customization commands here | ||
| module use $STORE/myenv/modules | ||
| module load ncview | ||
| export DATAPATH=$STORE/2025/data | ||
| ``` | ||
|
|
||
| Then create an alias in `~/.bashrc` for the `myenv` environment: | ||
|
|
||
| ```bash title="~/.bashrc" | ||
| alias myenv='uenv run prgenv-gnu/24.11:v2 --view=default -- bash --rcfile ~/.myenvrc' | ||
| ``` | ||
|
|
||
| This alias uses `uenv run` to start a new bash shell that will apply the customizations in `~/.myenvrc` once the uenv has been loaded. | ||
| Then, the environment can be started with a single command once logged in. | ||
|
|
||
| ```console | ||
| $ ssh eiger.cscs.ch | ||
| $ myenv | ||
| ``` | ||
|
|
||
| The benefit of this approach is that you can create multiple environments, whereas modifying `.bashrc` will lock you into using the same environment every time you log in. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.