diff --git a/nbclient/client.py b/nbclient/client.py index 40ec273b..2736f924 100644 --- a/nbclient/client.py +++ b/nbclient/client.py @@ -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( @@ -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'] = {} diff --git a/nbclient/tests/files/Skip Execution with Cell Tag.ipynb b/nbclient/tests/files/Skip Execution with Cell Tag.ipynb new file mode 100644 index 00000000..8b9c49a6 --- /dev/null +++ b/nbclient/tests/files/Skip Execution with Cell Tag.ipynb @@ -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 +} \ No newline at end of file diff --git a/nbclient/tests/test_client.py b/nbclient/tests/test_client.py index fa78f764..52351365 100644 --- a/nbclient/tests/test_client.py +++ b/nbclient/tests/test_client.py @@ -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")),