-
Notifications
You must be signed in to change notification settings - Fork 421
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
Add option for hiding input #135
Conversation
papermill/execute.py
Outdated
@@ -147,7 +147,8 @@ def execute_notebook(notebook, | |||
kernel_name=None, | |||
progress_bar=True, | |||
log_output=False, | |||
start_timeout=60): | |||
start_timeout=60, | |||
report-mode=None): |
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.
This should be an underscore, otherwise this is a subtraction.
papermill/execute.py
Outdated
|
||
Returns: | ||
nb (NotebookNode): executed notebook object | ||
""" | ||
print("Input Notebook: %s" % get_pretty_path(notebook), file=sys.stderr) | ||
print("Output Notebook: %s" % get_pretty_path(output), file=sys.stderr) | ||
nb = load_notebook_node(notebook) | ||
|
||
# Hide input if report-mode is set to True. | ||
if report-mode: |
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.
report_mode
here too.
ah right! Will fix. Thanks! |
hopefully it is better now |
Codecov Report
@@ Coverage Diff @@
## master #135 +/- ##
==========================================
+ Coverage 73.58% 73.66% +0.08%
==========================================
Files 8 8
Lines 935 938 +3
==========================================
+ Hits 688 691 +3
Misses 247 247 |
hm... what else is wrong? |
It's only reporting an error because coverage has gone down (no tests on this new command). I'll have to defer to one of the primary pythonistas for what they'd want next as well as style on the command. Thanks for submitting this! |
Alright! Looking forward to seeing what is done next! |
Two things to add now I think: If we're adding an option to the execute command it should also be on CLI. The cli.py file should be straight forward to manipulate and add a new flag (you can copy one of the adjacent flags properties). The second item is tests. We will want a test in the test_execute.py and test_cli.py to test that we can set the option and that it will change the metadata of an output notebook when it executes that notebook. |
papermill/execute.py
Outdated
|
||
# Hide input if report-mode is set to True. | ||
if report_mode: | ||
nb.metadata.inputHidden = True |
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.
@mpacer I saw some of the back-and-forth on jupyter threads about hidden inputs, is this the metadata field we want papermill to populate for other tools going forward?
will look into the error tmr! |
papermill/cli.py
Outdated
@@ -36,6 +36,8 @@ | |||
help="Flag for writing notebook output to stderr.") | |||
@click.option('--start_timeout', type=int, default=60, | |||
help="Time in seconds to wait for kernel to start.") | |||
@click.option('--report-mode/--not-report-mode', default=None, |
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.
You'll want this to be default=False
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.
right!
papermill/execute.py
Outdated
@@ -147,7 +147,8 @@ def execute_notebook(notebook, | |||
kernel_name=None, | |||
progress_bar=True, | |||
log_output=False, | |||
start_timeout=60): | |||
start_timeout=60, | |||
report_mode=None): |
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.
I'd do report_mode=False
here too as it's a flag
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.
ok thanks!
Have attempted writing tests in both test_execute.py and test_cli.py. |
I have read the errors(EDIT: this was written before squashing), and the following is my understanding:
The input and output notebooks I've made may or may not make a very good test case... Thanks! |
Try pasting the delta into a diff tool, should pop up quickly. Also try adding a debug point (or print statements) in the execute call to make sure you're getting expected values. You can isolate to a single test with https://stackoverflow.com/questions/36456920/is-there-a-way-to-specify-which-pytest-tests-to-run-from-a-file to narrow down the issue. I don't see the problem from a peripheral scan of the code. |
For test_execute you do not need to have the notebooks pushed anywhere, just make sure they're in the repo branch and added. Check that |
Yes, it was a typo. Thanks!! |
Awesome, two things left. First, let's squash these commits down. Second is we're discussing this week with a few nteract team members what the best metadata / library contract should be to respect this report mode. Specifically what should the metadata field look like and how do we want nteract exporters to respect metadata contracts moving forward. Today I don't believe any tools will respect |
The original jupyter discussion about hidden input was here: jupyter/notebook#534 nteract frontends all support both I totally forgot that at the last dev meetings we ended up on a nested path: https://github.com/jupyter/nbformat/pull/94/files
Let's go with that officially merged stance on |
Yes I do want html exporters to respect the field. Ok! Thanks. I'll squash and go through the links! |
@cldssty As long as we're namespacing the metadata to provide this functionality — I'm cool with that. With such a change I'm ok with this PR. Note that that spec that @rgbkrk linked to is a spec on a per cell basis, and so there is no one field to set for the whole notebook. More generally though, think we should consider the long-term plan for additional customisation (like report-mode) for a couple of reasons. First, the proposed solution will be respected by the As of right now, Part of the reason why there was disagreement around the term hide_input is whether that is intended to remove input altogether or make it so that its visibility can be toggled back and forth (see |
@cldssty Let us know if you get stuck in the final PR updates |
Feature mentioned in nteract/papermill#135 (comment)
@cldssty Do you think you'll have some time to complete this PR or should we make final touches to get it mergable? |
I'm really sorry for the delay! I'll be looking at this this weekend and will ask about any problems I'm encountering. Again really sorry about disappearing and thank you so much for your patience. Apologies for any inconvenience caused!! |
No problem, and no need to apologize. We wanted to get this nice capability added before the nteract sprints begin in a week so we'll give special attention to this PR and help with getting it finished. |
ff43d8a
to
ce7118f
Compare
I've skimmed through the links and these are my thoughts: I don't know why I assumed
EDIT: I'm going to go ahead and look into using In any case, since @mpacer says that I have yet to find out how to do all of this. If there are any misunderstandings or things that cannot be done, please let me know! Thanks :D |
Currently have something like this in execute.py:
|
It's saying that it doesn't have the 'jupyter' key... should the key be added somewhere or...? |
If it doesn't have the jupyter key, go ahead and add it in, then apply We can leave it to nbconvert to implement it without bogging this PR down. |
ok shall I just squash the commits? Going to look into making this work with html exports in a bit more detail. Oh wait, the field is now |
5e80a6b
to
2737a34
Compare
I'll keep working on this tmr. This is what I've done so far:
What I've tried so far:
Please advise! I will look into the exportation part of this and also if it gets too close to the nteract sprint and I still can't find a good solution, I would be happy to hand this over to someone who can wrap this up before the start of the sprint. You could specify a deadline for this if you like. Until then I'm going to keep trying! Thanks! |
papermill/execute.py
Outdated
if report_mode: | ||
for cell in nb.cells: | ||
if cell.cell_type == 'code': | ||
cell.metadata.jupyter.source_hidden = True |
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.
cell.metadata['jupyter'] = cell.get('jupyter', {})
cell.metadata.['jupyter']['source_hidden'] = True
papermill/iorw.py
Outdated
self.source_hidden = False | ||
self.outputs_hidden = False | ||
|
||
class Dumper(Jupyter): |
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.
You don't need these two classes
papermill/iorw.py
Outdated
@@ -167,6 +190,9 @@ def load_notebook_node(notebook_path): | |||
|
|||
if not hasattr(cell.metadata, 'papermill'): | |||
cell.metadata['papermill'] = dict() | |||
|
|||
if not hasattr(cell.metadata, 'jupyter'): |
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.
given the snippet I posted you can skip this check/assignment too
papermill/tests/test_execute.py
Outdated
nb = execute_notebook(self.notebook_path, self.nb_test_executed_fname, report_mode = True) | ||
for cell in nb.cells: | ||
if cell.cell_type == 'code': | ||
self.assertEqual(cell.metadata.jupyter.source_hidden, True) |
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.
self.assertEqual(cell.metadata.get('jupyter', {}).get('source_hidden'), True)
Thanks for coming back to wrap up the PR! I think leaving metadata with primitive objects (dict/str) will uncomplicated the part you're stuck on and posted come comments to help with making that change. Give that change a whirl and I think you'll be good :) |
Changes applied and squashed. Thanks for the tips!! |
This is looking pretty good, I think you can take the WIP title off if you think it's ready. :) |
So is I was going to do a bit more research later today to see if there is anything else I could do regarding html exports but if there isn't then yes I'm happy to take the WIP title off at this stage! Thanks! |
The intention is yes. We'll need to make a PR to nbconvert to respect the same field as nteract. @mpacer has a PR (jupyter/nbconvert#825) which we can help get completed and merged. |
Thanks for all the tips and being helpful + patient! I'll be looking out for further development in related PRs! |
Have made an attempt. Please tell me what to change/add. Thanks!