Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
4026cbba
Commit
4026cbba
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: FileOrThing passes-through if submit=True, and errors if in-memory or LOAD
is used in conjunction with submit=True
parent
60bde1fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/wrappers/wrapperutils.py
+54
-10
54 additions, 10 deletions
fsl/wrappers/wrapperutils.py
with
54 additions
and
10 deletions
fsl/wrappers/wrapperutils.py
+
54
−
10
View file @
4026cbba
...
@@ -154,12 +154,12 @@ def cmdwrapper(func):
...
@@ -154,12 +154,12 @@ def cmdwrapper(func):
:func:`fsl.utils.run.run` function in a standardised manner.
:func:`fsl.utils.run.run` function in a standardised manner.
"""
"""
def
wrapper
(
*
args
,
**
kwargs
):
def
wrapper
(
*
args
,
**
kwargs
):
stdout
=
kwargs
.
pop
(
'
stdout
'
,
True
)
stdout
=
kwargs
.
pop
(
'
stdout
'
,
True
)
stderr
=
kwargs
.
pop
(
'
stderr
'
,
True
)
stderr
=
kwargs
.
pop
(
'
stderr
'
,
True
)
exitcode
=
kwargs
.
pop
(
'
exitcode
'
,
False
)
exitcode
=
kwargs
.
pop
(
'
exitcode
'
,
False
)
submit
=
kwargs
.
pop
(
'
submit
'
,
None
)
submit
=
kwargs
.
pop
(
'
submit
'
,
None
)
log
=
kwargs
.
pop
(
'
log
'
,
{
'
tee
'
:
True
})
log
=
kwargs
.
pop
(
'
log
'
,
{
'
tee
'
:
True
})
cmd
=
func
(
*
args
,
**
kwargs
)
cmd
=
func
(
*
args
,
**
kwargs
)
return
run
.
run
(
cmd
,
return
run
.
run
(
cmd
,
stderr
=
stderr
,
stderr
=
stderr
,
log
=
log
,
log
=
log
,
...
@@ -175,12 +175,12 @@ def fslwrapper(func):
...
@@ -175,12 +175,12 @@ def fslwrapper(func):
:func:`fsl.utils.run.runfsl` function in a standardised manner.
:func:`fsl.utils.run.runfsl` function in a standardised manner.
"""
"""
def
wrapper
(
*
args
,
**
kwargs
):
def
wrapper
(
*
args
,
**
kwargs
):
stdout
=
kwargs
.
pop
(
'
stdout
'
,
True
)
stdout
=
kwargs
.
pop
(
'
stdout
'
,
True
)
stderr
=
kwargs
.
pop
(
'
stderr
'
,
True
)
stderr
=
kwargs
.
pop
(
'
stderr
'
,
True
)
exitcode
=
kwargs
.
pop
(
'
exitcode
'
,
False
)
exitcode
=
kwargs
.
pop
(
'
exitcode
'
,
False
)
submit
=
kwargs
.
pop
(
'
submit
'
,
None
)
submit
=
kwargs
.
pop
(
'
submit
'
,
None
)
log
=
kwargs
.
pop
(
'
log
'
,
{
'
tee
'
:
True
})
log
=
kwargs
.
pop
(
'
log
'
,
{
'
tee
'
:
True
})
cmd
=
func
(
*
args
,
**
kwargs
)
cmd
=
func
(
*
args
,
**
kwargs
)
return
run
.
runfsl
(
cmd
,
return
run
.
runfsl
(
cmd
,
stderr
=
stderr
,
stderr
=
stderr
,
log
=
log
,
log
=
log
,
...
@@ -452,6 +452,25 @@ class _FileOrThing(object):
...
@@ -452,6 +452,25 @@ class _FileOrThing(object):
generated by the function will not be present in the dictionary.
generated by the function will not be present in the dictionary.
**Cluster submission**
The above description holds in all situations, except when an argument
called ``submit`` is passed, and is set to ``True``. In this case, the
``_FileOrThing`` decorator will pass all arguments straight through to the
decorated function, and will return its return value unchanged.
This is because most functions that are decorated with the
:func:`fileOrImage` or :func:`fileOrArray` decorators will invoke a call
to :func:`.run` or :func:`.runfsl`, where a value of ``submit=True`` will
cause the command to be executed asynchronously on a cluster platform.
A :exc:`ValueError` will be raised if the decorated function is called
with ``submit=True``, and with any in-memory objects or ``LOAD`` symbols.
**Example**
**Example**
...
@@ -528,9 +547,13 @@ class _FileOrThing(object):
...
@@ -528,9 +547,13 @@ class _FileOrThing(object):
The decorated function
'
s actual return value is accessible via the
The decorated function
'
s actual return value is accessible via the
:meth:`output` property.
:meth:`output` property.
"""
"""
def
__init__
(
self
,
output
):
def
__init__
(
self
,
output
):
super
().
__init__
()
self
.
__output
=
output
self
.
__output
=
output
@property
@property
def
output
(
self
):
def
output
(
self
):
"""
Access the return value of the decorated function.
"""
"""
Access the return value of the decorated function.
"""
...
@@ -604,6 +627,27 @@ class _FileOrThing(object):
...
@@ -604,6 +627,27 @@ class _FileOrThing(object):
func
=
self
.
__func
func
=
self
.
__func
argnames
=
namedPositionals
(
func
,
args
)
argnames
=
namedPositionals
(
func
,
args
)
# Special case - if fsl.utils.run[fsl] is
# being decorated (e.g. via cmdwrapper/
# fslwrapper), and submit=True, this call
# will ultimately submit the job to the
# cluster, and will return immediately.
#
# We error if we are given any in-memory
# things, or LOAD symbols.
#
# n.b. testing values to be strings could
# interfere with the fileOrText decorator.
# Possible solution is to use pathlib?
if
kwargs
.
get
(
'
submit
'
,
False
):
allargs
=
{
**
dict
(
zip
(
argnames
,
args
)),
**
kwargs
}
for
name
,
val
in
allargs
.
items
():
if
(
name
in
self
.
__things
)
and
\
(
not
isinstance
(
val
,
six
.
string_types
)):
raise
ValueError
(
'
Cannot use in-memory objects
'
'
or LOAD with submit=True!
'
)
return
func
(
*
args
,
**
kwargs
)
# If this _FileOrThing is being called
# If this _FileOrThing is being called
# by another _FileOrThing don't create
# by another _FileOrThing don't create
# another working directory. We do this
# another working directory. We do this
...
...
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