-
Notifications
You must be signed in to change notification settings - Fork 567
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 get_export_names to skip configuration check #1471
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,11 @@ | |
#----------------------------------------------------------------------------- | ||
# Imports | ||
#----------------------------------------------------------------------------- | ||
|
||
import os | ||
from traitlets.config import Config | ||
|
||
from unittest.mock import patch | ||
|
||
from .base import ExportersTestsBase | ||
from ...preprocessors.base import Preprocessor | ||
from ..exporter import Exporter | ||
|
@@ -73,3 +75,30 @@ def test_get_export_names_disable(self): | |
}) | ||
export_names = get_export_names(config=config) | ||
self.assertEqual(export_names, ['notebook']) | ||
|
||
def test_get_exporter_disable_config_exporters(self): | ||
""" | ||
Does get_export_names behave correctly with respect to | ||
NBCONVERT_DISABLE_CONFIG_EXPORTERS being set in the | ||
environment? | ||
""" | ||
config = Config({ | ||
'Exporter': {'enabled': False}, | ||
'NotebookExporter': {'enabled': True} | ||
}) | ||
os.environ["NBCONVERT_DISABLE_CONFIG_EXPORTERS"] = "1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fun fact, you can use https://docs.python.org/3.7/library/unittest.mock.html#unittest.mock.patch.dict |
||
with patch("nbconvert.exporters.base.get_exporter") as exp: | ||
export_names = get_export_names(config=config) | ||
# get_export_names should not call get_exporter for | ||
# any of the entry points because we return before then. | ||
exp.assert_not_called() | ||
|
||
# We should have all exporters, not just the ones | ||
# enabled in the config | ||
self.assertNotEqual(export_names, ['notebook']) | ||
|
||
# In the absence of this variable we should revert to | ||
# the normal behavior. | ||
del os.environ["NBCONVERT_DISABLE_CONFIG_EXPORTERS"] | ||
export_names = get_export_names(config=config) | ||
self.assertEqual(export_names, ['notebook']) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: might be good to have a comment here so people know what this is for, i.e. bypass the (potentially slow) enable/disable check per extension if you know that you're supporting all exporters.
I also wonder if there is somewhere in the docs or config options that we could mention this environment variable otherwise people would only ever know about it if they were familiar with this code. Like maybe somewhere in here:
https://github.com/jupyter/nbconvert/blob/master/docs/source/api/exporters.rst
Though that's just auto-generated module doc.
Looking at https://nbconvert.readthedocs.io/en/latest/config_options.html#exporter-options maybe
Exporter.enabled
should mention this env var? Or https://nbconvert.readthedocs.io/en/latest/external_exporters.html?A CODEOWNER might have better ideas, but I'd think mentioning it with the
Exporter.enabled
config option would be the most discoverable place for mentioning this variable.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.
To @mriedem 's point, https://nbconvert.readthedocs.io/en/latest/config_options.html#exporter-options would be the best place to document the environment variable action. You can add this note by editing the
CLI Flags and Aliases
section inautogen_config.py
.Additionally we should probably log out a quick message when we're disabling config exporters so it's visible that the flag was set when helping future nbconvert issues. Use
from traitlets.log import get_logger
andget_logger().info("Config exporter loading disabled, no additional exporters will be automatically included.")