Skip to content

Commit 708e02e

Browse files
Add skip-execution cell tag functionality (#151)
* Add `skip-execution` tag functionality * Add skip_execution_tag option and test * change name of option * fix flake8 * Update nbclient/client.py Co-authored-by: David Brochart <[email protected]> Co-authored-by: David Brochart <[email protected]>
1 parent 4758129 commit 708e02e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

nbclient/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ class NotebookClient(LoggingConfigurable):
144144
),
145145
).tag(config=True)
146146

147+
skip_cells_with_tag: str = Unicode(
148+
'skip-execution',
149+
help=dedent(
150+
"""
151+
Name of the cell tag to use to denote a cell that should be skipped.
152+
"""
153+
),
154+
).tag(config=True)
155+
147156
extra_arguments: t.List = List(Unicode()).tag(config=True)
148157

149158
kernel_name: str = Unicode(
@@ -808,6 +817,10 @@ async def async_execute_cell(
808817
self.log.debug("Skipping non-executing cell %s", cell_index)
809818
return cell
810819

820+
if self.skip_cells_with_tag in cell.metadata.get("tags", []):
821+
self.log.debug("Skipping tagged cell %s", cell_index)
822+
return cell
823+
811824
if self.record_timing and 'execution' not in cell['metadata']:
812825
cell['metadata']['execution'] = {}
813826

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"source": [
7+
"print(\"a long running cell\")"
8+
],
9+
"outputs": [],
10+
"metadata": {
11+
"tags": [
12+
"skip-execution"
13+
]
14+
}
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 1,
19+
"source": [
20+
"print('ok')"
21+
],
22+
"outputs": [
23+
{
24+
"output_type": "stream",
25+
"name": "stdout",
26+
"text": [
27+
"ok\n"
28+
]
29+
}
30+
],
31+
"metadata": {}
32+
}
33+
],
34+
"metadata": {},
35+
"nbformat": 4,
36+
"nbformat_minor": 1
37+
}

nbclient/tests/test_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def notebook_resources():
257257
("JupyterWidgets.ipynb", dict(kernel_name="python")),
258258
("Skip Exceptions with Cell Tags.ipynb", dict(kernel_name="python")),
259259
("Skip Exceptions.ipynb", dict(kernel_name="python", allow_errors=True)),
260+
("Skip Execution with Cell Tag.ipynb", dict(kernel_name="python")),
260261
("SVG.ipynb", dict(kernel_name="python")),
261262
("Unicode.ipynb", dict(kernel_name="python")),
262263
("UnicodePy3.ipynb", dict(kernel_name="python")),

0 commit comments

Comments
 (0)