diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/location.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/main.py | 6 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/location.py | 22 |
3 files changed, 31 insertions, 5 deletions
diff --git a/lib/spack/spack/cmd/location.py b/lib/spack/spack/cmd/location.py index 2461074d88..3d0db9ab2a 100644 --- a/lib/spack/spack/cmd/location.py +++ b/lib/spack/spack/cmd/location.py @@ -56,7 +56,7 @@ def setup_parser(subparser): help="build directory for a spec " "(requires it to be staged first)") directories.add_argument( - '-e', '--env', action='store', + '-e', '--env', action='store', dest='location_env', help="location of an environment managed by spack") arguments.add_common_arguments(subparser, ['spec']) @@ -71,10 +71,10 @@ def location(parser, args): print(spack.paths.prefix) return - if args.env: - path = spack.environment.root(args.env) + if args.location_env: + path = spack.environment.root(args.location_env) if not os.path.isdir(path): - tty.die("no such environment: '%s'" % args.env) + tty.die("no such environment: '%s'" % args.location_env) print(path) return diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py index 334311fcf6..be07aa3e5c 100644 --- a/lib/spack/spack/main.py +++ b/lib/spack/spack/main.py @@ -528,6 +528,8 @@ class SpackCommand(object): Keyword Args: fail_on_error (optional bool): Don't raise an exception on error + global_args (optional list): List of global spack arguments: + simulates ``spack [global_args] [command] [*argv]`` Returns: (str): combined output and error as a string @@ -540,8 +542,10 @@ class SpackCommand(object): self.returncode = None self.error = None + prepend = kwargs['global_args'] if 'global_args' in kwargs else [] + args, unknown = self.parser.parse_known_args( - [self.command_name] + list(argv)) + prepend + [self.command_name] + list(argv)) fail_on_error = kwargs.get('fail_on_error', True) diff --git a/lib/spack/spack/test/cmd/location.py b/lib/spack/spack/test/cmd/location.py index 72c3912503..00fe46f8f0 100644 --- a/lib/spack/spack/test/cmd/location.py +++ b/lib/spack/spack/test/cmd/location.py @@ -19,6 +19,7 @@ pytestmark = pytest.mark.usefixtures('config', 'database') # location prints out "locations of packages and spack directories" location = SpackCommand('location') +env = SpackCommand('env') @pytest.fixture @@ -84,6 +85,27 @@ def test_location_env(mock_test_env): assert location('--env', test_env_name).strip() == env_dir +def test_location_env_flag_interference(mutable_mock_env_path, tmpdir): + """ + Tests that specifying an active environment using `spack -e x location ...` + does not interfere with the location command flags. + """ + + # create two environments + env('create', 'first_env') + env('create', 'second_env') + + global_args = ['-e', 'first_env'] + + # `spack -e first_env location -e second_env` should print the env + # path of second_env + assert 'first_env' not in location('-e', 'second_env', global_args=global_args) + + # `spack -e first_env location --packages` should not print + # the environment path of first_env. + assert 'first_env' not in location('--packages', global_args=global_args) + + def test_location_env_missing(): """Tests spack location --env.""" missing_env_name = 'missing-env' |