From 8c5c3d20823d74a8b159e9334df07f30522beb27 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 18 Jan 2018 10:51:59 +0000 Subject: [PATCH 1/2] Add failing test for gh-657 --- .../tests/files/Empty Cell.ipynb | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 nbconvert/preprocessors/tests/files/Empty Cell.ipynb diff --git a/nbconvert/preprocessors/tests/files/Empty Cell.ipynb b/nbconvert/preprocessors/tests/files/Empty Cell.ipynb new file mode 100644 index 000000000..202dc194c --- /dev/null +++ b/nbconvert/preprocessors/tests/files/Empty Cell.ipynb @@ -0,0 +1,79 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Test that executing skips over an empty cell." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Code 1'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Code 1\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Code 2'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Code 2\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From f8f8cac8c1765a02106086d7d7df48c6a42140da Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 18 Jan 2018 10:55:00 +0000 Subject: [PATCH 2/2] Skip executing empty code cells This matches the behaviour of the notebook application. Closes gh-657 --- nbconvert/preprocessors/execute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbconvert/preprocessors/execute.py b/nbconvert/preprocessors/execute.py index f5cca4280..0dbc6d5c8 100644 --- a/nbconvert/preprocessors/execute.py +++ b/nbconvert/preprocessors/execute.py @@ -290,7 +290,7 @@ def preprocess_cell(self, cell, resources, cell_index): To execute all cells see :meth:`preprocess`. """ - if cell.cell_type != 'code': + if cell.cell_type != 'code' or not cell.source.strip(): return cell, resources reply, outputs = self.run_cell(cell, cell_index)