From 9bffa967546a061022f4d8bcae3cb4f63874b614 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 15 Nov 2017 17:38:40 -0700 Subject: Reduce the calls to the python interpreter during initialization (#6312) * Reduce the calls to the python interpreter during initialization This should reduce the delay the users experience when sourcing the setup file to activate shell support. It works by generating at once all the commands that needs to evaluated (they are stored in a string and later `eval`ed by the shell). * setup_env.sh: changed `read` with an equivalent magic For some reason `read` breaks when sourced from a running script. Change the incantation we use to construct the unique python command that will be evaluated. * setup_env.sh: python command now constructed with `printf` for portability This recovers the support for `zsh` that was broken in previous commits. --- share/spack/setup-env.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh index 21a7e00345..38bcac03a9 100755 --- a/share/spack/setup-env.sh +++ b/share/spack/setup-env.sh @@ -236,9 +236,16 @@ fi; # # Set up modules and dotkit search paths in the user environment # -_sp_sys_type=$(spack-python -c 'print(spack.architecture.sys_type())') -_sp_dotkit_root=$(spack-python -c "print(spack.util.path.canonicalize_path(spack.config.get_config('config').get('module_roots', {}).get('dotkit')))") -_sp_tcl_root=$(spack-python -c "print(spack.util.path.canonicalize_path(spack.config.get_config('config').get('module_roots', {}).get('tcl')))") + +_python_command=$(printf "%s\\\n%s\\\n%s" \ +"print(\'_sp_sys_type={0}\'.format(spack.architecture.sys_type()))" \ +"print(\'_sp_dotkit_root={0}\'.format(spack.util.path.canonicalize_path(spack.config.get_config(\'config\').get(\'module_roots\', {}).get(\'dotkit\'))))" \ +"print(\'_sp_tcl_root={0}\'.format(spack.util.path.canonicalize_path(spack.config.get_config(\'config\').get(\'module_roots\', {}).get(\'tcl\'))))" +) + +_assignment_command=$(spack-python -c "exec('${_python_command}')") +eval ${_assignment_command} + _spack_pathadd DK_NODE "${_sp_dotkit_root%/}/$_sp_sys_type" _spack_pathadd MODULEPATH "${_sp_tcl_root%/}/$_sp_sys_type" -- cgit v1.2.3-60-g2f50