fastai / nbdev

Create delightful software with Jupyter Notebooks
https://nbdev.fast.ai/
Apache License 2.0
4.88k stars 488 forks source link

nbdev processor plugin framework #1000

Open jph00 opened 2 years ago

seeM commented 1 year ago

I have a working prototype of this in https://github.com/fastai/nbdev/pull/1157. @muellerzr's nbdev-extensions package is a great example of how a processor plugin would be created and packaged. Here's a rough draft of potential docs that also describes how it works at a high level:

Creating a processor plugin

To develop your own processor plugin, sub-class Processor and override any methods you need to. Check out the nbdev.processors module for examples -- all of nbdev's processing is implemented with pluggable processors.

Once its ready, upload your package to PyPI and/or conda.

For example, the nbdev-extensions package provides the nbdev_extensions.codenotes.NoteExportProc processor, which allows you to annotate code snippets with a new #| explain directive.

Using a processor plugin

First install the package containing the processor. Continuing with the nbdev-extensions example which is hosted on PyPI:

pip install nbdev-extensions

Add the import path to your processor under the procs key of your settings.ini. The import path should follow the same syntax as setuptools console scripts (without the name and equals sign). For example:

procs = nbdev_extensions.codenotes:NoteExportProc

The processor will now be applied in your nbdev project!

jph00 commented 1 year ago

This is looking good! :D