Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
d211ea51
Commit
d211ea51
authored
3 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
STY: Address/suppress lint
parent
adcd481c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fsl/utils/run.py
+36
-28
36 additions, 28 deletions
fsl/utils/run.py
fsl/wrappers/__init__.py
+37
-34
37 additions, 34 deletions
fsl/wrappers/__init__.py
fsl/wrappers/wrapperutils.py
+1
-1
1 addition, 1 deletion
fsl/wrappers/wrapperutils.py
with
74 additions
and
63 deletions
fsl/utils/run.py
+
36
−
28
View file @
d211ea51
...
@@ -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
)
log
g
=
kwargs
.
pop
(
'
log
'
,
None
)
args
=
prepareArgs
(
args
)
args
=
prepareArgs
(
args
)
if
log
is
None
:
if
log
g
is
None
:
log
=
{}
log
g
=
{}
tee
=
log
.
get
(
'
tee
'
,
False
)
tee
=
log
g
.
get
(
'
tee
'
,
False
)
logStdout
=
log
.
get
(
'
stdout
'
,
None
)
logStdout
=
log
g
.
get
(
'
stdout
'
,
None
)
logStderr
=
log
.
get
(
'
stderr
'
,
None
)
logStderr
=
log
g
.
get
(
'
stderr
'
,
None
)
logCmd
=
log
.
get
(
'
cmd
'
,
None
)
logCmd
=
log
g
.
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
...
...
This diff is collapsed.
Click to expand it.
fsl/wrappers/__init__.py
+
37
−
34
View file @
d211ea51
#!/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
This diff is collapsed.
Click to expand it.
fsl/wrappers/wrapperutils.py
+
1
−
1
View file @
d211ea51
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment