Make 'spack location -e' print the current env, and 'spack cd -e' go to the current env (#26654)
This commit is contained in:
parent
7f4bf2b2e1
commit
3fa0654d0b
@ -56,8 +56,8 @@ def setup_parser(subparser):
|
|||||||
help="build directory for a spec "
|
help="build directory for a spec "
|
||||||
"(requires it to be staged first)")
|
"(requires it to be staged first)")
|
||||||
directories.add_argument(
|
directories.add_argument(
|
||||||
'-e', '--env', action='store', dest='location_env',
|
'-e', '--env', action='store', dest='location_env', nargs='?', metavar="name",
|
||||||
help="location of an environment managed by spack")
|
default=False, help="location of the named or current environment")
|
||||||
|
|
||||||
arguments.add_common_arguments(subparser, ['spec'])
|
arguments.add_common_arguments(subparser, ['spec'])
|
||||||
|
|
||||||
@ -71,10 +71,17 @@ def location(parser, args):
|
|||||||
print(spack.paths.prefix)
|
print(spack.paths.prefix)
|
||||||
return
|
return
|
||||||
|
|
||||||
if args.location_env:
|
# no -e corresponds to False, -e without arg to None, -e name to the string name.
|
||||||
path = ev.root(args.location_env)
|
if args.location_env is not False:
|
||||||
if not os.path.isdir(path):
|
if args.location_env is None:
|
||||||
tty.die("no such environment: '%s'" % args.location_env)
|
# Get current environment path
|
||||||
|
spack.cmd.require_active_env('location -e')
|
||||||
|
path = ev.active_environment().path
|
||||||
|
else:
|
||||||
|
# Get named environment path
|
||||||
|
if not ev.exists(args.location_env):
|
||||||
|
tty.die("no such environment: '%s'" % args.location_env)
|
||||||
|
path = ev.root(args.location_env)
|
||||||
print(path)
|
print(path)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -23,17 +23,6 @@
|
|||||||
env = SpackCommand('env')
|
env = SpackCommand('env')
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def mock_test_env():
|
|
||||||
test_env_name = 'test'
|
|
||||||
env_dir = ev.root(test_env_name)
|
|
||||||
mkdirp(env_dir)
|
|
||||||
yield test_env_name, env_dir
|
|
||||||
|
|
||||||
# Remove the temporary test environment directory created above
|
|
||||||
shutil.rmtree(env_dir)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_spec():
|
def mock_spec():
|
||||||
spec = spack.spec.Spec('externaltest').concretized()
|
spec = spack.spec.Spec('externaltest').concretized()
|
||||||
@ -82,10 +71,19 @@ def test_location_cmd_error(options):
|
|||||||
location(*options)
|
location(*options)
|
||||||
|
|
||||||
|
|
||||||
def test_location_env(mock_test_env):
|
def test_location_env_exists(mutable_mock_env_path):
|
||||||
"""Tests spack location --env."""
|
"""Tests spack location --env <name> for an existing environment."""
|
||||||
test_env_name, env_dir = mock_test_env
|
e = ev.create("example")
|
||||||
assert location('--env', test_env_name).strip() == env_dir
|
e.write()
|
||||||
|
assert location('--env', "example").strip() == e.path
|
||||||
|
|
||||||
|
|
||||||
|
def test_location_with_active_env(mutable_mock_env_path):
|
||||||
|
"""Tests spack location --env with active env"""
|
||||||
|
e = ev.create("example")
|
||||||
|
e.write()
|
||||||
|
with e:
|
||||||
|
assert location('--env').strip() == e.path
|
||||||
|
|
||||||
|
|
||||||
def test_location_env_flag_interference(mutable_mock_env_path, tmpdir):
|
def test_location_env_flag_interference(mutable_mock_env_path, tmpdir):
|
||||||
|
Loading…
Reference in New Issue
Block a user