Support for (plugin) entry_points?

I heard a lot of good things about nbdev so I started using it for my new project: a library of plugins for pyannote.audio speaker diarization toolkit.

I know that nbdev supports creating console_scripts entry-points out of the box thanks to the console_scripts option in settings.ini.

But does it support creating (plugin-like) entry-points (like those introduced in this blog post)?

Based on the absence of answer, I understand that this is not supported.
So I went ahead and thought about a possible syntax for this new feature, using the entry points defined in the aforementioned blog post as an example.

It would rely on an additional [PLUGINS] section in settings.ini:

[PLUGINS]
snek_types = normal=snek:normal_snek fancy=snek:fancy_snek
maus_types = hairy=snek:hairy_maus

and would result in a setup.py populated like that:

setup(
    # ...
    entry_points={
        "snek_types": [
            "normal = snek:normal_snek",
            "fancy = snek:fancy_snek",
        ],
        "maus_types": [
            "hairy = snek:hairy_maus"
        ],
    },
    # ...
)

How does that sound? Would you be interested in a PR adding this feature?

Why don’t you just edit your own setup.py? I am not sure it makes sense to add this globally

I can definitely do that. Just wanted to know whether it would make sense to contribute this upstream since you already have this kind of support for console_scripts.

I am not sure that it does, perhaps if you show me more of an example of what you are trying to do and why this should be part of the library it might become more concrete

Basically, this allows to build a library that adds features to another library.
The aforementionned blog post does a good job explaining this (probably better than I would).

For instance, Explosion’s Prodigy supports this kind of plugin: Installation & Setup · Prodigy · An annotation tool for AI, Machine Learning & NLP
You would write Prodigy recipes in a separate (MyAwesomeRecipes, made by nbdev) library defining prodigy_recipes entrypoints, and these recipes would automatically be detected by Prodigy:

prodigy MyAwesomeRecipes.recipe1 ...

There is an issue to enable plugins and move black formatting functionality to an external plugin also. Move `black_formatting` into an external module · Issue #1001 · fastai/nbdev · GitHub

I believe this is for adding plugins to the nbdev library itself.

I am suggesting a different thing: allowing packages built with nbdev to define plugins.

1 Like

Thanks for the suggestion @hbredin. Personally, I just edit setup.py when creating entry points – I find this works pretty well. I’m not sure adding something to settings.ini for this is a big win personally, since the setup.py version works fine.