From 3ebae6b190612becd990d7b0a0dbe0e5efa08bed Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Tue, 20 Oct 2020 15:05:16 +0100 Subject: [PATCH] RF: when cmdonly is used with a wrapper function, assertions are disabled --- fsl/utils/assertions.py | 7 +++++-- fsl/wrappers/wrapperutils.py | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/fsl/utils/assertions.py b/fsl/utils/assertions.py index b8e5a43b5..63b004d1f 100644 --- a/fsl/utils/assertions.py +++ b/fsl/utils/assertions.py @@ -39,14 +39,17 @@ _DISABLE_ASSERTIONS = False @contextlib.contextmanager -def disabled(): +def disabled(disable=True): """Context manager which allows assertion checks to be temporarily disabled. + + :arg disable: Set to ``True`` (the default) to disable assertions, + or ``False`` to enable them. """ global _DISABLE_ASSERTIONS oldval = _DISABLE_ASSERTIONS - _DISABLE_ASSERTIONS = True + _DISABLE_ASSERTIONS = disable try: yield diff --git a/fsl/wrappers/wrapperutils.py b/fsl/wrappers/wrapperutils.py index 51f269bcb..ff6fcc06d 100644 --- a/fsl/wrappers/wrapperutils.py +++ b/fsl/wrappers/wrapperutils.py @@ -108,10 +108,11 @@ import six import nibabel as nib import numpy as np -import fsl.utils.run as run -import fsl.utils.path as fslpath -import fsl.utils.tempdir as tempdir -import fsl.data.image as fslimage +import fsl.utils.run as run +import fsl.utils.assertions as asrt +import fsl.utils.path as fslpath +import fsl.utils.tempdir as tempdir +import fsl.data.image as fslimage log = logging.getLogger(__name__) @@ -185,7 +186,14 @@ def genxwrapper(func, runner): submit = kwargs.pop('submit', None) cmdonly = kwargs.pop('cmdonly', False) log = kwargs.pop('log', {'tee' : True}) - cmd = func(*args, **kwargs) + + # many wrapper functions use fsl.utils.assertions + # statements to check that input arguments are + # valid. Disable these if the cmdonly argument is + # being used to generate a command without running + # it. + with asrt.disabled(cmdonly): + cmd = func(*args, **kwargs) return runner(cmd, stderr=stderr, -- GitLab