Skip to content

Commit

Permalink
support for view and module loading by start and run commands (#31)
Browse files Browse the repository at this point in the history
This PR implements support for loading views and making modules available inside an environment via command line arguments to `start` and `run` commands.

```bash
# start with the view named develop loaded
uenv start --view=develop myenv

# start with modules available
uenv start --modules myenv

# run a command with modules available
uenv run --modules myenv -- bash -c "module load cray-mpich; mpicc test.c"

# run a command with a view loaded
uenv run --view=develop myenv -- mpicc test.c
```

* add `lib/envvars.py` that  implements classes that support setting and modifying environment variables.
    * support for `scalar` variables that take a single value and `list` variables (e.g. `PATH`) that are assembled by setting, appending and prepending paths.
    * support for accumulating operations on collections environment variables
    * support 
* instead of sourcing `activate.sh` when loading a view, the script is parsed and `export` commands is generated based its contents
    * this allows us to perform operations like overriding or preserving existing list variables
    * in the future this can be used to generate information required to deactivate a view
* changed the behavior of `uenv view` to preserve existing values of variables like `PATH`, `LD_LIBRARY_PATH`, etc
* add unit tests for the new environment variable code
  • Loading branch information
bcumming authored Jun 5, 2024
1 parent 05344d8 commit 3b5d8f0
Show file tree
Hide file tree
Showing 17 changed files with 789 additions and 35 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.1
5.0.0-dev
1 change: 1 addition & 0 deletions activate
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export UENV_CMD='env -u PYTHONPATH -u VIRTUAL_ENV @@impl@@'
export UENV_IMG_CMD='env -u PYTHONPATH -u VIRTUAL_ENV @@image_impl@@'
export UENV_VERSION=@@version@@
export UENV_PREFIX=@@prefix@@
export UENV_WRAPPER_CMD=@@wrapper@@

function uenv {
local _last_exitcode=$?
Expand Down
6 changes: 6 additions & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ echo "local install: $local_install"
libexec=${prefix}/libexec
impl_path="${libexec}/uenv-impl"
img_impl_path="${libexec}/uenv-image"
wrapper_path="${libexec}/uenv-wrapper"
lib_path="${libexec}/lib"
if [ "$local_install" == "no" ]
then
Expand All @@ -169,6 +170,7 @@ echo "installing $lib_path"
run install -v -m755 -d "$lib_path"
run install -v -m644 -D -t "${destdir}/${lib_path}" ${script_path}/lib/alps.py
run install -v -m644 -D -t "${destdir}/${lib_path}" ${script_path}/lib/datastore.py
run install -v -m644 -D -t "${destdir}/${lib_path}" ${script_path}/lib/envvars.py
run install -v -m644 -D -t "${destdir}/${lib_path}" ${script_path}/lib/jfrog.py
run install -v -m644 -D -t "${destdir}/${lib_path}" ${script_path}/lib/names.py
run install -v -m644 -D -t "${destdir}/${lib_path}" ${script_path}/lib/oras.py
Expand All @@ -179,6 +181,9 @@ run install -v -m644 -D -t "${destdir}/${lib_path}" ${script_path}/lib/terminal.
echo "installing ${img_impl_path}"
run install -v -m755 -D "$script_path/uenv-image" "${destdir}/${img_impl_path}"

echo "installing ${wrapper_path}"
run install -v -m755 -D "$script_path/uenv-wrapper" "${destdir}/${wrapper_path}"

echo "installing $impl_path"
run install -D -m755 <(sed "s|@@version@@|$version|g" $script_path/uenv-impl) ${destdir}/$impl_path

Expand Down Expand Up @@ -206,6 +211,7 @@ run install -v -m644 -D <(
-e "s|@@version@@|$version|g" \
-e "s|@@prefix@@|$prefix|g" \
-e "s|@@image_impl@@|$img_impl_path|g" \
-e "s|@@wrapper@@|$wrapper_path|g" \
$script_path/activate) \
$init_path

Expand Down
Loading

0 comments on commit 3b5d8f0

Please sign in to comment.