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
282ab2d6
Commit
282ab2d6
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
chained _FileOrThing decorators construct output correctly
parent
f011b82f
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
+26
-13
26 additions, 13 deletions
fsl/wrappers/wrapperutils.py
with
26 additions
and
13 deletions
fsl/wrappers/wrapperutils.py
+
26
−
13
View file @
282ab2d6
...
@@ -176,7 +176,17 @@ def required(*reqargs):
...
@@ -176,7 +176,17 @@ def required(*reqargs):
for
reqarg
in
reqargs
:
for
reqarg
in
reqargs
:
assert
reqarg
in
kwargs
assert
reqarg
in
kwargs
return
func
(
**
kwargs
)
return
func
(
**
kwargs
)
return
_update_wrapper
(
wrapper
,
func
)
wrapper
=
_update_wrapper
(
wrapper
,
func
)
# If this is a bound method, make
# sure that the instance is set on
# the wrapper function - this is
# needed by _FileOrThing decorators.
if
hasattr
(
func
,
'
__self__
'
):
wrapper
.
__self__
=
func
.
__self__
return
wrapper
return
decorator
return
decorator
...
@@ -320,25 +330,28 @@ class _FileOrThing(object):
...
@@ -320,25 +330,28 @@ class _FileOrThing(object):
def
__call__
(
self
,
func
):
def
__call__
(
self
,
func
):
"""
Creates and returns the real decorator function.
"""
"""
Creates and returns the real decorator function.
"""
self
.
__func
=
func
isFOT
=
isinstance
(
getattr
(
func
,
'
__self__
'
,
None
),
_FileOrThing
)
self
.
__isFileOrThing
=
False
wrapper
=
functools
.
partial
(
self
.
__wrapper
,
func
,
isFOT
)
if
hasattr
(
func
,
'
__self__
'
):
# TODO
self
.
__isFileOrThing
=
isinstance
(
func
.
__self__
,
_FileOrThing
)
wrapper
=
_update_wrapper
(
wrapper
,
func
)
wrapper
.
__self__
=
self
wrapper
=
functools
.
partial
(
self
.
__wrapper
,
func
)
return
wrapper
return
_update_wrapper
(
wrapper
,
func
)
def
__wrapper
(
self
,
func
,
isFileOrThing
,
*
args
,
**
kwargs
):
def
__wrapper
(
self
,
func
,
*
args
,
**
kwargs
):
"""
Function which wraps ``func``, ensuring that any arguments of
"""
Function which wraps ``func``, ensuring that any arguments of
type ``Thing`` are saved to temporary files, and any arguments
type ``Thing`` are saved to temporary files, and any arguments
with the value :data:`RETURN` are loaded and returned.
with the value :data:`RETURN` are loaded and returned.
"""
func
=
self
.
__func
:arg func: The func being wrapped.
isFileOrThing
=
self
.
__isFileOrThing
:arg isFileOrThing: Set to ``True`` if ``func`` is a wrapper metho
of another ``_FileOrThing`` instance. In this case,
the output arguments will be flattenedinto a single
tuple.
"""
kwargs
=
kwargs
.
copy
()
kwargs
=
kwargs
.
copy
()
kwargs
.
update
(
argsToKwargs
(
func
,
args
))
kwargs
.
update
(
argsToKwargs
(
func
,
args
))
...
@@ -372,7 +385,7 @@ class _FileOrThing(object):
...
@@ -372,7 +385,7 @@ class _FileOrThing(object):
if
isFileOrThing
:
if
isFileOrThing
:
things
=
result
[
1
:]
things
=
result
[
1
:]
result
=
result
[
0
]
result
=
result
[
0
]
return
tuple
([
result
]
+
things
+
outthings
)
return
tuple
([
result
]
+
list
(
things
)
+
outthings
)
else
:
else
:
return
tuple
([
result
]
+
outthings
)
return
tuple
([
result
]
+
outthings
)
...
...
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