Skip to content

Commit

Permalink
Allow get_export_names to skip configuration check
Browse files Browse the repository at this point in the history
This introduces an environment variable named
NBCONVERT_DISABLE_CONFIG_EXPORTERS that will cause get_export_names to
return all entrypoints instead of checking the "enabled" status of
each one.

Closes: #1439
  • Loading branch information
rmoe committed Nov 20, 2020
1 parent f66ec51 commit 61b0082
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nbconvert/exporters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import os
import warnings

import entrypoints
Expand Down Expand Up @@ -135,6 +136,9 @@ def get_export_names(config=get_config()):
them as an nbconvert.exporter entrypoint.
"""
exporters = sorted(entrypoints.get_group_named('nbconvert.exporters'))
if os.environ.get("NBCONVERT_DISABLE_CONFIG_EXPORTERS"):
return exporters

enabled_exporters = []
for exporter_name in exporters:
try:
Expand Down
31 changes: 30 additions & 1 deletion nbconvert/exporters/tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
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 abscence 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'])

0 comments on commit 61b0082

Please sign in to comment.