Skip to content

Commit f416ab5

Browse files
authored
Add nbconvert version check (#1333)
* Add mistune version check * check nbconvert version * Update test
1 parent 5de8473 commit f416ab5

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858
voila tests/notebooks/sleep10seconds.ipynb --port=8878 --VoilaConfiguration.http_keep_alive_timeout=2 &
5959
sleep 2
6060
wget --read-timeout=5 --tries=1 http://localhost:8878
61+
# Test nbconvert < 7.6.0
62+
python -m pip install "nbconvert<7.6.0"
63+
VOILA_TEST_XEUS_CLING=1 py.test tests/app/image_inlining_test.py
6164
6265
test-osx:
6366
runs-on: ${{ matrix.os }}

ui-tests/playwright.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ module.exports = {
1616
video: 'retain-on-failure'
1717
},
1818
// Try one retry as some tests are flaky
19-
retries: 1
19+
retries: 1,
20+
expect: {
21+
toMatchSnapshot: {
22+
maxDiffPixelRatio: 0.05
23+
}
24+
}
2025
};

ui-tests/tests/voila.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ test.describe('Voila performance Tests', () => {
105105
const testFunction = async () => {
106106
await page.goto(`/voila/render/${notebookName}.ipynb`);
107107
// wait for the widgets to load
108-
await page.waitForSelector('span[role="presentation"] >> text=x');
108+
await page.waitForSelector('span.mjx-char >> text=x');
109109
};
110110
await addBenchmarkToTest(notebookName, testFunction, testInfo, browserName);
111111
// change the value of the slider
112112
await page.fill('text=4.00', '8.00');
113113
await page.keyboard.down('Enter');
114+
await page.waitForTimeout(500);
114115
// fetch the value of the label
115116
const value = await page.$eval('input', (el) => el.value);
116117

voila/exporter.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#############################################################################
99

1010
import mimetypes
11+
from typing import Optional
1112

1213
import traitlets
1314
from traitlets.config import Config
@@ -20,11 +21,20 @@
2021
from nbconvert.exporters.html import HTMLExporter
2122
from nbconvert.exporters.templateexporter import TemplateExporter
2223
from nbconvert.filters.highlight import Highlight2HTML
23-
from nbconvert.filters.markdown_mistune import IPythonRenderer, MarkdownWithMath
24-
24+
from nbconvert.filters.markdown_mistune import (
25+
IPythonRenderer,
26+
MarkdownWithMath,
27+
)
2528
from .static_file_handler import TemplateStaticFileHandler
2629
from .utils import create_include_assets_functions
2730

31+
try:
32+
from nbconvert.filters.markdown_mistune import MISTUNE_V3 # noqa
33+
34+
NB_CONVERT_760 = True
35+
except ImportError:
36+
NB_CONVERT_760 = False
37+
2838

2939
class VoilaMarkdownRenderer(IPythonRenderer):
3040
"""Custom markdown renderer that inlines images"""
@@ -33,14 +43,20 @@ def __init__(self, contents_manager, *args, **kwargs):
3343
self.contents_manager = contents_manager
3444
super().__init__(*args, **kwargs)
3545

36-
def image(self, src, title, text):
46+
def image(self, text: str, url: str, title: Optional[str] = None):
3747
contents_manager = self.contents_manager
48+
# for nbconvert <7.6.0, the first argument is the URL
49+
src = url if NB_CONVERT_760 else text
50+
3851
if contents_manager.file_exists(src):
3952
content = contents_manager.get(src, format="base64")
4053
data = content["content"].replace("\n", "") # remove the newline
4154
mime_type, encoding = mimetypes.guess_type(src)
4255
src = f"data:{mime_type};base64,{data}"
43-
return super().image(src, title, text)
56+
if NB_CONVERT_760:
57+
return super().image(text, src, title)
58+
else:
59+
return super().image(src, url, title)
4460

4561

4662
class VoilaExporter(HTMLExporter):

0 commit comments

Comments
 (0)