-
Notifications
You must be signed in to change notification settings - Fork 535
ENH: ReportCapableInterface mix-in/base interface #2560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
854afe6
ENH: Add pre- and post-run hooks to BaseInterface
effigies 982822c
ENH: Add ReportCapableInterface mix-in/base class
effigies 2e71052
FIX: Add mixins.__init__
effigies e6b258f
FIX: Relative import
effigies 7a678c1
RF: Move generate_report from input spec to instance variable
effigies 583d0f8
FIX: Build absolute path with runtime.cwd
effigies 25c98b7
FIX: Do not pass self to super.__init__
effigies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .reporting import ( | ||
ReportCapableInterface, ReportCapableInputSpec, ReportCapableOutputSpec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | ||
# vi: set ft=python sts=4 ts=4 sw=4 et: | ||
""" class mixin and utilities for enabling reports for nipype interfaces """ | ||
from __future__ import (print_function, division, unicode_literals, | ||
absolute_import) | ||
|
||
import os | ||
from abc import abstractmethod | ||
|
||
from ... import logging | ||
from ..base import ( | ||
File, BaseInterface, BaseInterfaceInputSpec, TraitedSpec) | ||
|
||
iflogger = logging.getLogger('interface') | ||
|
||
|
||
class ReportCapableInputSpec(BaseInterfaceInputSpec): | ||
out_report = File('report', usedefault=True, hash_files=False, | ||
desc='filename for the visual report') | ||
|
||
|
||
class ReportCapableOutputSpec(TraitedSpec): | ||
out_report = File(desc='filename for the visual report') | ||
|
||
|
||
class ReportCapableInterface(BaseInterface): | ||
"""Mixin to enable reporting for Nipype interfaces""" | ||
_out_report = None | ||
|
||
def __init__(self, generate_report=False, **kwargs): | ||
super(ReportCapableInterface, self).__init__(**kwargs) | ||
self.generate_report = generate_report | ||
|
||
def _post_run_hook(self, runtime): | ||
runtime = super(ReportCapableInterface, self)._post_run_hook(runtime) | ||
|
||
# leave early if there's nothing to do | ||
if not self.generate_report: | ||
return runtime | ||
|
||
self._out_report = self.inputs.out_report | ||
if not os.path.isabs(self._out_report): | ||
self._out_report = os.path.abspath(os.path.join(runtime.cwd, | ||
self._out_report)) | ||
|
||
self._generate_report() | ||
|
||
return runtime | ||
|
||
def _list_outputs(self): | ||
try: | ||
outputs = super(ReportCapableInterface, self)._list_outputs() | ||
except NotImplementedError: | ||
outputs = {} | ||
if self._out_report is not None: | ||
outputs['out_report'] = self._out_report | ||
return outputs | ||
|
||
@abstractmethod | ||
def _generate_report(self): | ||
""" | ||
Saves report to file identified by _out_report instance variable | ||
""" | ||
raise NotImplementedError |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satra Are you comfortable with this change to
BaseInterface
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now yes - we may have to add some prov stuff when i refactor that piece.