MyST-NB icon indicating copy to clipboard operation
MyST-NB copied to clipboard

Register render plugins without using entrypoints

Open jacobtomlinson opened this issue 2 years ago • 1 comments

Context

I'm trying to do a little custom rendering on the first cell in each notebook. I want to use the cell metadata to add some extra elements.

My understanding is that I need to implement a custom renderer to do this, install it as a Python module with an entrypoint and configure it in my conf.py. https://myst-nb.readthedocs.io/en/latest/render/format_code_cells.html#customise-the-render-process

When I write custom sphinx extensions I usually just add them to my Python path and load them by their module name. I think this is a pretty common practice.

# conf.py
import os
import sys

sys.path.insert(0, os.path.abspath("../extensions"))

extensions = [
    ...,
    "some_file_in_extensions",
]

However, with the MyST-NB plugin needing to be registered via an entrypoint it seems I would need to make my docs an installable Python module with a pyproject.toml/setup.py so that I can set the entrypoint. This has implications for everyone developing the docs and would require CI changes too. I'd prefer to avoid this.

Proposal

Could plugins be registered via conf.py in a way where they don't need to be installed? Could nb_render_plugin just check if the value is an importable class?

nb_render_plugin = "some_file_in_extensions:MyAwesomeRenderer"

Alternative solutions

I did also look into whether I could register an entrypoint in my conf.py to point to a file in my extensions directory and ended up on this SO answer https://stackoverflow.com/a/50789191/1003288. But I'm not sure if that's a good route to go down.

Any advice would be appreciated.

jacobtomlinson avatar Jan 20 '23 16:01 jacobtomlinson

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar Jan 20 '23 16:01 welcome[bot]