Skip to content

Commit 6c0ee1b

Browse files
authored
Merge pull request #3879 from starcruiseromega/exporters
Get the list of exporters from entrypoints
2 parents 98085dc + c258d3f commit 6c0ee1b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

notebook/services/nbconvert/handlers.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@
44

55
from ...base.handlers import APIHandler
66

7+
78
class NbconvertRootHandler(APIHandler):
89

910
@web.authenticated
1011
def get(self):
1112
try:
12-
from nbconvert.exporters.export import exporter_map
13+
from nbconvert.exporters import base
1314
except ImportError as e:
1415
raise web.HTTPError(500, "Could not import nbconvert: %s" % e)
1516
res = {}
16-
for format, exporter in exporter_map.items():
17-
res[format] = info = {}
18-
info['output_mimetype'] = exporter.output_mimetype
17+
exporters = base.get_export_names()
18+
for exporter_name in exporters:
19+
try:
20+
exporter_class = base.get_exporter(exporter_name)
21+
except ValueError:
22+
# I think the only way this will happen is if the entrypoint
23+
# is uninstalled while this method is running
24+
continue
25+
# XXX: According to the docs, it looks like this should be set to None
26+
# if the exporter shouldn't be exposed to the front-end and a friendly
27+
# name if it should. However, none of the built-in exports have it defined.
28+
# if not exporter_class.export_from_notebook:
29+
# continue
30+
res[exporter_name] = {
31+
"output_mimetype": exporter_class.output_mimetype,
32+
}
1933

2034
self.finish(json.dumps(res))
2135

0 commit comments

Comments
 (0)