Commit eb8e9f20 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Warn if default plugin destination is based on an unset environment

variable - abort if --force is used
parent 7de029ed
......@@ -94,6 +94,7 @@ When called in one of the above forms, ``fsl_add_module`` will:
import os.path as op
import os
import sys
import argparse
......@@ -105,6 +106,7 @@ import fsl.add_module.plugin_manifest as plgman
from fsl.add_module import __VERSION__
from fsl.add_module.messages import (info,
......@@ -231,7 +233,8 @@ def loadManifest(args : argparse.Namespace) -> Tuple[plgman.Manifest,
# for each requested plugin
if len(dests) == len(plugins):
for p, d in zip(plugins, dests):
manifest[p].destination = d
manifest[p].destination = d
manifest[p].origDestination = d
# or they provided one destination
# to be applied to all plugins (but
......@@ -239,7 +242,8 @@ def loadManifest(args : argparse.Namespace) -> Tuple[plgman.Manifest,
# above rule takes precedence)
elif len(dests) == 1:
for p in manifest.keys():
manifest[p].destination = dests[0]
manifest[p].destination = dests[0]
manifest[p].origDestination = dests[0]
return manifest, plugins
......@@ -270,6 +274,26 @@ def selectPlugins(args : argparse.Namespace,
plugins = [manifest[p] for p in plugins]
# warn the user if any plugins have a default
# destination that is based on an unset
# environment variable. If --force is active,
# this causes the installation to be aborted.
abort = False
for plugin in plugins:
envvars = routines.envvars(plugin.origDestination)
for _, name in envvars:
if name not in os.environ:
abort = args.force
warning(f'WARNING: Default destination for the '
f'[{}] module is based on an '
f'unset environment variable '
EMPHASIS, wrap=True)
if abort:
raise RuntimeError('Aborting installation - cannot use --force '
'when an installation destination depends on '
'an unset environment variable.')
# if the user did not specify install
# destinations, ask them to confirm
# the destination directory for each
......@@ -354,7 +378,7 @@ def main(argv=None):
install( args, plugins)
except Exception as e:
error(str(e), EMPHASIS, wrap=True)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment