Skip to content

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 7 commits into from
May 18, 2018

Conversation

effigies
Copy link
Member

Related (closes?): #2553

Changes proposed in this pull request

  • Adds pre- and post-run hooks to BaseInterface, which is intended to allow mix-ins to be more flexible about where exactly they fall within the method resolution stack.
  • Creates ReportCapableInterface as a mix-in that is also written to work as a base class as well.

This factors out what seemed to be the essential parts of the niworkflows ReportCapableInterface.

Differences:

  • Compression is removed as an option - without the actual figure generation and compression machinery, this would be under-supported. If these are worth adding, we can do so, but in point of fact we're considering undoing some of our compression steps as they make our reports Chrome-only.
  • _post_run_hook is now the driver of this functionality, and classes using this mix-in should tail-call return super(..., self)._post_run_hook(runtime).
  • _generate_error_report was removed. I don't think this can actually be hit in niworkflows, as CommandLine interfaces that had bad return values raised exceptions.

@codecov-io
Copy link

codecov-io commented Apr 27, 2018

Codecov Report

Merging #2560 into master will decrease coverage by 0.01%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2560      +/-   ##
==========================================
- Coverage   67.57%   67.56%   -0.02%     
==========================================
  Files         333      335       +2     
  Lines       42547    42589      +42     
  Branches     5266     5269       +3     
==========================================
+ Hits        28750    28774      +24     
- Misses      13124    13142      +18     
  Partials      673      673
Flag Coverage Δ
#smoketests 50.71% <100%> (+0.01%) ⬆️
#unittests 64.96% <57.14%> (-0.06%) ⬇️
Impacted Files Coverage Δ
nipype/interfaces/base/core.py 89.7% <100%> (+0.09%) ⬆️
nipype/interfaces/mixins/__init__.py 100% <100%> (ø)
nipype/interfaces/mixins/reporting.py 48.57% <48.57%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a96ea5...25c98b7. Read the comment docs.

@mgxd
Copy link
Member

mgxd commented Apr 27, 2018

@effigies is this targeting 1.0.3?

@effigies
Copy link
Member Author

No. For my part the only things to try to get in for 1.0.3 are any fixes needed to pass all the tests and avoid distribution errors.

@effigies effigies added this to the 1.0.4 milestone Apr 30, 2018
Copy link
Member Author

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for review.

@oesteban I'd appreciate your thoughts on the differences with the niworkflows version.

runtime = self._run_interface(runtime)
runtime = self._post_run_hook(runtime)
Copy link
Member Author

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?

Copy link
Member

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.



class ReportCapableInputSpec(BaseInterfaceInputSpec):
generate_report = traits.Bool(False, usedefault=True,
Copy link
Contributor

@oesteban oesteban May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for terminal_output and ignore_exception, this should not be an input. Should be a state variable of the instance.

if not self.inputs.generate_report:
return runtime

self._out_report = os.path.abspath(self.inputs.out_report)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current working directory might have changed at this point :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see three options:

  1. chdir(runtime.cwd) between each step - ugly, but forgiving
  2. RuntimeError if os.getcwd() != runtime.cwd after one of these steps is run
  3. Reject the idea of cwd assurances altogether and resolve this path relative to runtime.cwd

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 1 is okay 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm going to do 3 for now. @satra, let me know if you think we should do any work to either mitigate or error out if _*_run_hook and _run_interface change the CWD on us.

@effigies
Copy link
Member Author

I was able to use this PR to refactor reporting interfaces in nipreps/niworkflows#238, so this should be good to go.

@effigies effigies merged commit d65688c into nipy:master May 18, 2018
@effigies effigies deleted the enh/rci branch May 18, 2018 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants