From 21ec33b34215fa14773e9ffb17b0bfe1bec74166 Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Mon, 7 Nov 2022 08:36:03 -0800 Subject: [PATCH 1/4] add parameter for name --- nbdev/export.py | 4 ++-- nbs/_quarto.yml | 2 ++ nbs/api/export.ipynb | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nbdev/export.py b/nbdev/export.py index 5bf813d75..f9db6430f 100644 --- a/nbdev/export.py +++ b/nbdev/export.py @@ -41,7 +41,7 @@ def black_format(cell, # Cell to format except: pass # %% ../nbs/api/export.ipynb 9 -def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker): +def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker, name=None): "Create module(s) from notebook" if lib_path is None: lib_path = get_config().lib_path exp = ExportModuleProc() @@ -49,7 +49,7 @@ def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker= nb.process() for mod,cells in exp.modules.items(): all_cells = exp.in_all[mod] - name = getattr(exp, 'default_exp', None) if mod=='#' else mod + name = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod) if not name: warn(f"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\n" "Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n" diff --git a/nbs/_quarto.yml b/nbs/_quarto.yml index e79329a47..70852950e 100644 --- a/nbs/_quarto.yml +++ b/nbs/_quarto.yml @@ -23,6 +23,8 @@ website: contents: tutorials/* - section: Explanations contents: explanations/* + - section: Integrations + contents: integrations/**/*.ipynb - section: API contents: api/* favicon: favicon.png diff --git a/nbs/api/export.ipynb b/nbs/api/export.ipynb index a579ad13b..f6e99a4d1 100644 --- a/nbs/api/export.ipynb +++ b/nbs/api/export.ipynb @@ -134,7 +134,7 @@ "outputs": [], "source": [ "#|export\n", - "def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker):\n", + "def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker, name=None):\n", " \"Create module(s) from notebook\"\n", " if lib_path is None: lib_path = get_config().lib_path\n", " exp = ExportModuleProc()\n", @@ -142,7 +142,7 @@ " nb.process()\n", " for mod,cells in exp.modules.items():\n", " all_cells = exp.in_all[mod]\n", - " name = getattr(exp, 'default_exp', None) if mod=='#' else mod\n", + " name = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)\n", " if not name:\n", " warn(f\"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\\n\"\n", " \"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\\n\"\n", @@ -185,7 +185,19 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AssertionError", + "evalue": "h_n", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", + "Input \u001b[0;32mIn [10]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m _alls \u001b[38;5;241m=\u001b[39m L(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma b d e m n o p q\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39msplit())\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m _alls\u001b[38;5;241m.\u001b[39mmap(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m_y\u001b[39m\u001b[38;5;124m\"\u001b[39m): \u001b[38;5;28;01massert\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m g, s\n\u001b[0;32m----> 7\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mc_y_nall _f_y_nall g_n h_n i_n j_n k_n l_n\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39msplit(): \u001b[38;5;28;01massert\u001b[39;00m s \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m g, s\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m _alls\u001b[38;5;241m.\u001b[39mmap(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m_y\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;241m+\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mc_y_nall\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_f_y_nall\u001b[39m\u001b[38;5;124m\"\u001b[39m]: \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(g[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtmp\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39meverything,s), s\n", + "\u001b[0;31mAssertionError\u001b[0m: h_n" + ] + } + ], "source": [ "#|eval: false\n", "nb_export(everything_fn, 'tmp')\n", From 331830daee6990b23a938bd5275c4a04e1811151 Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Mon, 7 Nov 2022 08:39:06 -0800 Subject: [PATCH 2/4] undo section --- nbs/_quarto.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/nbs/_quarto.yml b/nbs/_quarto.yml index 70852950e..e79329a47 100644 --- a/nbs/_quarto.yml +++ b/nbs/_quarto.yml @@ -23,8 +23,6 @@ website: contents: tutorials/* - section: Explanations contents: explanations/* - - section: Integrations - contents: integrations/**/*.ipynb - section: API contents: api/* favicon: favicon.png From 24bfcc403e8d9ec6be550a43c72642db8ef44fee Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Mon, 7 Nov 2022 08:42:44 -0800 Subject: [PATCH 3/4] clean notebook --- nbs/api/export.ipynb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/nbs/api/export.ipynb b/nbs/api/export.ipynb index f6e99a4d1..b1f6b318e 100644 --- a/nbs/api/export.ipynb +++ b/nbs/api/export.ipynb @@ -185,19 +185,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "AssertionError", - "evalue": "h_n", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", - "Input \u001b[0;32mIn [10]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m _alls \u001b[38;5;241m=\u001b[39m L(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma b d e m n o p q\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39msplit())\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m _alls\u001b[38;5;241m.\u001b[39mmap(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m_y\u001b[39m\u001b[38;5;124m\"\u001b[39m): \u001b[38;5;28;01massert\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m g, s\n\u001b[0;32m----> 7\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mc_y_nall _f_y_nall g_n h_n i_n j_n k_n l_n\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39msplit(): \u001b[38;5;28;01massert\u001b[39;00m s \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m g, s\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m _alls\u001b[38;5;241m.\u001b[39mmap(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m_y\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;241m+\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mc_y_nall\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_f_y_nall\u001b[39m\u001b[38;5;124m\"\u001b[39m]: \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(g[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtmp\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39meverything,s), s\n", - "\u001b[0;31mAssertionError\u001b[0m: h_n" - ] - } - ], + "outputs": [], "source": [ "#|eval: false\n", "nb_export(everything_fn, 'tmp')\n", From b7d36ef3cf8fe96b78825e673f6d580cbe670d26 Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Mon, 7 Nov 2022 09:24:57 -0800 Subject: [PATCH 4/4] mark it as new if param name is supplied --- nbdev/export.py | 6 +++--- nbs/api/export.ipynb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nbdev/export.py b/nbdev/export.py index f9db6430f..7a6bf785e 100644 --- a/nbdev/export.py +++ b/nbdev/export.py @@ -49,11 +49,11 @@ def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker= nb.process() for mod,cells in exp.modules.items(): all_cells = exp.in_all[mod] - name = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod) - if not name: + nm = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod) + if not nm: warn(f"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\n" "Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n" "See https://nbdev.fast.ai/getting_started.html for more information.") return - mm = mod_maker(dest=lib_path, name=name, nb_path=nbname, is_new=mod=='#') + mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#') mm.make(cells, all_cells, lib_path=lib_path) diff --git a/nbs/api/export.ipynb b/nbs/api/export.ipynb index b1f6b318e..a681147c0 100644 --- a/nbs/api/export.ipynb +++ b/nbs/api/export.ipynb @@ -142,13 +142,13 @@ " nb.process()\n", " for mod,cells in exp.modules.items():\n", " all_cells = exp.in_all[mod]\n", - " name = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)\n", - " if not name:\n", + " nm = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)\n", + " if not nm:\n", " warn(f\"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\\n\"\n", " \"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\\n\"\n", " \"See https://nbdev.fast.ai/getting_started.html for more information.\")\n", " return\n", - " mm = mod_maker(dest=lib_path, name=name, nb_path=nbname, is_new=mod=='#')\n", + " mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#')\n", " mm.make(cells, all_cells, lib_path=lib_path)" ] },