Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions nbclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ class NotebookClient(LoggingConfigurable):
),
).tag(config=True)

skip_cells_with_tag: str = Unicode(
'skip-execution',
help=dedent(
"""
Name of the cell tag to use to denote a cell that should be skipped.
"""
),
).tag(config=True)

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

kernel_name: str = Unicode(
Expand Down Expand Up @@ -803,6 +812,10 @@ async def async_execute_cell(
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