Introduce a SPACK_PYTHON environment variable (#21222)
The SPACK_PYTHON environment variable can be set to a python interpreter to be used by the spack command. This allows the spack command itself to use a consistent and separate interpreter from whatever python might be used for package building.
This commit is contained in:
parent
7add9de2e5
commit
5a771bc8ad
5 changed files with 48 additions and 4 deletions
|
@ -10,9 +10,12 @@
|
|||
# Following line is a shell no-op, and starts a multi-line Python comment.
|
||||
# See https://stackoverflow.com/a/47886254
|
||||
""":"
|
||||
# prefer python3, then python, then python2
|
||||
for cmd in python3 python python2; do
|
||||
command -v > /dev/null $cmd && exec $cmd $0 "$@"
|
||||
# prefer SPACK_PYTHON environment variable, python3, python, then python2
|
||||
for cmd in "${SPACK_PYTHON:-}" python3 python python2; do
|
||||
if command -v > /dev/null "$cmd"; then
|
||||
export SPACK_PYTHON="$(command -v "$cmd")"
|
||||
exec "${SPACK_PYTHON}" "$0" "$@"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "==> Error: spack could not find a python interpreter!" >&2
|
||||
|
|
|
@ -75,6 +75,14 @@ shell integration for :ref:`certain commands <packaging-shell-support>`,
|
|||
If you do not want to use Spack's shell support, you can always just run
|
||||
the ``spack`` command directly from ``spack/bin/spack``.
|
||||
|
||||
When the ``spack`` command is executed it searches for an appropriate
|
||||
Python interpreter to use, which can be explicitly overridden by setting
|
||||
the ``SPACK_PYTHON`` environment variable. When sourcing the appropriate shell
|
||||
setup script, ``SPACK_PYTHON`` will be set to the interpreter found at
|
||||
sourcing time, ensuring future invocations of the ``spack`` command will
|
||||
continue to use the same consistent python version regardless of changes in
|
||||
the environment.
|
||||
|
||||
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
Check Installation
|
||||
|
|
|
@ -58,6 +58,18 @@ alias spack 'set _sp_args = (\!*); source $_spack_share_dir/csh/spack.c
|
|||
alias spacktivate 'spack env activate'
|
||||
alias _spack_pathadd 'set _pa_args = (\!*) && source $_spack_share_dir/csh/pathadd.csh'
|
||||
|
||||
# Identify and lock the python interpreter
|
||||
if (! $?SPACK_PYTHON) then
|
||||
setenv SPACK_PYTHON ""
|
||||
endif
|
||||
foreach cmd ("$SPACK_PYTHON" python3 python python2)
|
||||
command -v "$cmd" >& /dev/null
|
||||
if ($status == 0) then
|
||||
setenv SPACK_PYTHON `command -v "$cmd"`
|
||||
break
|
||||
endif
|
||||
end
|
||||
|
||||
# Set variables needed by this script
|
||||
_spack_pathadd PATH "$SPACK_ROOT/bin"
|
||||
eval `spack --print-shell-vars csh`
|
||||
|
|
|
@ -253,7 +253,7 @@ function match_flag -d "checks all combinations of flags ocurring inside of a st
|
|||
set -l _a (string sub -s 2 (string trim "x$argv[1]"))
|
||||
set -l _b (string sub -s 2 (string trim "x$argv[2]"))
|
||||
|
||||
if test -z "$_a" || test -z "$_b"
|
||||
if test -z "$_a" or test -z "$_b"
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -667,6 +667,19 @@ set -l sp_source_file (status -f) # name of current file
|
|||
|
||||
|
||||
|
||||
#
|
||||
# Identify and lock the python interpreter
|
||||
#
|
||||
for cmd in "$SPACK_PYTHON" python3 python python2
|
||||
set -l _sp_python (command -s "$cmd")
|
||||
if test $status -eq 0
|
||||
set -x SPACK_PYTHON $_sp_python
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Find root directory and add bin to path.
|
||||
#
|
||||
|
|
|
@ -326,6 +326,14 @@ if [ "$_sp_shell" = bash ]; then
|
|||
export -f _spack_shell_wrapper
|
||||
fi
|
||||
|
||||
# Identify and lock the python interpreter
|
||||
for cmd in "${SPACK_PYTHON:-}" python3 python python2; do
|
||||
if command -v > /dev/null "$cmd"; then
|
||||
export SPACK_PYTHON="$(command -v "$cmd")"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# make available environment-modules
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue