From e8a71089a6dba415d8af2f803832ceb1613513df Mon Sep 17 00:00:00 2001 From: Gregory Lee Date: Thu, 25 Jul 2019 11:48:32 -0700 Subject: use Excecutable instead of exec for editing licenses (#11968) * fix defunct editor exit in #11691 --- lib/spack/spack/hooks/licensing.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/hooks/licensing.py b/lib/spack/spack/hooks/licensing.py index cc47f1a4c7..8a56dc122f 100644 --- a/lib/spack/spack/hooks/licensing.py +++ b/lib/spack/spack/hooks/licensing.py @@ -9,6 +9,7 @@ import llnl.util.tty as tty from llnl.util.filesystem import mkdirp from spack.util.editor import editor +from spack.util.executable import Executable, which def pre_install(spec): @@ -37,8 +38,26 @@ def set_up_license(pkg): # Create a new license file write_license_file(pkg, license_path) # Open up file in user's favorite $EDITOR for editing - editor(license_path) - tty.msg("Added global license file %s" % license_path) + editor_exe = None + if 'VISUAL' in os.environ: + editor_exe = Executable(os.environ['VISUAL']) + # gvim runs in the background by default so we force it to run + # in the foreground to make sure the license file is updated + # before we try to install + if 'gvim' in os.environ['VISUAL']: + editor_exe.add_default_arg('-f') + elif 'EDITOR' in os.environ: + editor_exe = Executable(os.environ['EDITOR']) + else: + editor_exe = which('vim', 'vi', 'emacs', 'nano') + if editor_exe is None: + raise EnvironmentError( + 'No text editor found! Please set the VISUAL and/or EDITOR' + ' environment variable(s) to your preferred text editor.') + + def editor_wrapper(exe, args): + editor_exe(license_path) + editor(license_path, _exec_func=editor_wrapper) else: # Use already existing license file tty.msg("Found already existing license %s" % license_path) -- cgit v1.2.3-70-g09d2