Skip to content

Commit

Permalink
Merge pull request #3879 from starcruiseromega/exporters
Browse files Browse the repository at this point in the history
Get the list of exporters from entrypoints
  • Loading branch information
minrk authored Sep 7, 2018
2 parents 98085dc + c258d3f commit 6c0ee1b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions notebook/services/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@

from ...base.handlers import APIHandler


class NbconvertRootHandler(APIHandler):

@web.authenticated
def get(self):
try:
from nbconvert.exporters.export import exporter_map
from nbconvert.exporters import base
except ImportError as e:
raise web.HTTPError(500, "Could not import nbconvert: %s" % e)
res = {}
for format, exporter in exporter_map.items():
res[format] = info = {}
info['output_mimetype'] = exporter.output_mimetype
exporters = base.get_export_names()
for exporter_name in exporters:
try:
exporter_class = base.get_exporter(exporter_name)
except ValueError:
# I think the only way this will happen is if the entrypoint
# is uninstalled while this method is running
continue
# XXX: According to the docs, it looks like this should be set to None
# if the exporter shouldn't be exposed to the front-end and a friendly
# name if it should. However, none of the built-in exports have it defined.
# if not exporter_class.export_from_notebook:
# continue
res[exporter_name] = {
"output_mimetype": exporter_class.output_mimetype,
}

self.finish(json.dumps(res))

Expand Down

0 comments on commit 6c0ee1b

Please sign in to comment.