From d211ea51d11757dedd9caa84535789bde4e74448 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Fri, 20 Aug 2021 12:46:43 +0100 Subject: [PATCH] STY: Address/suppress lint --- fsl/utils/run.py | 64 ++++++++++++++++++-------------- fsl/wrappers/__init__.py | 71 +++++++++++++++++++----------------- fsl/wrappers/wrapperutils.py | 2 +- 3 files changed, 74 insertions(+), 63 deletions(-) diff --git a/fsl/utils/run.py b/fsl/utils/run.py index f67103570..6117934b1 100644 --- a/fsl/utils/run.py +++ b/fsl/utils/run.py @@ -52,17 +52,16 @@ class FSLNotPresent(Exception): """Error raised by the :func:`runfsl` function when ``$FSLDIR`` cannot be found. """ - pass @contextlib.contextmanager -def dryrun(*args): +def dryrun(*_): """Context manager which causes all calls to :func:`run` to be logged but not executed. See the :data:`DRY_RUN` flag. The returned standard output will be equal to ``' '.join(args)``. """ - global DRY_RUN + global DRY_RUN # pylint: disable=global-statement oldval = DRY_RUN DRY_RUN = True @@ -184,16 +183,16 @@ def run(*args, **kwargs): returnExitcode = kwargs.pop('exitcode', False) submit = kwargs.pop('submit', {}) cmdonly = kwargs.pop('cmdonly', False) - log = kwargs.pop('log', None) + logg = kwargs.pop('log', None) args = prepareArgs(args) - if log is None: - log = {} + if logg is None: + logg = {} - tee = log.get('tee', False) - logStdout = log.get('stdout', None) - logStderr = log.get('stderr', None) - logCmd = log.get('cmd', None) + tee = logg.get('tee', False) + logStdout = logg.get('stdout', None) + logStderr = logg.get('stderr', None) + logCmd = logg.get('cmd', None) if not bool(submit): submit = None @@ -394,25 +393,32 @@ def runfsl(*args, **kwargs): def wslcmd(cmdpath, *args): + """Convert a command + arguments into an equivalent set of arguments that + will run the command under Windows Subsystem for Linux + + :param cmdpath: Fully qualified path to the command. This is essentially + a WSL path not a Windows one since FSLDIR is specified + as a WSL path, however it may have backslashes as path + separators due to previous use of ``os.path.join`` + + :param args: Sequence of command arguments (the first of which is the + unqualified command name) + + :return: If ``cmdpath`` exists and is executable in WSL, return a + sequence of command arguments which when executed will run the + command in WSL. Windows paths in the argument list will be + converted to WSL paths. If ``cmdpath`` was not executable in + WSL, returns None """ - Convert a command + arguments into an equivalent set of arguments that will run the command - under Windows Subsystem for Linux - - :param cmdpath: Fully qualified path to the command. This is essentially a WSL path not a Windows - one since FSLDIR is specified as a WSL path, however it may have backslashes - as path separators due to previous use of ``os.path.join`` - :param args: Sequence of command arguments (the first of which is the unqualified command name) - - :return: If ``cmdpath`` exists and is executable in WSL, return a sequence of command arguments - which when executed will run the command in WSL. Windows paths in the argument list will - be converted to WSL paths. If ``cmdpath`` was not executable in WSL, returns None - """ - # Check if command exists in WSL (remembering that the command path may include FSLDIR which - # is a Windows path) + # Check if command exists in WSL (remembering + # that the command path may include FSLDIR + # which is a Windows path) cmdpath = fslpath.wslpath(cmdpath) - _stdout, _stderr, retcode = _realrun(False, None, None, None, "wsl", "test", "-x", cmdpath) + _stdout, _stderr, retcode = _realrun( + False, None, None, None, "wsl", "test", "-x", cmdpath) if retcode == 0: - # Form a new argument list and convert any Windows paths in it into WSL paths + # Form a new argument list and convert + # any Windows paths in it into WSL paths wslargs = [fslpath.wslpath(arg) for arg in args] wslargs[0] = cmdpath local_fsldir = fslpath.wslpath(fslplatform.fsldir) @@ -420,8 +426,10 @@ def wslcmd(cmdpath, *args): local_fsldevdir = fslpath.wslpath(fslplatform.fsldevdir) else: local_fsldevdir = None - # Prepend important environment variables - note that it seems we cannot - # use WSLENV for this due to its insistance on path mapping. FIXME FSLDEVDIR? + # Prepend important environment variables - + # note that it seems we cannot use WSLENV + # for this due to its insistance on path + # mapping. FIXME FSLDEVDIR? local_path = "$PATH" if local_fsldevdir: local_path += ":%s/bin" % local_fsldevdir diff --git a/fsl/wrappers/__init__.py b/fsl/wrappers/__init__.py index 638587cea..2f1d97d67 100755 --- a/fsl/wrappers/__init__.py +++ b/fsl/wrappers/__init__.py @@ -1,5 +1,8 @@ #!/usr/bin/env python # +# pylint: disable=unused-import +# flake8: noqa: F401 +# # __init__.py - Wrappers for FSL command-line tools. # # Author: Paul McCarthy <pauldmccarthy@gmail.com> @@ -79,37 +82,37 @@ decorators. """ -from .wrapperutils import (LOAD,) # noqa -from .bet import (bet, # noqa - robustfov) -from .eddy import (eddy_cuda, # noqa - topup, - applytopup) -from .fast import (fast,) # noqa -from .fsl_anat import (fsl_anat,) # noqa -from .fsl_sub import (fsl_sub,) # noqa -from .flirt import (flirt, # noqa - invxfm, - applyxfm, - applyxfm4D, - concatxfm, - mcflirt) -from .fnirt import (fnirt, # noqa - applywarp, - invwarp, - convertwarp) -from .fslmaths import (fslmaths,) # noqa -from .fslstats import (fslstats,) # noqa -from .fugue import (fugue, # noqa - prelude, - sigloss, - fsl_prepare_fieldmap) -from .melodic import (melodic, # noqa - fsl_regfilt) -from .misc import (fslreorient2std, # noqa - fslroi, - slicer, - cluster, - gps) -from .epi_reg import epi_reg -from . import tbss # noqa +from fsl.wrappers.wrapperutils import (LOAD,) +from fsl.wrappers.bet import (bet, + robustfov) +from fsl.wrappers.eddy import (eddy_cuda, + topup, + applytopup) +from fsl.wrappers.fast import (fast,) +from fsl.wrappers.fsl_anat import (fsl_anat,) +from fsl.wrappers.fsl_sub import (fsl_sub,) +from fsl.wrappers.flirt import (flirt, + invxfm, + applyxfm, + applyxfm4D, + concatxfm, + mcflirt) +from fsl.wrappers.fnirt import (fnirt, + applywarp, + invwarp, + convertwarp) +from fsl.wrappers.fslmaths import (fslmaths,) +from fsl.wrappers.fslstats import (fslstats,) +from fsl.wrappers.fugue import (fugue, + prelude, + sigloss, + fsl_prepare_fieldmap) +from fsl.wrappers.melodic import (melodic, + fsl_regfilt) +from fsl.wrappers.misc import (fslreorient2std, + fslroi, + slicer, + cluster, + gps) +from fsl.wrappers.epi_reg import epi_reg +from fsl.wrappers import tbss diff --git a/fsl/wrappers/wrapperutils.py b/fsl/wrappers/wrapperutils.py index 60413b866..ac647674b 100644 --- a/fsl/wrappers/wrapperutils.py +++ b/fsl/wrappers/wrapperutils.py @@ -441,7 +441,7 @@ file should be loaded into memory and returned as a Python object. """ -class FileOrThing(object): +class FileOrThing: """Decorator which ensures that certain arguments which are passed into the decorated function are always passed as file names. Both positional and keyword arguments can be specified. -- GitLab