summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2023-11-06 07:53:26 +0100
committerGitHub <noreply@github.com>2023-11-05 22:53:26 -0800
commit3c641c85097cef24cbea238f2254ced90f57bd2c (patch)
tree44849b19551b4d1ff6cd6a8f0a0f9627c706e2ec /share
parent141c7de5d89f32b203438e1d6fca1efd817299f7 (diff)
downloadspack-3c641c85097cef24cbea238f2254ced90f57bd2c.tar.gz
spack-3c641c85097cef24cbea238f2254ced90f57bd2c.tar.bz2
spack-3c641c85097cef24cbea238f2254ced90f57bd2c.tar.xz
spack-3c641c85097cef24cbea238f2254ced90f57bd2c.zip
spack env activate: create & activate default environment without args (#40756)
This PR implements the concept of "default environment", which doesn't have to be created explicitly. The aim is to lower the barrier for adopting environments. To (create and) activate the default environment, run ``` $ spack env activate ``` This mimics the behavior of ``` $ cd ``` which brings you to your home directory. This is not a breaking change, since `spack env activate` without arguments currently errors. It is similar to the already existing `spack env activate --temp` command which always creates an env in a temporary directory, the difference is that the default environment is a managed / named environment named `default`. The name `default` is not a reserved name, it's just that `spack env activate` creates it for you if you don't have it already. With this change, you can get started with environments faster: ``` $ spack env activate [--prompt] $ spack install --add x y z ``` instead of ``` $ spack env create default ==> Created environment 'default in /Users/harmenstoppels/spack/var/spack/environments/default ==> You can activate this environment with: ==> spack env activate default $ spack env activate [--prompt] default $ spack install --add x y z ``` Notice that Spack supports switching (but not stacking) environments, so the parallel with `cd` is pretty clear: ``` $ spack env activate named_env $ spack env status ==> In environment named_env $ spack env activate $ spack env status ==> In environment default ```
Diffstat (limited to 'share')
-rwxr-xr-xshare/spack/qa/setup-env-test.fish6
-rwxr-xr-xshare/spack/qa/setup-env-test.sh6
-rwxr-xr-xshare/spack/setup-env.sh3
3 files changed, 11 insertions, 4 deletions
diff --git a/share/spack/qa/setup-env-test.fish b/share/spack/qa/setup-env-test.fish
index 6474917b70..589f4cbfa8 100755
--- a/share/spack/qa/setup-env-test.fish
+++ b/share/spack/qa/setup-env-test.fish
@@ -371,7 +371,6 @@ spt_contains " spack env list " spack env list --help
title 'Testing `spack env activate`'
spt_contains "No such environment:" spack env activate no_such_environment
-spt_contains "env activate requires an environment " spack env activate
spt_contains "usage: spack env activate " spack env activate -h
spt_contains "usage: spack env activate " spack env activate --help
@@ -415,6 +414,11 @@ spt_contains 'spack_test_2_env' 'fish' '-c' 'echo $PATH'
spt_does_not_contain 'spack_test_env' 'fish' '-c' 'echo $PATH'
despacktivate
+echo "Testing default environment"
+spack env activate
+contains "In environment default" spack env status
+despacktivate
+
echo "Correct error exit codes for activate and deactivate"
spt_fails spack env activate nonexisiting_environment
spt_fails spack env deactivate
diff --git a/share/spack/qa/setup-env-test.sh b/share/spack/qa/setup-env-test.sh
index 4172a40155..b26619b9cd 100755
--- a/share/spack/qa/setup-env-test.sh
+++ b/share/spack/qa/setup-env-test.sh
@@ -140,7 +140,6 @@ contains " spack env list " spack env list --help
title 'Testing `spack env activate`'
contains "No such environment:" spack env activate no_such_environment
-contains "env activate requires an environment " spack env activate
contains "usage: spack env activate " spack env activate -h
contains "usage: spack env activate " spack env activate --help
@@ -197,6 +196,11 @@ contains "spack_test_2_env" sh -c 'echo $PATH'
does_not_contain "spack_test_env" sh -c 'echo $PATH'
despacktivate
+echo "Testing default environment"
+spack env activate
+contains "In environment default" spack env status
+despacktivate
+
echo "Correct error exit codes for activate and deactivate"
fails spack env activate nonexisiting_environment
fails spack env deactivate
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 91a601e652..a42882266c 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -126,8 +126,7 @@ _spack_shell_wrapper() {
# Space needed here to differentiate between `-h`
# argument and environments with "-h" in the name.
# Also see: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion
- if [ -z ${1+x} ] || \
- [ "${_a#* --sh}" != "$_a" ] || \
+ if [ "${_a#* --sh}" != "$_a" ] || \
[ "${_a#* --csh}" != "$_a" ] || \
[ "${_a#* -h}" != "$_a" ] || \
[ "${_a#* --help}" != "$_a" ];