nbsphinx icon indicating copy to clipboard operation
nbsphinx copied to clipboard

Unable to create gallery with notebooks out of the doc tree with nblinkgallery

Open gVallverdu opened this issue 1 year ago • 1 comments

Hi, I have a python project structured like this:

projects/
    - docs/
        source/
        conf.py
        index.rst
        ...
    - src/
        ...
    - notebooks/
        example.ipynb

In my documentation, I would like to include notebooks from the notebooks directory lying in the root directory of the project.

Following this example https://nbsphinx.readthedocs.io/en/typlog-theme/a-normal-rst-file.html#thumbnail-link-galleries-html-only, I tried to write something like this

.. nblinkgallery::
    :caption: A few links

    ../../../notebooks/example.ipynb

But the gallery appears empty. Only the caption is displayed on the html doc.

I got a warning like:

user_doc/index
/Users/gvallver/git/pyc2mc/docs/source/user_doc/index.rst:14: 
WARNING: la table des matières contient des références à des 
documents inexistants 'notebooks/example'

The html output is

<div class="toctree-wrapper compound">
<p class="caption" role="heading"><span class="caption-text">A few links</span></p>
<div class="nbsphinx-gallery">
</div>
</div>

In my conf.py I have

extensions = [
    "sphinx.ext.autodoc",  # automatic generation of doc
    "sphinx.ext.viewcode",  # link to code source in the doc
    "sphinx.ext.napoleon",  # doc format
    "nbsphinx",  # jupyter notebook support
]

gVallverdu avatar Jun 08 '23 20:06 gVallverdu

I use PyScaffold to create templates gives me a folder structure similar to what's mentioned (i.e., a top-level notebooks folder), so this functionality is important to me.

The following is expected behavior:

WARNING: toctree contains reference to nonexisting document

One workaround is to use nbsphinx_link.

Thumbnails present a whole other set of issues: https://nbsphinx.readthedocs.io/en/0.9.2/subdir/gallery.html.

One option for local image files:

from IPython.display import Image
Image(filename="sdl-demo-test.jpg")

Related

  • https://stackoverflow.com/questions/10199233/can-sphinx-link-to-documents-that-are-not-located-in-directories-below-the-root
  • https://buildmedia.readthedocs.org/media/pdf/nbsphinx/latest/nbsphinx.pdf (Section 5.2)

sgbaird avatar Jun 14 '23 09:06 sgbaird