Skip to content

Commit 5810b81

Browse files
committed
[embedhtml] only import from lxml if we're actually about to use it
This allows nbconvert_support to import the module, even if lxml is missing or has missing dependency libs, etc. In this way, problems with lxml should only bother people who are actually tryying to use this.
1 parent 3688a3b commit 5810b81

File tree

1 file changed

+8
-1
lines changed
  • src/jupyter_contrib_nbextensions/nbconvert_support

1 file changed

+8
-1
lines changed

src/jupyter_contrib_nbextensions/nbconvert_support/embedhtml.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import base64
44
import os
55

6-
import lxml.etree as et
76
from ipython_genutils.ipstruct import Struct
87
from nbconvert.exporters.html import HTMLExporter
98

@@ -66,6 +65,14 @@ def replfunc(self, node):
6665
node.attrib["src"] = prefix + b64_data
6766

6867
def from_notebook_node(self, nb, resources=None, **kw):
68+
# The parent nbconvert_support module imports this module, and
69+
# nbconvert_support is imported as part of our install scripts, and
70+
# other fairly basic stuff.
71+
# By keeping lxml import in this method, we can still import this
72+
# module even if lxml isn't available, or is missing dependencies, etc.
73+
# In this way, problems with lxml should only bother people who are
74+
# actually trying to *use* this.
75+
import lxml.etree as et
6976
output, resources = super(
7077
EmbedHTMLExporter, self).from_notebook_node(nb, resources)
7178

0 commit comments

Comments
 (0)