Skip to content
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 skip-execution cell tag functionality #151

Merged
merged 5 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions nbclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ class NotebookClient(LoggingConfigurable):
),
).tag(config=True)

skip_cells_with_tag: str = Unicode(
'skip-execution',
help=dedent(
"""
Name of the cell tag to use to,
to denote a cell that should be skipped.
chrisjsewell marked this conversation as resolved.
Show resolved Hide resolved
"""
),
).tag(config=True)

extra_arguments: t.List = List(Unicode()).tag(config=True)

kernel_name: str = Unicode(
Expand Down Expand Up @@ -802,6 +812,10 @@ async def async_execute_cell(
if cell.cell_type != 'code' or not cell.source.strip():
self.log.debug("Skipping non-executing cell %s", cell_index)
return cell

if self.skip_cells_with_tag in cell.metadata.get("tags", []):
self.log.debug("Skipping tagged cell %s", cell_index)
return cell

if self.record_timing and 'execution' not in cell['metadata']:
cell['metadata']['execution'] = {}
Expand Down
37 changes: 37 additions & 0 deletions nbclient/tests/files/Skip Execution with Cell Tag.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"source": [
"print(\"a long running cell\")"
],
"outputs": [],
"metadata": {
"tags": [
"skip-execution"
]
}
},
{
"cell_type": "code",
"execution_count": 1,
"source": [
"print('ok')"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"ok\n"
]
}
],
"metadata": {}
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 1
}
1 change: 1 addition & 0 deletions nbclient/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def notebook_resources():
("JupyterWidgets.ipynb", dict(kernel_name="python")),
("Skip Exceptions with Cell Tags.ipynb", dict(kernel_name="python")),
("Skip Exceptions.ipynb", dict(kernel_name="python", allow_errors=True)),
("Skip Execution with Cell Tag.ipynb", dict(kernel_name="python")),
("SVG.ipynb", dict(kernel_name="python")),
("Unicode.ipynb", dict(kernel_name="python")),
("UnicodePy3.ipynb", dict(kernel_name="python")),
Expand Down