Skip to content

feat: allow passing kernel manager to parser#721

Open
flying-sheep wants to merge 1 commit into
executablebooks:mainfrom
flying-sheep:km
Open

feat: allow passing kernel manager to parser#721
flying-sheep wants to merge 1 commit into
executablebooks:mainfrom
flying-sheep:km

Conversation

@flying-sheep

@flying-sheep flying-sheep commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Hi, I built sphinx-exec-jupyter to leverage myst-nb’s machinery for running code blocks in isolation.

In it, I’m using a custom KernelClient for efficiency.

This client needs to be passed down all the way to executenb, and it would be great if that was possible without monkeypatching myst-nb.

Usage

It can be used directly when using a Parser programmaticly:

from myst_nb.sphinx_ import Parser

parser = Parser(km=MyKernelManager())
parser.parse(...)

… or by overriding the registered parser in a Sphinx extension like this:

from docutils import nodes
from myst_nb.sphinx_ import Parser

class SomeKernelManager(...): ...

class MyParser(Parser):
    # could override in `__init__` or here
    def parse(self, inputstring: str, document: nodes.document) -> None:
        self.km = MyKernelManager(document.settings.env)
        return super().parse(inputstring, document)

def setup(app):
    app.setup_extension("myst_nb")
    app.add_source_parser(MyParser, override=True)

Possible alternatives

  • Instead of adding the km property to the parser and passing them to create_client, we could wrap create_client into a method on Parser, then I could override it. The other changes would still be necessary.

  • In addition to the above method, I could break up parse into more granular steps in general for easier extensibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant