summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-08-27 01:54:58 +0200
committerGitHub <noreply@github.com>2021-08-26 16:54:58 -0700
commit74389472abb5ed8200c5e83cf5f0775718ee8b4c (patch)
treebd084e54239c63826423df14db308e8785df1dea /lib
parentf5d4f5bdaca60f821426fc44f4da8143eacf1bd9 (diff)
downloadspack-74389472abb5ed8200c5e83cf5f0775718ee8b4c.tar.gz
spack-74389472abb5ed8200c5e83cf5f0775718ee8b4c.tar.bz2
spack-74389472abb5ed8200c5e83cf5f0775718ee8b4c.tar.xz
spack-74389472abb5ed8200c5e83cf5f0775718ee8b4c.zip
Make env (de)activate error with -e, -E, -D flags (#25625)
* Make sure that spack -e. env activate b and spack -e. env deactivate error * Add a test
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/env.py10
-rw-r--r--lib/spack/spack/test/cmd/env.py23
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/spack/spack/cmd/env.py b/lib/spack/spack/cmd/env.py
index 75d573f6fe..5d436624bd 100644
--- a/lib/spack/spack/cmd/env.py
+++ b/lib/spack/spack/cmd/env.py
@@ -88,6 +88,11 @@ def env_activate(args):
)
return 1
+ # Error out when -e, -E, -D flags are given, cause they are ambiguous.
+ if args.env or args.no_env or args.env_dir:
+ tty.die('Calling spack env activate with --env, --env-dir and --no-env '
+ 'is ambiguous')
+
if ev.exists(env) and not args.dir:
spack_env = ev.root(env)
short_name = env
@@ -137,6 +142,11 @@ def env_deactivate(args):
)
return 1
+ # Error out when -e, -E, -D flags are given, cause they are ambiguous.
+ if args.env or args.no_env or args.env_dir:
+ tty.die('Calling spack env deactivate with --env, --env-dir and --no-env '
+ 'is ambiguous')
+
if 'SPACK_ENV' not in os.environ:
tty.die('No environment is currently active.')
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index ea1c660804..d9d6f5483c 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -4,6 +4,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import glob
import os
+from argparse import Namespace
import pytest
from six import StringIO
@@ -11,6 +12,7 @@ from six import StringIO
import llnl.util.filesystem as fs
import llnl.util.link_tree
+import spack.cmd.env
import spack.environment as ev
import spack.hash_types as ht
import spack.modules
@@ -2632,3 +2634,24 @@ def test_query_develop_specs():
assert e.is_develop(Spec('mpich'))
assert not e.is_develop(Spec('mpileaks'))
+
+
+@pytest.mark.parametrize('method', [
+ spack.cmd.env.env_activate,
+ spack.cmd.env.env_deactivate
+])
+@pytest.mark.parametrize(
+ 'env,no_env,env_dir',
+ [
+ ('b', False, None),
+ (None, True, None),
+ (None, False, 'path/'),
+ ])
+def test_activation_and_deactiviation_ambiguities(method, env, no_env, env_dir, capsys):
+ """spack [-e x | -E | -D x/] env [activate | deactivate] y are ambiguous"""
+ args = Namespace(shell='sh', activate_env='a',
+ env=env, no_env=no_env, env_dir=env_dir)
+ with pytest.raises(SystemExit):
+ method(args)
+ _, err = capsys.readouterr()
+ assert 'is ambiguous' in err