Skip to content
Snippets Groups Projects
Commit d211ea51 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

STY: Address/suppress lint

parent adcd481c
No related branches found
No related tags found
No related merge requests found
...@@ -52,17 +52,16 @@ class FSLNotPresent(Exception): ...@@ -52,17 +52,16 @@ class FSLNotPresent(Exception):
"""Error raised by the :func:`runfsl` function when ``$FSLDIR`` cannot """Error raised by the :func:`runfsl` function when ``$FSLDIR`` cannot
be found. be found.
""" """
pass
@contextlib.contextmanager @contextlib.contextmanager
def dryrun(*args): def dryrun(*_):
"""Context manager which causes all calls to :func:`run` to be logged but """Context manager which causes all calls to :func:`run` to be logged but
not executed. See the :data:`DRY_RUN` flag. not executed. See the :data:`DRY_RUN` flag.
The returned standard output will be equal to ``' '.join(args)``. The returned standard output will be equal to ``' '.join(args)``.
""" """
global DRY_RUN global DRY_RUN # pylint: disable=global-statement
oldval = DRY_RUN oldval = DRY_RUN
DRY_RUN = True DRY_RUN = True
...@@ -184,16 +183,16 @@ def run(*args, **kwargs): ...@@ -184,16 +183,16 @@ def run(*args, **kwargs):
returnExitcode = kwargs.pop('exitcode', False) returnExitcode = kwargs.pop('exitcode', False)
submit = kwargs.pop('submit', {}) submit = kwargs.pop('submit', {})
cmdonly = kwargs.pop('cmdonly', False) cmdonly = kwargs.pop('cmdonly', False)
log = kwargs.pop('log', None) logg = kwargs.pop('log', None)
args = prepareArgs(args) args = prepareArgs(args)
if log is None: if logg is None:
log = {} logg = {}
tee = log.get('tee', False) tee = logg.get('tee', False)
logStdout = log.get('stdout', None) logStdout = logg.get('stdout', None)
logStderr = log.get('stderr', None) logStderr = logg.get('stderr', None)
logCmd = log.get('cmd', None) logCmd = logg.get('cmd', None)
if not bool(submit): if not bool(submit):
submit = None submit = None
...@@ -394,25 +393,32 @@ def runfsl(*args, **kwargs): ...@@ -394,25 +393,32 @@ def runfsl(*args, **kwargs):
def wslcmd(cmdpath, *args): 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 # Check if command exists in WSL (remembering
under Windows Subsystem for Linux # that the command path may include FSLDIR
# which is a Windows path)
: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)
cmdpath = fslpath.wslpath(cmdpath) 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: 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 = [fslpath.wslpath(arg) for arg in args]
wslargs[0] = cmdpath wslargs[0] = cmdpath
local_fsldir = fslpath.wslpath(fslplatform.fsldir) local_fsldir = fslpath.wslpath(fslplatform.fsldir)
...@@ -420,8 +426,10 @@ def wslcmd(cmdpath, *args): ...@@ -420,8 +426,10 @@ def wslcmd(cmdpath, *args):
local_fsldevdir = fslpath.wslpath(fslplatform.fsldevdir) local_fsldevdir = fslpath.wslpath(fslplatform.fsldevdir)
else: else:
local_fsldevdir = None local_fsldevdir = None
# Prepend important environment variables - note that it seems we cannot # Prepend important environment variables -
# use WSLENV for this due to its insistance on path mapping. FIXME FSLDEVDIR? # note that it seems we cannot use WSLENV
# for this due to its insistance on path
# mapping. FIXME FSLDEVDIR?
local_path = "$PATH" local_path = "$PATH"
if local_fsldevdir: if local_fsldevdir:
local_path += ":%s/bin" % local_fsldevdir local_path += ":%s/bin" % local_fsldevdir
......
#!/usr/bin/env python #!/usr/bin/env python
# #
# pylint: disable=unused-import
# flake8: noqa: F401
#
# __init__.py - Wrappers for FSL command-line tools. # __init__.py - Wrappers for FSL command-line tools.
# #
# Author: Paul McCarthy <pauldmccarthy@gmail.com> # Author: Paul McCarthy <pauldmccarthy@gmail.com>
...@@ -79,37 +82,37 @@ decorators. ...@@ -79,37 +82,37 @@ decorators.
""" """
from .wrapperutils import (LOAD,) # noqa from fsl.wrappers.wrapperutils import (LOAD,)
from .bet import (bet, # noqa from fsl.wrappers.bet import (bet,
robustfov) robustfov)
from .eddy import (eddy_cuda, # noqa from fsl.wrappers.eddy import (eddy_cuda,
topup, topup,
applytopup) applytopup)
from .fast import (fast,) # noqa from fsl.wrappers.fast import (fast,)
from .fsl_anat import (fsl_anat,) # noqa from fsl.wrappers.fsl_anat import (fsl_anat,)
from .fsl_sub import (fsl_sub,) # noqa from fsl.wrappers.fsl_sub import (fsl_sub,)
from .flirt import (flirt, # noqa from fsl.wrappers.flirt import (flirt,
invxfm, invxfm,
applyxfm, applyxfm,
applyxfm4D, applyxfm4D,
concatxfm, concatxfm,
mcflirt) mcflirt)
from .fnirt import (fnirt, # noqa from fsl.wrappers.fnirt import (fnirt,
applywarp, applywarp,
invwarp, invwarp,
convertwarp) convertwarp)
from .fslmaths import (fslmaths,) # noqa from fsl.wrappers.fslmaths import (fslmaths,)
from .fslstats import (fslstats,) # noqa from fsl.wrappers.fslstats import (fslstats,)
from .fugue import (fugue, # noqa from fsl.wrappers.fugue import (fugue,
prelude, prelude,
sigloss, sigloss,
fsl_prepare_fieldmap) fsl_prepare_fieldmap)
from .melodic import (melodic, # noqa from fsl.wrappers.melodic import (melodic,
fsl_regfilt) fsl_regfilt)
from .misc import (fslreorient2std, # noqa from fsl.wrappers.misc import (fslreorient2std,
fslroi, fslroi,
slicer, slicer,
cluster, cluster,
gps) gps)
from .epi_reg import epi_reg from fsl.wrappers.epi_reg import epi_reg
from . import tbss # noqa from fsl.wrappers import tbss
...@@ -441,7 +441,7 @@ file should be loaded into memory and returned as a Python object. ...@@ -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 """Decorator which ensures that certain arguments which are passed into the
decorated function are always passed as file names. Both positional and decorated function are always passed as file names. Both positional and
keyword arguments can be specified. keyword arguments can be specified.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment