summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2020-01-16 15:46:18 -0600
committerGitHub <noreply@github.com>2020-01-16 15:46:18 -0600
commit808c80d65ae2e19e79a14a7ecfb67d2788954aaf (patch)
tree533f248af4e540dbe701a4906fa1c5560f2e3428 /lib
parent7a61d1dbd1b7c16f65c03aab28619d581b28fe7c (diff)
downloadspack-808c80d65ae2e19e79a14a7ecfb67d2788954aaf.tar.gz
spack-808c80d65ae2e19e79a14a7ecfb67d2788954aaf.tar.bz2
spack-808c80d65ae2e19e79a14a7ecfb67d2788954aaf.tar.xz
spack-808c80d65ae2e19e79a14a7ecfb67d2788954aaf.zip
Fix use of sys.executable for module/env commands (#14496)
* Fix use of sys.executable for module/env commands * Fix unit tests * More consistent quotation, less duplication * Fix import syntax
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/util/environment.py5
-rw-r--r--lib/spack/spack/util/module_cmd.py5
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py
index 489cafa1e1..18a365dcef 100644
--- a/lib/spack/spack/util/environment.py
+++ b/lib/spack/spack/util/environment.py
@@ -17,6 +17,7 @@ import six
import llnl.util.tty as tty
import spack.util.executable as executable
+from spack.util.module_cmd import py_cmd
from llnl.util.lang import dedupe
@@ -918,8 +919,8 @@ def environment_after_sourcing_files(*files, **kwargs):
source_file.extend(x for x in file_and_args)
source_file = ' '.join(source_file)
- dump_cmd = 'import os, json; print(json.dumps(dict(os.environ)))'
- dump_environment = sys.executable + ' -c "{0}"'.format(dump_cmd)
+ dump_environment = 'PYTHONHOME="{0}" "{1}" -c "{2}"'.format(
+ sys.prefix, sys.executable, py_cmd)
# Try to source the file
source_file_arguments = ' '.join([
diff --git a/lib/spack/spack/util/module_cmd.py b/lib/spack/spack/util/module_cmd.py
index 0edf7e6102..f7716854c7 100644
--- a/lib/spack/spack/util/module_cmd.py
+++ b/lib/spack/spack/util/module_cmd.py
@@ -18,7 +18,7 @@ import llnl.util.tty as tty
# This list is not exhaustive. Currently we only use load and unload
# If we need another option that changes the environment, add it here.
module_change_commands = ['load', 'swap', 'unload', 'purge', 'use', 'unuse']
-py_cmd = "'import os;import json;print(json.dumps(dict(os.environ)))'"
+py_cmd = 'import os; import json; print(json.dumps(dict(os.environ)))'
# This is just to enable testing. I hate it but we can't find a better way
_test_mode = False
@@ -32,7 +32,8 @@ def module(*args):
if args[0] in module_change_commands:
# Do the module manipulation, then output the environment in JSON
# and read the JSON back in the parent process to update os.environ
- module_cmd += ' >/dev/null;' + sys.executable + ' -c %s' % py_cmd
+ module_cmd += ' > /dev/null; PYTHONHOME="{0}" "{1}" -c "{2}"'.format(
+ sys.prefix, sys.executable, py_cmd)
module_p = subprocess.Popen(module_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,