env: remove all -e arguments on subcommands

- add and remove now require an active environment
- update tests to use with <ENV> instead of -e
This commit is contained in:
Todd Gamblin 2018-10-27 11:02:21 -07:00
parent d483e6e17b
commit 08e4720ed9
2 changed files with 25 additions and 18 deletions

View File

@ -61,13 +61,16 @@ def get_env(args, cmd_name, fail_on_error=True):
"""
env = args.env
if not env:
env = os.environ.get('SPACK_ENV')
if not env:
if not fail_on_error:
return None
tty.die(
'spack env %s requires an active environment or an argument'
% cmd_name)
if ev.active:
return ev.active
elif not fail_on_error:
return None
tty.die(
'`spack env %s` requires an environment' % cmd_name,
'activate an environment first:',
' spack env activate ENV',
'or use:',
' spack -e ENV %s ...' % cmd_name)
environment = ev.disambiguate(env)
@ -308,8 +311,6 @@ def env_list(args):
#
def env_add_setup_parser(subparser):
"""add a spec to an environment"""
subparser.add_argument(
'-e', '--env', help='add spec to this environment')
subparser.add_argument(
'specs', nargs=argparse.REMAINDER, help="spec of the package to add")
@ -331,8 +332,6 @@ def env_add(args):
#
def env_remove_setup_parser(subparser):
"""remove a spec from an environment"""
subparser.add_argument(
'-e', '--env', help='remove spec with this name from environment')
subparser.add_argument(
'-a', '--all', action='store_true', dest='all',
help="Remove all specs from (clear) the environment")

View File

@ -144,18 +144,23 @@ def test_remove_after_concretize():
def test_remove_command():
env('create', 'test')
env('add', '-e', 'test', 'mpileaks')
with ev.read('test'):
env('add', 'mpileaks')
assert 'mpileaks' in env('status', 'test')
env('remove', '-e', 'test', 'mpileaks')
with ev.read('test'):
env('remove', 'mpileaks')
assert 'mpileaks' not in env('status', 'test')
env('add', '-e', 'test', 'mpileaks')
with ev.read('test'):
env('add', 'mpileaks')
assert 'mpileaks' in env('status', 'test')
env('concretize', 'test')
assert 'mpileaks' in env('status', 'test')
env('remove', '-e', 'test', 'mpileaks')
with ev.read('test'):
env('remove', 'mpileaks')
assert 'mpileaks' not in env('status', 'test')
@ -478,7 +483,9 @@ def test_bad_env_yaml_format(tmpdir):
def test_env_loads(install_mockery, mock_fetch):
env('create', 'test')
env('add', '-e', 'test', 'mpileaks')
with ev.read('test'):
env('add', 'mpileaks')
env('concretize', 'test')
env('install', '--fake', 'test')
env('loads', 'test')
@ -496,8 +503,9 @@ def test_env_loads(install_mockery, mock_fetch):
@pytest.mark.disable_clean_stage_check
def test_env_stage(mock_stage, mock_fetch, install_mockery):
env('create', 'test')
env('add', '-e', 'test', 'mpileaks')
env('add', '-e', 'test', 'zmpi')
with ev.read('test'):
print env('add', 'mpileaks')
print env('add', 'zmpi')
env('concretize', 'test')
env('stage', 'test')