From 3688bf6fce9b56c782c3598ec660977cc9314cf9 Mon Sep 17 00:00:00 2001 From: Jean-Luc Parouty <Jean-Luc.Parouty@grenoble-inp.fr> Date: Sun, 13 Dec 2020 13:41:26 +0100 Subject: [PATCH] Update index generator for README --- fidle/Update_index.ipynb | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/fidle/Update_index.ipynb b/fidle/Update_index.ipynb index a53d231..71c7fa5 100644 --- a/fidle/Update_index.ipynb +++ b/fidle/Update_index.ipynb @@ -7,6 +7,8 @@ "outputs": [], "source": [ "import nbformat\n", + "from nbconvert.preprocessors import ExecutePreprocessor\n", + "\n", "import re\n", "import sys, os, glob\n", "import json\n", @@ -29,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -118,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -188,26 +190,25 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 5, "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'nbf' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-9-85936a69f607>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mnbformat\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mv4\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnew_markdown_cell\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msource\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mreadme\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'../test.ipynb'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'w'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mnbf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnnb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mNameError\u001b[0m: name 'nbf' is not defined" - ] - } - ], + "outputs": [], "source": [ - "nnb = nbformat.v4.new_notebook()\n", - "nbformat.v4.new_markdown_cell(source=readme)\n", - "with open('../test.ipynb', 'w') as f:\n", - " nbf.write(nnb, f)" + "# ---- Create Notebook\n", + "#\n", + "notebook = nbformat.v4.new_notebook()\n", + "new_cell = nbformat.v4.new_markdown_cell(source=readme)\n", + "notebook.cells.append(new_cell)\n", + "\n", + "# ---- Run it\n", + "#\n", + "ep = ExecutePreprocessor(timeout=600, kernel_name=\"python3\")\n", + "ep.preprocess(notebook)\n", + "\n", + "# ---- Save it\n", + "#\n", + "with open('../test.ipynb', mode=\"w\", encoding='utf-8') as fp:\n", + " nbformat.write(notebook, fp)" ] }, { -- GitLab