nbsphinx icon indicating copy to clipboard operation
nbsphinx copied to clipboard

Default thumbnail asset not found

Open wpbonelli opened this issue 1 year ago • 3 comments

I'm using nbsphinx to a create a notebook gallery. I am using nbsphinx_execute = "never" and converting python scripts to notebooks with jupytext in GitHub Actions CI, then uploading the notebooks for ReadTheDocs to consume. The reason for this is to avoid timeouts on RTD, some of the notebooks are slow.

Note the empty thumbnails for some of the notebooks, for instance the "Advgwtidal example". I see a request going out for the thumbnail and returning 404:

GET https://modflow6-examples.readthedocs.io/en/latest/_images/_notebooks_ex-gwf-advtidal_10_5.png

Opening the notebook page, all the plots load fine via:

GET https://modflow6-examples.readthedocs.io/en/latest/_images/_notebooks_ex-gwf-advtidal_10_1.png
GET https://modflow6-examples.readthedocs.io/en/latest/_images/_notebooks_ex-gwf-advtidal_10_2.png
GET https://modflow6-examples.readthedocs.io/en/latest/_images/_notebooks_ex-gwf-advtidal_10_3.png
GET https://modflow6-examples.readthedocs.io/en/latest/_images/_notebooks_ex-gwf-advtidal_10_4.png

Why is the thumbnail index 5, when there are only 4 plots in the notebook, and nbsphinx is not re-executing the notebook?

A locally built/served site (with latest sphinx and nbsphinx) shows the correct thumbnails, and the thumbnail retrieved for the gallery page is the same asset as the one shown in the notebook (the index is 626, I presume because I've run the notebook many times).

wpbonelli avatar May 07 '24 19:05 wpbonelli

Thanks for reporting this!

I don't know yet how to solve this, but it might have something to do with https://github.com/jupyter/nbconvert/pull/2089, which caused #776 a.k.a. https://github.com/jupyter/nbconvert/issues/2092, and which was (partially?) fixed in https://github.com/jupyter/nbconvert/pull/2142.

Why is the thumbnail index 5, when there are only 4 plots in the notebook, and nbsphinx is not re-executing the notebook?

Yeah, that's the question!

I guess it has to do with the plain text outputs that come before:

In some situations those seem to be considered as a single output (with index 0), which leads to index 1 to 4 for the plots.

However, in some other situations those seem to be considered two outputs (with index 0 and 1), which would lead to index 2 to 5 for the plots.

The behavior might differ depending on the nbconvert version.

mgeier avatar May 09 '24 12:05 mgeier

I think it works with nbconvert==7.16.3, but it doesn't work with nbconvert<7.14 nor with nbconvert==7.16.4.

mgeier avatar May 09 '24 13:05 mgeier

nbconvert 7.16.3 does work! thanks for the tip.

wpbonelli avatar May 11 '24 05:05 wpbonelli

#797 should fix this problem for nbconvert>=7.14.

mgeier avatar May 13 '24 18:05 mgeier

converting python scripts to notebooks with jupytext in GitHub Actions CI

Out of curiosity, how exactly do you execute your notebooks?

When I try executing a notebook with two consecutive stream outputs, those get merged into one stream output. So far I wasn't able to create a notebook with consecutive stream outputs (which means that this issue cannot arise in the first place).

mgeier avatar May 13 '24 19:05 mgeier

how exactly do you execute your notebooks?

With jupytext e.g. jupytext --from py --to ipynb --execute ..., invoked from python with Popen(...), driven by pytest executing in parallel via xdist. Here is a CI run. It's a bit goldberg...

wpbonelli avatar May 13 '24 23:05 wpbonelli

I still can't reproduce this with two print() calls. How/where it the following line in your output created?

<flopy.mf6.data.mfstructure.MFDataItemStructure object at 0x7fda3d9d2ac0>

BTW, removing this output would also have solved the thumbnail problem.

mgeier avatar May 16 '24 19:05 mgeier

BTW, removing this output would also have solved the thumbnail problem.

I didn't notice the connection between missing thumbnails and text output in the cell that creates the plot. Thanks!

How/where it the following line in your output created?

Deep inside the flopy package, I will have to dig for it — it should really be suppressed in any case

wpbonelli avatar May 17 '24 01:05 wpbonelli