Exemplo n.º 1
0
def setup(app):
    # Configuration
    app.add_config_value('jupyter_execute_kwargs',
                         dict(timeout=-1, allow_errors=True), 'env')
    app.add_config_value('jupyter_execute_default_kernel', 'python3', 'env')
    app.add_config_value(
        'jupyter_execute_data_priority',
        [
            WIDGET_VIEW_MIMETYPE, 'text/html', 'image/svg+xml', 'image/png',
            'image/jpeg', 'text/latex', 'text/plain'
        ],
        'env',
    )

    # KernelNode is just a doctree marker for the ExecuteJupyterCells
    # transform, so we don't actually render it.
    def skip(self, node):
        raise docutils.nodes.SkipNode

    app.add_node(
        KernelNode,
        html=(skip, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    app.add_node(
        Cell,
        html=(visit_container, depart_container),
        latex=(visit_container, depart_container),
        textinfo=(visit_container, depart_container),
        text=(visit_container, depart_container),
        man=(visit_container, depart_container),
    )

    app.add_directive('jupyter-execute', JupyterCell)
    app.add_directive('jupyter-kernel', JupyterKernel)
    app.add_role('jupyter-download:notebook', jupyter_download_role)
    app.add_role('jupyter-download:script', jupyter_download_role)
    app.add_transform(ExecuteJupyterCells)

    # For syntax highlighting
    app.add_lexer('ipythontb', IPythonTracebackLexer())
    app.add_lexer('ipython', IPython3Lexer())

    return {'version': __version__}
Exemplo n.º 2
0
def setup(app):
    # Configuration

    app.add_config_value(
        'jupyter_execute_kwargs',
        dict(timeout=-1, allow_errors=True, store_widget_state=True),
        'env'
    )
    app.add_config_value(
        'jupyter_execute_default_kernel',
        'python3',
        'env'
    )
    app.add_config_value(
        'jupyter_execute_data_priority',
        [
            WIDGET_VIEW_MIMETYPE,
            'application/javascript',
            'text/html',
            'image/svg+xml',
            'image/png',
            'image/jpeg',
            'text/latex',
            'text/plain'
        ],
        'env',
    )

    # ipywidgets config
    app.add_config_value('jupyter_sphinx_require_url', REQUIRE_URL_DEFAULT, 'html')
    app.add_config_value('jupyter_sphinx_embed_url', None, 'html')

    # thebelab config, can be either a filename or a dict
    app.add_config_value('jupyter_sphinx_thebelab_config', None, 'html')

    app.add_config_value('jupyter_sphinx_thebelab_url', THEBELAB_URL_DEFAULT, 'html')

    # linenos config
    app.add_config_value('jupyter_sphinx_linenos', False, 'env')
    app.add_config_value('jupyter_sphinx_continue_linenos', False, 'env')

    # Used for nodes that do not need to be rendered
    def skip(self, node):
        raise docutils.nodes.SkipNode

    # Renders the children of a container
    render_container = (
        lambda self, node: self.visit_container(node),
        lambda self, node: self.depart_container(node),
    )

    # Used to render the container and its children as HTML
    def visit_container_html(self, node):
        self.body.append(node.visit_html())
        self.visit_container(node)

    def depart_container_html(self, node):
        self.depart_container(node)
        self.body.append(node.depart_html())

    # Used to render an element node as HTML
    def visit_element_html(self, node):
        self.body.append(node.html())
        raise docutils.nodes.SkipNode

    # Used to render the ThebeSourceNode conditionally for non-HTML builders
    def visit_thebe_source(self, node):
        if node['hide_code']:
            raise docutils.nodes.SkipNode
        else:
            self.visit_container(node)

    render_thebe_source = (
        visit_thebe_source,
        lambda self, node: self.depart_container(node)
    )


    # JupyterKernelNode is just a doctree marker for the
    # ExecuteJupyterCells transform, so we don't actually render it.
    app.add_node(
        JupyterKernelNode,
        html=(skip, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    # JupyterCellNode is a container that holds the input and
    # any output, so we render it as a container.
    app.add_node(
        JupyterCellNode,
        html=render_container,
        latex=render_container,
        textinfo=render_container,
        text=render_container,
        man=render_container,
    )

    # JupyterWidgetViewNode holds widget view JSON,
    # but is only rendered properly in HTML documents.
    app.add_node(
        JupyterWidgetViewNode,
        html=(visit_element_html, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )
    # JupyterWidgetStateNode holds the widget state JSON,
    # but is only rendered in HTML documents.
    app.add_node(
        JupyterWidgetStateNode,
        html=(visit_element_html, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    # ThebeSourceNode holds the source code and is rendered if
    # hide-code is not specified. For HTML it is always rendered,
    # but hidden using the stylesheet
    app.add_node(
        ThebeSourceNode,
        html=(visit_container_html, depart_container_html),
        latex=render_thebe_source,
        textinfo=render_thebe_source,
        text=render_thebe_source,
        man=render_thebe_source,
    )

    # ThebeOutputNode holds the output of the Jupyter cells
    # and is rendered if hide-output is not specified.
    app.add_node(
        ThebeOutputNode,
        html=(visit_container_html, depart_container_html),
        latex=render_container,
        textinfo=render_container,
        text=render_container,
        man=render_container,
    )

    # ThebeButtonNode is the button that activates thebelab
    # and is only rendered for the HTML builder
    app.add_node(
        ThebeButtonNode,
        html=(visit_element_html, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    app.add_directive('jupyter-execute', JupyterCell)
    app.add_directive('jupyter-kernel', JupyterKernel)
    app.add_directive('thebe-button', ThebeButton)
    app.add_role('jupyter-download:notebook', jupyter_download_role)
    app.add_role('jupyter-download:script', jupyter_download_role)
    app.add_transform(ExecuteJupyterCells)

    # For syntax highlighting
    app.add_lexer('ipythontb', IPythonTracebackLexer())
    app.add_lexer('ipython', IPython3Lexer())

    app.connect('builder-inited', builder_inited)
    app.connect('build-finished', build_finished)

    return {
        'version': __version__,
        'parallel_read_safe': True,
    }
Exemplo n.º 3
0
def setup(app):
    """A temporary setup function so that we can use it here and in execute.

    This should be removed and converted into `setup` after a deprecation
    cycle.
    """
    # Configuration

    app.add_config_value(
        "jupyter_execute_kwargs",
        dict(timeout=-1, allow_errors=True, store_widget_state=True),
        "env",
    )
    app.add_config_value("jupyter_execute_default_kernel", "python3", "env")
    app.add_config_value(
        "jupyter_execute_data_priority",
        [
            WIDGET_VIEW_MIMETYPE,
            "application/javascript",
            "text/html",
            "image/svg+xml",
            "image/png",
            "image/jpeg",
            "text/latex",
            "text/plain",
        ],
        "env",
    )

    # ipywidgets config
    app.add_config_value("jupyter_sphinx_require_url", REQUIRE_URL_DEFAULT,
                         "html")
    app.add_config_value("jupyter_sphinx_embed_url", None, "html")

    # thebelab config, can be either a filename or a dict
    app.add_config_value("jupyter_sphinx_thebelab_config", None, "html")
    app.add_config_value("jupyter_sphinx_thebelab_url", THEBELAB_URL_DEFAULT,
                         "html")

    # linenos config
    app.add_config_value("jupyter_sphinx_linenos", False, "env")
    app.add_config_value("jupyter_sphinx_continue_linenos", False, "env")

    # JupyterKernelNode is just a doctree marker for the
    # ExecuteJupyterCells transform, so we don't actually render it.
    app.add_node(
        JupyterKernelNode,
        html=(skip, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    # Register our container nodes, these should behave just like a regular container
    for node in [JupyterCellNode, CellInputNode, CellOutputNode]:
        app.add_node(
            node,
            override=True,
            html=(render_container),
            latex=(render_container),
            textinfo=(render_container),
            text=(render_container),
            man=(render_container),
        )

    # Register the output bundle node.
    # No translators should touch this node because we'll replace it in a post-transform
    app.add_node(
        CellOutputBundleNode,
        override=True,
        html=(halt, None),
        latex=(halt, None),
        textinfo=(halt, None),
        text=(halt, None),
        man=(halt, None),
    )

    # JupyterWidgetViewNode holds widget view JSON,
    # but is only rendered properly in HTML documents.
    app.add_node(
        JupyterWidgetViewNode,
        html=(visit_element_html, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )
    # JupyterWidgetStateNode holds the widget state JSON,
    # but is only rendered in HTML documents.
    app.add_node(
        JupyterWidgetStateNode,
        html=(visit_element_html, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    # ThebeSourceNode holds the source code and is rendered if
    # hide-code is not specified. For HTML it is always rendered,
    # but hidden using the stylesheet
    app.add_node(
        ThebeSourceNode,
        html=(visit_container_html, depart_container_html),
        latex=render_thebe_source,
        textinfo=render_thebe_source,
        text=render_thebe_source,
        man=render_thebe_source,
    )

    # ThebeOutputNode holds the output of the Jupyter cells
    # and is rendered if hide-output is not specified.
    app.add_node(
        ThebeOutputNode,
        html=(visit_container_html, depart_container_html),
        latex=render_container,
        textinfo=render_container,
        text=render_container,
        man=render_container,
    )

    # ThebeButtonNode is the button that activates thebelab
    # and is only rendered for the HTML builder
    app.add_node(
        ThebeButtonNode,
        html=(visit_element_html, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    app.add_directive("jupyter-execute", JupyterCell)
    app.add_directive("jupyter-kernel", JupyterKernel)
    app.add_directive("thebe-button", ThebeButton)
    app.add_role("jupyter-download:notebook", JupyterDownloadRole())
    app.add_role("jupyter-download:nb", JupyterDownloadRole())
    app.add_role("jupyter-download:script", JupyterDownloadRole())
    app.add_transform(ExecuteJupyterCells)
    app.add_post_transform(CellOutputsToNodes)

    # For syntax highlighting
    app.add_lexer("ipythontb", IPythonTracebackLexer())
    app.add_lexer("ipython", IPython3Lexer())

    app.connect("builder-inited", builder_inited)
    app.connect("build-finished", build_finished)

    return {"version": __version__, "parallel_read_safe": True}
Exemplo n.º 4
0
def setup(app):
    # Configuration
    app.add_config_value(
        'jupyter_execute_kwargs',
        dict(timeout=-1, allow_errors=True, store_widget_state=True), 'env')
    app.add_config_value('jupyter_execute_default_kernel', 'python3', 'env')
    app.add_config_value(
        'jupyter_execute_data_priority',
        [
            WIDGET_VIEW_MIMETYPE, 'application/javascript', 'text/html',
            'image/svg+xml', 'image/png', 'image/jpeg', 'text/latex',
            'text/plain'
        ],
        'env',
    )

    # ipywidgets config
    app.add_config_value('jupyter_sphinx_require_url', REQUIRE_URL_DEFAULT,
                         'html')
    app.add_config_value('jupyter_sphinx_embed_url', None, 'html')

    # JupyterKernelNode is just a doctree marker for the
    # ExecuteJupyterCells transform, so we don't actually render it.
    def skip(self, node):
        raise docutils.nodes.SkipNode

    app.add_node(
        JupyterKernelNode,
        html=(skip, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    # JupyterCellNode is a container that holds the input and
    # any output, so we render it as a container.
    render_container = (
        lambda self, node: self.visit_container(node),
        lambda self, node: self.depart_container(node),
    )

    app.add_node(
        JupyterCellNode,
        html=render_container,
        latex=render_container,
        textinfo=render_container,
        text=render_container,
        man=render_container,
    )

    # JupyterWidgetViewNode holds widget view JSON,
    # but is only rendered properly in HTML documents.
    def visit_widget_html(self, node):
        self.body.append(node.html())
        raise docutils.nodes.SkipNode

    def visit_widget_text(self, node):
        self.body.append(node.text())
        raise docutils.nodes.SkipNode

    app.add_node(
        JupyterWidgetViewNode,
        html=(visit_widget_html, None),
        latex=(visit_widget_text, None),
        textinfo=(visit_widget_text, None),
        text=(visit_widget_text, None),
        man=(visit_widget_text, None),
    )
    # JupyterWidgetStateNode holds the widget state JSON,
    # but is only rendered in HTML documents.
    app.add_node(
        JupyterWidgetStateNode,
        html=(visit_widget_html, None),
        latex=(skip, None),
        textinfo=(skip, None),
        text=(skip, None),
        man=(skip, None),
    )

    app.add_directive('jupyter-execute', JupyterCell)
    app.add_directive('jupyter-kernel', JupyterKernel)
    app.add_role('jupyter-download:notebook', jupyter_download_role)
    app.add_role('jupyter-download:script', jupyter_download_role)
    app.add_transform(ExecuteJupyterCells)

    # For syntax highlighting
    app.add_lexer('ipythontb', IPythonTracebackLexer())
    app.add_lexer('ipython', IPython3Lexer())

    app.connect('builder-inited', builder_inited)

    return {
        'version': __version__,
        'parallel_read_safe': True,
    }