From 14b512c3bbac5547153957757e452f89fada1cd0 Mon Sep 17 00:00:00 2001 From: Rens Date: Sun, 2 Mar 2025 14:53:56 +0100 Subject: [PATCH 01/12] Replace TypeDispatch with Plum Function in showdoc --- nbdev/showdoc.py | 4 +- nbs/api/08_showdoc.ipynb | 277 +++------------------------------------ settings.ini | 2 +- 3 files changed, 18 insertions(+), 265 deletions(-) diff --git a/nbdev/showdoc.py b/nbdev/showdoc.py index 7361ca442..8f317acea 100644 --- a/nbdev/showdoc.py +++ b/nbdev/showdoc.py @@ -7,13 +7,13 @@ from .doclinks import * from .config import get_config -from fastcore.dispatch import TypeDispatch from fastcore.docments import * from fastcore.utils import * from importlib import import_module import inspect, sys from collections import OrderedDict +from plum import Function from textwrap import fill from types import FunctionType @@ -189,7 +189,7 @@ def show_doc(sym, # Symbol to document elif isinstance(renderer,str): p,m = renderer.rsplit('.', 1) renderer = getattr(import_module(p), m) - if isinstance(sym, TypeDispatch): pass + if isinstance(sym, Function): pass else:return renderer(sym or show_doc, name=name, title_level=title_level) # %% ../nbs/api/08_showdoc.ipynb diff --git a/nbs/api/08_showdoc.ipynb b/nbs/api/08_showdoc.ipynb index 8f25cfcf5..b3f1f9460 100644 --- a/nbs/api/08_showdoc.ipynb +++ b/nbs/api/08_showdoc.ipynb @@ -32,13 +32,13 @@ "from nbdev.doclinks import *\n", "from nbdev.config import get_config\n", "\n", - "from fastcore.dispatch import TypeDispatch\n", "from fastcore.docments import *\n", "from fastcore.utils import *\n", "\n", "from importlib import import_module\n", "import inspect, sys\n", "from collections import OrderedDict\n", + "from plum import Function\n", "from textwrap import fill\n", "from types import FunctionType" ] @@ -648,7 +648,7 @@ " elif isinstance(renderer,str):\n", " p,m = renderer.rsplit('.', 1)\n", " renderer = getattr(import_module(p), m)\n", - " if isinstance(sym, TypeDispatch): pass\n", + " if isinstance(sym, Function): pass\n", " else:return renderer(sym or show_doc, name=name, title_level=title_level)" ] }, @@ -681,47 +681,7 @@ "execution_count": null, "id": "8b9e9b32", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### f\n", - "\n", - "> f (x=1)\n", - "\n", - "func docstring in the numpy style.\n", - "\n", - "This is another line of the docstring.\n", - "\n", - "| | **Type** | **Default** | **Details** |\n", - "| -- | -------- | ----------- | ----------- |\n", - "| x | int | 1 | the parameter x |\n", - "| **Returns** | **None** | | **this function doesn't return anything** |" - ], - "text/plain": [ - "---\n", - "\n", - "### f\n", - "\n", - "> f (x=1)\n", - "\n", - "func docstring in the numpy style.\n", - "\n", - "This is another line of the docstring.\n", - "\n", - "| | **Type** | **Default** | **Details** |\n", - "| -- | -------- | ----------- | ----------- |\n", - "| x | int | 1 | the parameter x |\n", - "| **Returns** | **None** | | **this function doesn't return anything** |" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "def f(x=1):\n", @@ -777,33 +737,7 @@ "execution_count": null, "id": "1c28ec9d-29ff-497f-97b0-ca262f530cf6", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### Foo\n", - "\n", - "> Foo (d:str, e:int)\n", - "\n", - "This is the docstring for the `__init__` method" - ], - "text/plain": [ - "---\n", - "\n", - "### Foo\n", - "\n", - "> Foo (d:str, e:int)\n", - "\n", - "This is the docstring for the `__init__` method" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "class Foo:\n", @@ -831,45 +765,7 @@ "execution_count": null, "id": "3441e6c7-472b-411c-a179-b1e37dcbceac", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### Foo.a_method\n", - "\n", - "> Foo.a_method (a:list, b:dict, c)\n", - "\n", - "This is a method\n", - "\n", - "| | **Type** | **Details** |\n", - "| -- | -------- | ----------- |\n", - "| a | list | param a |\n", - "| b | dict | |\n", - "| c | | |" - ], - "text/plain": [ - "---\n", - "\n", - "### Foo.a_method\n", - "\n", - "> Foo.a_method (a:list, b:dict, c)\n", - "\n", - "This is a method\n", - "\n", - "| | **Type** | **Details** |\n", - "| -- | -------- | ----------- |\n", - "| a | list | param a |\n", - "| b | dict | |\n", - "| c | | |" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "@patch\n", @@ -909,33 +805,7 @@ "execution_count": null, "id": "f2727145-be26-4fd1-b67c-78efae89b871", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### Foo.some_prop\n", - "\n", - "> Foo.some_prop ()\n", - "\n", - "This is a class property." - ], - "text/plain": [ - "---\n", - "\n", - "### Foo.some_prop\n", - "\n", - "> Foo.some_prop ()\n", - "\n", - "This is a class property." - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "show_doc(Foo.some_prop)" @@ -1042,25 +912,7 @@ "execution_count": null, "id": "37b5a903", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "

show_doc

\n", - "
show_doc (sym, renderer=None, name:str|None=None, title_level:int=3)

Show signature and docstring for `sym`


source\n", - " \n", - " \n", - "
Type Default Details
sym Symbol to document
renderer NoneType None Optional renderer (defaults to markdown)
name str | None None Optionally override displayed name of `sym`
title_level int 3 Heading level to use for symbol name
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#|hide\n", "doc(show_doc)" @@ -1071,23 +923,7 @@ "execution_count": null, "id": "059071e3", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "

F

\n", - "
F(x:int=1)

class docstring

" - ], - "text/plain": [ - "<__main__.BasicHtmlRenderer>" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "class F:\n", @@ -1114,43 +950,7 @@ "execution_count": null, "id": "e217c559-58b6-49a5-bb58-1575a4a42ded", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### F.class_method\n", - "\n", - "> F.class_method (foo:str, bar:int)\n", - "\n", - "This is a class method.\n", - "\n", - "| | **Type** | **Details** |\n", - "| -- | -------- | ----------- |\n", - "| foo | str | docment for parameter foo |\n", - "| bar | int | |" - ], - "text/plain": [ - "---\n", - "\n", - "### F.class_method\n", - "\n", - "> F.class_method (foo:str, bar:int)\n", - "\n", - "This is a class method.\n", - "\n", - "| | **Type** | **Details** |\n", - "| -- | -------- | ----------- |\n", - "| foo | str | docment for parameter foo |\n", - "| bar | int | |" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "_res = show_doc(F.class_method)\n", @@ -1174,41 +974,7 @@ "execution_count": null, "id": "57a1e24f-2534-41d7-ad98-ade5d42f096c", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### F.regular_method\n", - "\n", - "> F.regular_method (baz:bool=True)\n", - "\n", - "This is a regular method\n", - "\n", - "| | **Type** | **Default** | **Details** |\n", - "| -- | -------- | ----------- | ----------- |\n", - "| baz | bool | True | docment for parameter baz |" - ], - "text/plain": [ - "---\n", - "\n", - "### F.regular_method\n", - "\n", - "> F.regular_method (baz:bool=True)\n", - "\n", - "This is a regular method\n", - "\n", - "| | **Type** | **Default** | **Details** |\n", - "| -- | -------- | ----------- | ----------- |\n", - "| baz | bool | True | docment for parameter baz |" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "show_doc(F.regular_method)" @@ -1300,20 +1066,7 @@ "execution_count": null, "id": "80e0a6cd", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "[Open `index` in Colab](https://colab.research.google.com/github/fastai/nbdev/blob/master/nbs/index.ipynb)" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "colab_link('index')" ] @@ -1334,7 +1087,7 @@ "outputs": [], "source": [ "#|hide\n", - "from fastcore.dispatch import typedispatch" + "from plum import dispatch" ] }, { @@ -1345,7 +1098,7 @@ "outputs": [], "source": [ "#|hide\n", - "@typedispatch\n", + "@dispatch\n", "def _typ_test(\n", " a:list, # A list\n", " b:str, # A second integer\n", @@ -1353,7 +1106,7 @@ " \"Perform op\"\n", " return a.extend(b)\n", "\n", - "@typedispatch\n", + "@dispatch\n", "def _typ_test(\n", " a:str, # An integer\n", " b:str # A str\n", @@ -1361,7 +1114,7 @@ " \"Perform op\"\n", " return str(a) + b\n", "\n", - "test_eq(show_doc(_typ_test), None) # show_doc ignores typedispatch at the moment" + "test_eq(show_doc(_typ_test), None) # show_doc ignores dispatch at the moment" ] }, { diff --git a/settings.ini b/settings.ini index 8d766f219..6bebcf767 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.5.27 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools +requirements = fastcore>=1.5.27 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai From 53e8d127c1cba446653cfd1495bbcb7a9be44185 Mon Sep 17 00:00:00 2001 From: Rens Date: Mon, 3 Mar 2025 19:33:44 +0100 Subject: [PATCH 02/12] update fastcore requirement to version 1.8.0 where TypeDispatch is removed --- settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.ini b/settings.ini index 6bebcf767..8c1af29bc 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.5.27 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum +requirements = fastcore>=1.8.0 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai From 7380e06589d8833df753dee2d81d7e3a89daef1e Mon Sep 17 00:00:00 2001 From: Rens Date: Mon, 3 Mar 2025 20:04:20 +0100 Subject: [PATCH 03/12] fix plum requirement --- settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.ini b/settings.ini index 8c1af29bc..ab69c59ab 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.8.0 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum +requirements = fastcore>=1.8.0 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum-dispatch pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai From 2e2df88b6d93d4ce70737acd570cc3a2d80bd767 Mon Sep 17 00:00:00 2001 From: Rens Date: Mon, 3 Mar 2025 20:10:03 +0100 Subject: [PATCH 04/12] show nb outputs --- nbs/api/08_showdoc.ipynb | 265 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 256 insertions(+), 9 deletions(-) diff --git a/nbs/api/08_showdoc.ipynb b/nbs/api/08_showdoc.ipynb index b3f1f9460..29b2179ef 100644 --- a/nbs/api/08_showdoc.ipynb +++ b/nbs/api/08_showdoc.ipynb @@ -681,7 +681,47 @@ "execution_count": null, "id": "8b9e9b32", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### f\n", + "\n", + "> f (x=1)\n", + "\n", + "func docstring in the numpy style.\n", + "\n", + "This is another line of the docstring.\n", + "\n", + "| | **Type** | **Default** | **Details** |\n", + "| -- | -------- | ----------- | ----------- |\n", + "| x | int | 1 | the parameter x |\n", + "| **Returns** | **None** | | **this function doesn't return anything** |" + ], + "text/plain": [ + "---\n", + "\n", + "### f\n", + "\n", + "> f (x=1)\n", + "\n", + "func docstring in the numpy style.\n", + "\n", + "This is another line of the docstring.\n", + "\n", + "| | **Type** | **Default** | **Details** |\n", + "| -- | -------- | ----------- | ----------- |\n", + "| x | int | 1 | the parameter x |\n", + "| **Returns** | **None** | | **this function doesn't return anything** |" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "def f(x=1):\n", @@ -737,7 +777,33 @@ "execution_count": null, "id": "1c28ec9d-29ff-497f-97b0-ca262f530cf6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### Foo\n", + "\n", + "> Foo (d:str, e:int)\n", + "\n", + "This is the docstring for the `__init__` method" + ], + "text/plain": [ + "---\n", + "\n", + "### Foo\n", + "\n", + "> Foo (d:str, e:int)\n", + "\n", + "This is the docstring for the `__init__` method" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "class Foo:\n", @@ -765,7 +831,45 @@ "execution_count": null, "id": "3441e6c7-472b-411c-a179-b1e37dcbceac", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### Foo.a_method\n", + "\n", + "> Foo.a_method (a:list, b:dict, c)\n", + "\n", + "This is a method\n", + "\n", + "| | **Type** | **Details** |\n", + "| -- | -------- | ----------- |\n", + "| a | list | param a |\n", + "| b | dict | |\n", + "| c | | |" + ], + "text/plain": [ + "---\n", + "\n", + "### Foo.a_method\n", + "\n", + "> Foo.a_method (a:list, b:dict, c)\n", + "\n", + "This is a method\n", + "\n", + "| | **Type** | **Details** |\n", + "| -- | -------- | ----------- |\n", + "| a | list | param a |\n", + "| b | dict | |\n", + "| c | | |" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "@patch\n", @@ -805,7 +909,33 @@ "execution_count": null, "id": "f2727145-be26-4fd1-b67c-78efae89b871", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### Foo.some_prop\n", + "\n", + "> Foo.some_prop ()\n", + "\n", + "This is a class property." + ], + "text/plain": [ + "---\n", + "\n", + "### Foo.some_prop\n", + "\n", + "> Foo.some_prop ()\n", + "\n", + "This is a class property." + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "show_doc(Foo.some_prop)" @@ -912,7 +1042,25 @@ "execution_count": null, "id": "37b5a903", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "

show_doc

\n", + "
show_doc (sym, renderer=None, name:str|None=None, title_level:int=3)

Show signature and docstring for `sym`


source\n", + " \n", + " \n", + "
Type Default Details
sym Symbol to document
renderer NoneType None Optional renderer (defaults to markdown)
name str | None None Optionally override displayed name of `sym`
title_level int 3 Heading level to use for symbol name
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#|hide\n", "doc(show_doc)" @@ -923,7 +1071,23 @@ "execution_count": null, "id": "059071e3", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "

F

\n", + "
F(x:int=1)

class docstring

" + ], + "text/plain": [ + "<__main__.BasicHtmlRenderer>" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "class F:\n", @@ -950,7 +1114,43 @@ "execution_count": null, "id": "e217c559-58b6-49a5-bb58-1575a4a42ded", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### F.class_method\n", + "\n", + "> F.class_method (foo:str, bar:int)\n", + "\n", + "This is a class method.\n", + "\n", + "| | **Type** | **Details** |\n", + "| -- | -------- | ----------- |\n", + "| foo | str | docment for parameter foo |\n", + "| bar | int | |" + ], + "text/plain": [ + "---\n", + "\n", + "### F.class_method\n", + "\n", + "> F.class_method (foo:str, bar:int)\n", + "\n", + "This is a class method.\n", + "\n", + "| | **Type** | **Details** |\n", + "| -- | -------- | ----------- |\n", + "| foo | str | docment for parameter foo |\n", + "| bar | int | |" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "_res = show_doc(F.class_method)\n", @@ -974,7 +1174,41 @@ "execution_count": null, "id": "57a1e24f-2534-41d7-ad98-ade5d42f096c", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### F.regular_method\n", + "\n", + "> F.regular_method (baz:bool=True)\n", + "\n", + "This is a regular method\n", + "\n", + "| | **Type** | **Default** | **Details** |\n", + "| -- | -------- | ----------- | ----------- |\n", + "| baz | bool | True | docment for parameter baz |" + ], + "text/plain": [ + "---\n", + "\n", + "### F.regular_method\n", + "\n", + "> F.regular_method (baz:bool=True)\n", + "\n", + "This is a regular method\n", + "\n", + "| | **Type** | **Default** | **Details** |\n", + "| -- | -------- | ----------- | ----------- |\n", + "| baz | bool | True | docment for parameter baz |" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "show_doc(F.regular_method)" @@ -1066,7 +1300,20 @@ "execution_count": null, "id": "80e0a6cd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "[Open `index` in Colab](https://colab.research.google.com/github/fastai/nbdev/blob/master/nbs/index.ipynb)" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "colab_link('index')" ] From e3844f3cdc1e0a106cbbe08161029ac9d6238b03 Mon Sep 17 00:00:00 2001 From: Rens Date: Mon, 3 Mar 2025 20:13:27 +0100 Subject: [PATCH 05/12] Revert fastcore requirement to version 1.5.27 --- settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.ini b/settings.ini index ab69c59ab..bc91a6616 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.8.0 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum-dispatch +requirements = fastcore>=1.5.27 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum-dispatch pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai From eddb9443ac4ab3f08b4a71cd8e3c9253dd78a9f5 Mon Sep 17 00:00:00 2001 From: Jeremy Howard Date: Sat, 8 Mar 2025 10:03:06 +1000 Subject: [PATCH 06/12] fixes #1504 --- settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.ini b/settings.ini index 8d766f219..a62accf50 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.5.27 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools +requirements = fastcore>=1.5.27 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai From f53f6a3c5a184f9e94e8fc6ae855cb4e18bc140d Mon Sep 17 00:00:00 2001 From: Jeremy Howard Date: Sat, 8 Mar 2025 10:03:34 +1000 Subject: [PATCH 07/12] bump --- nbdev/__init__.py | 2 +- settings.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nbdev/__init__.py b/nbdev/__init__.py index 8e375122b..bd799b77f 100644 --- a/nbdev/__init__.py +++ b/nbdev/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.3.35" +__version__ = "2.3.36" from .doclinks import nbdev_export from .showdoc import show_doc diff --git a/settings.ini b/settings.ini index a62accf50..d982feedb 100644 --- a/settings.ini +++ b/settings.ini @@ -9,7 +9,7 @@ author = Jeremy Howard and Hamel Husain author_email = j@fast.ai branch = master min_python = 3.7 -version = 2.3.35 +version = 2.3.36 audience = Developers language = English custom_sidebar = True From 8b8e26ac9bba5e839c31a6dc7a870b1fd9d75444 Mon Sep 17 00:00:00 2001 From: Rens Date: Sat, 15 Mar 2025 11:19:46 +0100 Subject: [PATCH 08/12] Replace TypeDispatch with Plum Function in showdoc --- nbdev/showdoc.py | 4 +- nbs/api/08_showdoc.ipynb | 277 +++------------------------------------ settings.ini | 2 +- 3 files changed, 18 insertions(+), 265 deletions(-) diff --git a/nbdev/showdoc.py b/nbdev/showdoc.py index 7361ca442..8f317acea 100644 --- a/nbdev/showdoc.py +++ b/nbdev/showdoc.py @@ -7,13 +7,13 @@ from .doclinks import * from .config import get_config -from fastcore.dispatch import TypeDispatch from fastcore.docments import * from fastcore.utils import * from importlib import import_module import inspect, sys from collections import OrderedDict +from plum import Function from textwrap import fill from types import FunctionType @@ -189,7 +189,7 @@ def show_doc(sym, # Symbol to document elif isinstance(renderer,str): p,m = renderer.rsplit('.', 1) renderer = getattr(import_module(p), m) - if isinstance(sym, TypeDispatch): pass + if isinstance(sym, Function): pass else:return renderer(sym or show_doc, name=name, title_level=title_level) # %% ../nbs/api/08_showdoc.ipynb diff --git a/nbs/api/08_showdoc.ipynb b/nbs/api/08_showdoc.ipynb index 8f25cfcf5..b3f1f9460 100644 --- a/nbs/api/08_showdoc.ipynb +++ b/nbs/api/08_showdoc.ipynb @@ -32,13 +32,13 @@ "from nbdev.doclinks import *\n", "from nbdev.config import get_config\n", "\n", - "from fastcore.dispatch import TypeDispatch\n", "from fastcore.docments import *\n", "from fastcore.utils import *\n", "\n", "from importlib import import_module\n", "import inspect, sys\n", "from collections import OrderedDict\n", + "from plum import Function\n", "from textwrap import fill\n", "from types import FunctionType" ] @@ -648,7 +648,7 @@ " elif isinstance(renderer,str):\n", " p,m = renderer.rsplit('.', 1)\n", " renderer = getattr(import_module(p), m)\n", - " if isinstance(sym, TypeDispatch): pass\n", + " if isinstance(sym, Function): pass\n", " else:return renderer(sym or show_doc, name=name, title_level=title_level)" ] }, @@ -681,47 +681,7 @@ "execution_count": null, "id": "8b9e9b32", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### f\n", - "\n", - "> f (x=1)\n", - "\n", - "func docstring in the numpy style.\n", - "\n", - "This is another line of the docstring.\n", - "\n", - "| | **Type** | **Default** | **Details** |\n", - "| -- | -------- | ----------- | ----------- |\n", - "| x | int | 1 | the parameter x |\n", - "| **Returns** | **None** | | **this function doesn't return anything** |" - ], - "text/plain": [ - "---\n", - "\n", - "### f\n", - "\n", - "> f (x=1)\n", - "\n", - "func docstring in the numpy style.\n", - "\n", - "This is another line of the docstring.\n", - "\n", - "| | **Type** | **Default** | **Details** |\n", - "| -- | -------- | ----------- | ----------- |\n", - "| x | int | 1 | the parameter x |\n", - "| **Returns** | **None** | | **this function doesn't return anything** |" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "def f(x=1):\n", @@ -777,33 +737,7 @@ "execution_count": null, "id": "1c28ec9d-29ff-497f-97b0-ca262f530cf6", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### Foo\n", - "\n", - "> Foo (d:str, e:int)\n", - "\n", - "This is the docstring for the `__init__` method" - ], - "text/plain": [ - "---\n", - "\n", - "### Foo\n", - "\n", - "> Foo (d:str, e:int)\n", - "\n", - "This is the docstring for the `__init__` method" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "class Foo:\n", @@ -831,45 +765,7 @@ "execution_count": null, "id": "3441e6c7-472b-411c-a179-b1e37dcbceac", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### Foo.a_method\n", - "\n", - "> Foo.a_method (a:list, b:dict, c)\n", - "\n", - "This is a method\n", - "\n", - "| | **Type** | **Details** |\n", - "| -- | -------- | ----------- |\n", - "| a | list | param a |\n", - "| b | dict | |\n", - "| c | | |" - ], - "text/plain": [ - "---\n", - "\n", - "### Foo.a_method\n", - "\n", - "> Foo.a_method (a:list, b:dict, c)\n", - "\n", - "This is a method\n", - "\n", - "| | **Type** | **Details** |\n", - "| -- | -------- | ----------- |\n", - "| a | list | param a |\n", - "| b | dict | |\n", - "| c | | |" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "@patch\n", @@ -909,33 +805,7 @@ "execution_count": null, "id": "f2727145-be26-4fd1-b67c-78efae89b871", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### Foo.some_prop\n", - "\n", - "> Foo.some_prop ()\n", - "\n", - "This is a class property." - ], - "text/plain": [ - "---\n", - "\n", - "### Foo.some_prop\n", - "\n", - "> Foo.some_prop ()\n", - "\n", - "This is a class property." - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "show_doc(Foo.some_prop)" @@ -1042,25 +912,7 @@ "execution_count": null, "id": "37b5a903", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "

show_doc

\n", - "
show_doc (sym, renderer=None, name:str|None=None, title_level:int=3)

Show signature and docstring for `sym`


source\n", - " \n", - " \n", - "
Type Default Details
sym Symbol to document
renderer NoneType None Optional renderer (defaults to markdown)
name str | None None Optionally override displayed name of `sym`
title_level int 3 Heading level to use for symbol name
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#|hide\n", "doc(show_doc)" @@ -1071,23 +923,7 @@ "execution_count": null, "id": "059071e3", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "

F

\n", - "
F(x:int=1)

class docstring

" - ], - "text/plain": [ - "<__main__.BasicHtmlRenderer>" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "class F:\n", @@ -1114,43 +950,7 @@ "execution_count": null, "id": "e217c559-58b6-49a5-bb58-1575a4a42ded", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### F.class_method\n", - "\n", - "> F.class_method (foo:str, bar:int)\n", - "\n", - "This is a class method.\n", - "\n", - "| | **Type** | **Details** |\n", - "| -- | -------- | ----------- |\n", - "| foo | str | docment for parameter foo |\n", - "| bar | int | |" - ], - "text/plain": [ - "---\n", - "\n", - "### F.class_method\n", - "\n", - "> F.class_method (foo:str, bar:int)\n", - "\n", - "This is a class method.\n", - "\n", - "| | **Type** | **Details** |\n", - "| -- | -------- | ----------- |\n", - "| foo | str | docment for parameter foo |\n", - "| bar | int | |" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "_res = show_doc(F.class_method)\n", @@ -1174,41 +974,7 @@ "execution_count": null, "id": "57a1e24f-2534-41d7-ad98-ade5d42f096c", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "---\n", - "\n", - "### F.regular_method\n", - "\n", - "> F.regular_method (baz:bool=True)\n", - "\n", - "This is a regular method\n", - "\n", - "| | **Type** | **Default** | **Details** |\n", - "| -- | -------- | ----------- | ----------- |\n", - "| baz | bool | True | docment for parameter baz |" - ], - "text/plain": [ - "---\n", - "\n", - "### F.regular_method\n", - "\n", - "> F.regular_method (baz:bool=True)\n", - "\n", - "This is a regular method\n", - "\n", - "| | **Type** | **Default** | **Details** |\n", - "| -- | -------- | ----------- | ----------- |\n", - "| baz | bool | True | docment for parameter baz |" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#|hide\n", "show_doc(F.regular_method)" @@ -1300,20 +1066,7 @@ "execution_count": null, "id": "80e0a6cd", "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "[Open `index` in Colab](https://colab.research.google.com/github/fastai/nbdev/blob/master/nbs/index.ipynb)" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "colab_link('index')" ] @@ -1334,7 +1087,7 @@ "outputs": [], "source": [ "#|hide\n", - "from fastcore.dispatch import typedispatch" + "from plum import dispatch" ] }, { @@ -1345,7 +1098,7 @@ "outputs": [], "source": [ "#|hide\n", - "@typedispatch\n", + "@dispatch\n", "def _typ_test(\n", " a:list, # A list\n", " b:str, # A second integer\n", @@ -1353,7 +1106,7 @@ " \"Perform op\"\n", " return a.extend(b)\n", "\n", - "@typedispatch\n", + "@dispatch\n", "def _typ_test(\n", " a:str, # An integer\n", " b:str # A str\n", @@ -1361,7 +1114,7 @@ " \"Perform op\"\n", " return str(a) + b\n", "\n", - "test_eq(show_doc(_typ_test), None) # show_doc ignores typedispatch at the moment" + "test_eq(show_doc(_typ_test), None) # show_doc ignores dispatch at the moment" ] }, { diff --git a/settings.ini b/settings.ini index d982feedb..eae8c208b 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.5.27 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools +requirements = fastcore>=1.5.27 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai From 919294f26315e77f92587c2ac30d6b356258cc42 Mon Sep 17 00:00:00 2001 From: Rens Date: Sat, 15 Mar 2025 11:21:01 +0100 Subject: [PATCH 09/12] update fastcore requirement to version 1.8.0 where TypeDispatch is removed --- settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.ini b/settings.ini index eae8c208b..02c3d0886 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.5.27 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum +requirements = fastcore>=1.8.0 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai From 072948d366d9787e8e043787b5c0db09cf28cd29 Mon Sep 17 00:00:00 2001 From: Rens Date: Sat, 15 Mar 2025 11:21:43 +0100 Subject: [PATCH 10/12] fix plum requirement --- settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.ini b/settings.ini index 02c3d0886..ca54abe31 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.8.0 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum +requirements = fastcore>=1.8.0 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum-dispatch pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai From dd746aed96d2256355f27bb00e3e4cc118c46a3d Mon Sep 17 00:00:00 2001 From: Rens Date: Mon, 3 Mar 2025 20:10:03 +0100 Subject: [PATCH 11/12] show nb outputs --- nbs/api/08_showdoc.ipynb | 265 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 256 insertions(+), 9 deletions(-) diff --git a/nbs/api/08_showdoc.ipynb b/nbs/api/08_showdoc.ipynb index b3f1f9460..29b2179ef 100644 --- a/nbs/api/08_showdoc.ipynb +++ b/nbs/api/08_showdoc.ipynb @@ -681,7 +681,47 @@ "execution_count": null, "id": "8b9e9b32", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### f\n", + "\n", + "> f (x=1)\n", + "\n", + "func docstring in the numpy style.\n", + "\n", + "This is another line of the docstring.\n", + "\n", + "| | **Type** | **Default** | **Details** |\n", + "| -- | -------- | ----------- | ----------- |\n", + "| x | int | 1 | the parameter x |\n", + "| **Returns** | **None** | | **this function doesn't return anything** |" + ], + "text/plain": [ + "---\n", + "\n", + "### f\n", + "\n", + "> f (x=1)\n", + "\n", + "func docstring in the numpy style.\n", + "\n", + "This is another line of the docstring.\n", + "\n", + "| | **Type** | **Default** | **Details** |\n", + "| -- | -------- | ----------- | ----------- |\n", + "| x | int | 1 | the parameter x |\n", + "| **Returns** | **None** | | **this function doesn't return anything** |" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "def f(x=1):\n", @@ -737,7 +777,33 @@ "execution_count": null, "id": "1c28ec9d-29ff-497f-97b0-ca262f530cf6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### Foo\n", + "\n", + "> Foo (d:str, e:int)\n", + "\n", + "This is the docstring for the `__init__` method" + ], + "text/plain": [ + "---\n", + "\n", + "### Foo\n", + "\n", + "> Foo (d:str, e:int)\n", + "\n", + "This is the docstring for the `__init__` method" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "class Foo:\n", @@ -765,7 +831,45 @@ "execution_count": null, "id": "3441e6c7-472b-411c-a179-b1e37dcbceac", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### Foo.a_method\n", + "\n", + "> Foo.a_method (a:list, b:dict, c)\n", + "\n", + "This is a method\n", + "\n", + "| | **Type** | **Details** |\n", + "| -- | -------- | ----------- |\n", + "| a | list | param a |\n", + "| b | dict | |\n", + "| c | | |" + ], + "text/plain": [ + "---\n", + "\n", + "### Foo.a_method\n", + "\n", + "> Foo.a_method (a:list, b:dict, c)\n", + "\n", + "This is a method\n", + "\n", + "| | **Type** | **Details** |\n", + "| -- | -------- | ----------- |\n", + "| a | list | param a |\n", + "| b | dict | |\n", + "| c | | |" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "@patch\n", @@ -805,7 +909,33 @@ "execution_count": null, "id": "f2727145-be26-4fd1-b67c-78efae89b871", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### Foo.some_prop\n", + "\n", + "> Foo.some_prop ()\n", + "\n", + "This is a class property." + ], + "text/plain": [ + "---\n", + "\n", + "### Foo.some_prop\n", + "\n", + "> Foo.some_prop ()\n", + "\n", + "This is a class property." + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "show_doc(Foo.some_prop)" @@ -912,7 +1042,25 @@ "execution_count": null, "id": "37b5a903", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "

show_doc

\n", + "
show_doc (sym, renderer=None, name:str|None=None, title_level:int=3)

Show signature and docstring for `sym`


source\n", + " \n", + " \n", + "
Type Default Details
sym Symbol to document
renderer NoneType None Optional renderer (defaults to markdown)
name str | None None Optionally override displayed name of `sym`
title_level int 3 Heading level to use for symbol name
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#|hide\n", "doc(show_doc)" @@ -923,7 +1071,23 @@ "execution_count": null, "id": "059071e3", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "

F

\n", + "
F(x:int=1)

class docstring

" + ], + "text/plain": [ + "<__main__.BasicHtmlRenderer>" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "class F:\n", @@ -950,7 +1114,43 @@ "execution_count": null, "id": "e217c559-58b6-49a5-bb58-1575a4a42ded", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### F.class_method\n", + "\n", + "> F.class_method (foo:str, bar:int)\n", + "\n", + "This is a class method.\n", + "\n", + "| | **Type** | **Details** |\n", + "| -- | -------- | ----------- |\n", + "| foo | str | docment for parameter foo |\n", + "| bar | int | |" + ], + "text/plain": [ + "---\n", + "\n", + "### F.class_method\n", + "\n", + "> F.class_method (foo:str, bar:int)\n", + "\n", + "This is a class method.\n", + "\n", + "| | **Type** | **Details** |\n", + "| -- | -------- | ----------- |\n", + "| foo | str | docment for parameter foo |\n", + "| bar | int | |" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "_res = show_doc(F.class_method)\n", @@ -974,7 +1174,41 @@ "execution_count": null, "id": "57a1e24f-2534-41d7-ad98-ade5d42f096c", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "---\n", + "\n", + "### F.regular_method\n", + "\n", + "> F.regular_method (baz:bool=True)\n", + "\n", + "This is a regular method\n", + "\n", + "| | **Type** | **Default** | **Details** |\n", + "| -- | -------- | ----------- | ----------- |\n", + "| baz | bool | True | docment for parameter baz |" + ], + "text/plain": [ + "---\n", + "\n", + "### F.regular_method\n", + "\n", + "> F.regular_method (baz:bool=True)\n", + "\n", + "This is a regular method\n", + "\n", + "| | **Type** | **Default** | **Details** |\n", + "| -- | -------- | ----------- | ----------- |\n", + "| baz | bool | True | docment for parameter baz |" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#|hide\n", "show_doc(F.regular_method)" @@ -1066,7 +1300,20 @@ "execution_count": null, "id": "80e0a6cd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "[Open `index` in Colab](https://colab.research.google.com/github/fastai/nbdev/blob/master/nbs/index.ipynb)" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "colab_link('index')" ] From e8653c973cd6d9aa3b460f952ebedb0c7efc28a3 Mon Sep 17 00:00:00 2001 From: Rens Date: Sat, 15 Mar 2025 11:23:46 +0100 Subject: [PATCH 12/12] Revert fastcore requirement to version 1.5.27 --- settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.ini b/settings.ini index ca54abe31..a66af8bbd 100644 --- a/settings.ini +++ b/settings.ini @@ -15,7 +15,7 @@ language = English custom_sidebar = True license = apache2 status = 5 -requirements = fastcore>=1.8.0 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum-dispatch +requirements = fastcore>=1.5.27 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum-dispatch pip_requirements = PyYAML conda_requirements = pyyaml conda_user = fastai