Skip to content

Commit c258d3f

Browse files
Get the list of exporters from entrypoints
`exporter_map` is deprecated, so let's use the list of exporters fetched from the installed entrypoints. There's a supposed attribute `export_from_notebook` that should be set to a friendly string name if the exporter should be exposed in the front-end. However, the exporters defined in `nbconvert` don't have it set, so I haven't used it to determine inclusion in the list. Instead, I've used the entrypoint name as the friendly name, which looks like it was the intention from the way they are named. I ran the unit tests and tried starting up the notebook server and accessing the API endpoint to verify the JSON looked correct.
1 parent 98085dc commit c258d3f

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)