MyST-NB icon indicating copy to clipboard operation
MyST-NB copied to clipboard

`remove-cell` skips cell execution in `inline` execution mode

Open agoose77 opened this issue 3 years ago • 5 comments

Describe the bug

context When I added the remove-cell tag to a code cell, I wasn't sure whether it was going to process the cell for execution. In my case, I wanted to generate a figure for use with {eval:figure}, and want to hide the script that generates it.

expectation That the cell is executed but omitted from the rendered document

bug remove-cell actually skips the processing of that cell, whilst the docs imply it's just the rendering that is ignored. I think this is unintentional, as we have the skip-execution tag in nbclient explicitly labelled as a control for the execution behaviour.

Reproduce the bug

Add remove-cell to a cell that modifies the kernel state, and observe that it is not executed during building.

Fix

Remove these lines in nb_to_tokens https://github.com/executablebooks/MyST-NB/blob/2428268b0e436df4ad2281c24408326bf38117de/myst_nb/core/nb_to_tokens.py#L45-L48

Have remove-cell set both remove-input and remove-output in this block https://github.com/executablebooks/MyST-NB/blob/5e2d59c4ab5e66b4522a7b12a2ef01ab90b93ba8/myst_nb/core/render.py#L134-L151

agoose77 avatar May 18 '22 11:05 agoose77

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar May 18 '22 11:05 welcome[bot]

Related to https://github.com/executablebooks/MyST-NB/issues/349

agoose77 avatar Jun 09 '22 15:06 agoose77

That the cell is executed but omitted from the rendered document

to note, this is only an issue for inline execution mode, otherwise this is indeed the behaviour (since execution happens before conversion to tokens / rendering)

chrisjsewell avatar Jun 13 '22 16:06 chrisjsewell

Thanks Chris, I suspect I didn't check different executors.

agoose77 avatar Jun 13 '22 16:06 agoose77

yeh no worries, its oversite on my part for this execution mode. does skip-execution work correctly, for this execution mode, can't remember if I checked?

chrisjsewell avatar Jun 13 '22 17:06 chrisjsewell