From cbbc713a77a20ba0c2fe903a4ed409a74f7798ff Mon Sep 17 00:00:00 2001 From: Yuval Langer Date: Tue, 3 May 2016 19:07:33 +0300 Subject: [PATCH 1/2] Make Importing Notebooks guide work again. --- .../Notebook/Importing Notebooks.ipynb | 33 ++++++++++++------- .../Notebook/nbpackage/mynotebook.ipynb | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/docs/source/examples/Notebook/Importing Notebooks.ipynb b/docs/source/examples/Notebook/Importing Notebooks.ipynb index a4dde144b..d0b76a2f2 100644 --- a/docs/source/examples/Notebook/Importing Notebooks.ipynb +++ b/docs/source/examples/Notebook/Importing Notebooks.ipynb @@ -40,7 +40,7 @@ "outputs": [], "source": [ "from IPython import get_ipython\n", - "from IPython.nbformat import current\n", + "from nbformat import read, current_nbformat\n", "from IPython.core.interactiveshell import InteractiveShell" ] }, @@ -130,7 +130,7 @@ " \n", " # load the notebook object\n", " with io.open(path, 'r', encoding='utf-8') as f:\n", - " nb = current.read(f, 'json')\n", + " nb = read(f, current_nbformat)\n", " \n", " \n", " # create the module and add it to sys.modules\n", @@ -148,10 +148,10 @@ " self.shell.user_ns = mod.__dict__\n", " \n", " try:\n", - " for cell in nb.worksheets[0].cells:\n", - " if cell.cell_type == 'code' and cell.language == 'python':\n", + " for cell in nb.cells:\n", + " if cell.cell_type == 'code':\n", " # transform the input to executable Python\n", - " code = self.shell.input_transformer_manager.transform_cell(cell.input)\n", + " code = self.shell.input_transformer_manager.transform_cell(cell.source)\n", " # run the code in themodule\n", " exec(code, mod.__dict__)\n", " finally:\n", @@ -261,7 +261,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "So I should be able to `import nbimp.mynotebook`.\n" + "So I should be able to `import nbpackage.mynotebook`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import nbpackage.mynotebook" ] }, { @@ -316,12 +327,12 @@ "def show_notebook(fname):\n", " \"\"\"display a short summary of the cells of a notebook\"\"\"\n", " with io.open(fname, 'r', encoding='utf-8') as f:\n", - " nb = current.read(f, 'json')\n", + " nb = read(f, current_nbformat)\n", " html = []\n", - " for cell in nb.worksheets[0].cells:\n", + " for cell in nb.cells:\n", " html.append(\"

%s cell

\" % cell.cell_type)\n", " if cell.cell_type == 'code':\n", - " html.append(highlight(cell.input, lexer, formatter))\n", + " html.append(highlight(cell.source, lexer, formatter))\n", " else:\n", " html.append(\"
%s
\" % cell.source)\n", " display(HTML('\\n'.join(html)))\n", @@ -463,7 +474,7 @@ "outputs": [], "source": [ "import shutil\n", - "from IPython.utils.path import get_ipython_package_dir\n", + "from IPython.paths import get_ipython_package_dir\n", "\n", "utils = os.path.join(get_ipython_package_dir(), 'utils')\n", "shutil.copy(os.path.join(\"nbpackage\", \"mynotebook.ipynb\"),\n", @@ -515,7 +526,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.5.1+" } }, "nbformat": 4, diff --git a/docs/source/examples/Notebook/nbpackage/mynotebook.ipynb b/docs/source/examples/Notebook/nbpackage/mynotebook.ipynb index fd3920ca4..191e181af 100644 --- a/docs/source/examples/Notebook/nbpackage/mynotebook.ipynb +++ b/docs/source/examples/Notebook/nbpackage/mynotebook.ipynb @@ -61,7 +61,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.2" + "version": "3.5.1+" } }, "nbformat": 4, From 80ae2c9322d71791ae732d5ba86b43040f7ae493 Mon Sep 17 00:00:00 2001 From: Yuval Langer Date: Tue, 3 May 2016 20:07:28 +0300 Subject: [PATCH 2/2] Use fixed version number. --- docs/source/examples/Notebook/Importing Notebooks.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/examples/Notebook/Importing Notebooks.ipynb b/docs/source/examples/Notebook/Importing Notebooks.ipynb index d0b76a2f2..a7cdbcbce 100644 --- a/docs/source/examples/Notebook/Importing Notebooks.ipynb +++ b/docs/source/examples/Notebook/Importing Notebooks.ipynb @@ -40,7 +40,7 @@ "outputs": [], "source": [ "from IPython import get_ipython\n", - "from nbformat import read, current_nbformat\n", + "from nbformat import read\n", "from IPython.core.interactiveshell import InteractiveShell" ] }, @@ -130,7 +130,7 @@ " \n", " # load the notebook object\n", " with io.open(path, 'r', encoding='utf-8') as f:\n", - " nb = read(f, current_nbformat)\n", + " nb = read(f, 4)\n", " \n", " \n", " # create the module and add it to sys.modules\n", @@ -327,7 +327,7 @@ "def show_notebook(fname):\n", " \"\"\"display a short summary of the cells of a notebook\"\"\"\n", " with io.open(fname, 'r', encoding='utf-8') as f:\n", - " nb = read(f, current_nbformat)\n", + " nb = read(f, 4)\n", " html = []\n", " for cell in nb.cells:\n", " html.append(\"

%s cell

\" % cell.cell_type)\n",