summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/cmd/python.py7
-rw-r--r--lib/spack/spack/test/cmd/python.py6
-rwxr-xr-xshare/spack/spack-completion.bash2
3 files changed, 14 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/python.py b/lib/spack/spack/cmd/python.py
index 588ddce853..5cee319ff5 100644
--- a/lib/spack/spack/cmd/python.py
+++ b/lib/spack/spack/cmd/python.py
@@ -34,6 +34,9 @@ def setup_parser(subparser):
'-m', dest='module', action='store',
help='run library module as a script')
subparser.add_argument(
+ '--path', action='store_true', dest='show_path',
+ help='show path to python interpreter that spack uses')
+ subparser.add_argument(
'python_args', nargs=argparse.REMAINDER,
help="file to run plus arguments")
@@ -43,6 +46,10 @@ def python(parser, args, unknown_args):
print('Python', platform.python_version())
return
+ if args.show_path:
+ print(sys.executable)
+ return
+
if args.module:
sys.argv = ['spack-python'] + unknown_args + args.python_args
runpy.run_module(args.module, run_name="__main__", alter_sys=True)
diff --git a/lib/spack/spack/test/cmd/python.py b/lib/spack/spack/test/cmd/python.py
index 360d947a07..d2ef35a85e 100644
--- a/lib/spack/spack/test/cmd/python.py
+++ b/lib/spack/spack/test/cmd/python.py
@@ -4,6 +4,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import platform
+import sys
import pytest
@@ -18,6 +19,11 @@ def test_python():
assert out.strip() == spack.spack_version
+def test_python_interpreter_path():
+ out = python('--path')
+ assert out.strip() == sys.executable
+
+
def test_python_version():
out = python('-V')
assert platform.python_version() in out
diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash
index 4653a753b7..62645bd6ac 100755
--- a/share/spack/spack-completion.bash
+++ b/share/spack/spack-completion.bash
@@ -1385,7 +1385,7 @@ _spack_pydoc() {
_spack_python() {
if $list_options
then
- SPACK_COMPREPLY="-h --help -V --version -c -i -m"
+ SPACK_COMPREPLY="-h --help -V --version -c -i -m --path"
else
SPACK_COMPREPLY=""
fi