-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow exporters to be enabled or disabled via config #1273
Conversation
Signed-off-by: Ian Allison <iana@pims.math.ca>
This pull request has been mentioned on Jupyter Community Forum. There might be relevant details there: https://discourse.jupyter.org/t/remove-download-as-options-in-jupyter-notebook/4374/5 |
nbconvert/exporters/exporter.py
Outdated
@@ -52,6 +52,8 @@ class Exporter(LoggingConfigurable): | |||
accompanying resources dict. | |||
""" | |||
|
|||
enabled = Bool(True).tag(config=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a short "doc string"/help text to this to explain how/why people would use this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, thanks, I've added a one line help, if you think it needs more explanation I can add it.
Looks nice! Do we have any data on how many exporters exist that don't inherit from I like it but not very familiar with the nbconvert code and conventions to know what else we should look at/think about before merging. ps. did you run this with lab and classic notebook to see it in action? |
Signed-off-by: Ian Allison <iana@pims.math.ca>
All of the exporters in [e for e in names if getattr(get_exporter(e)(config=c), 'enabled', True)] I'll leave this out for now, but if there are other exporters that seems to work OK. I've been testing the changes in the notebook but they seem to work in jupyterlab as well. I haven't figured out exactly how lab builds it's list of exporters but it does seem to "just work". I'll try to dig into lab and make sure this is true in general. |
The doc build failure seems to be related to nbconvert/docs/example.ipynb. Something goes wrong extracting the output as a png and then LaTeX chokes on the broken png file. |
Yes the docs build failure I need to go fix. Don't worry about it for this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's only filtering the names that are visible to entrypoints rather than the actual exporters. Does this need to affect get_exporter
as well?
This commit moves the logic for disabling exporters into the get_exporter function rather than just updating the list of available exporters. If someone explicitly asks for an exporter which is disabled in their configuration they will get a ExporterDisabledError exception. The logic in get_exporter_names can be simplified so it only has to catch (and ignore) that exception when building the list of enabled exporters. Signed-off-by: Ian Allison <iana@pims.math.ca>
I took a look at moving the logic to I think most things (notebook in particular) check to see what exporters are available with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that works. Covers both function to respect the attribute. Thanks for following through on the PR feedback!
Nice work and thank you for contributing! |
[This change in nbconvert](jupyter/nbconvert#1273) meant that importing `from nbconvert.nbconvertapp import NbConvertApp` in the global scope causes a circular import. That change seems to undo the efforts of jupyter/nbconvert#423, so there might be case to be made to clean it up on the nbconvert side, but this change should at least make this module workable with nbconvert 6 for now.
This change allows people to configure which Exporters are enabled by adding a
.enabled
attribute/traitlet to theExporter
class. It allows users to control functionality such as the "Download as" entry in the notebook and addresses issues like #1065 or this discourse post.To disable a single exporter, configuration looks like
Or, since everything inherits from
Exporter
, you could disable all but one withPeople wanting to tweak the notebook "Download as" options those could go in their
jupyter_notebook_config.py
but to get complete control over those entries you also need a change to the notebook (e.g. this hack). In principal you could do everything there, but I felt that the disable/enable functionality was more general than just the notebook so I thought I'd ask for feedback here first.