Skip to content

Commit 8f0e989

Browse files
committed
fixes ploomber#980
1 parent 57b83ec commit 8f0e989

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

src/ploomber/tasks/notebook.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ class NotebookConverter:
151151
def __init__(self,
152152
path_to_output,
153153
exporter_name=None,
154-
nbconvert_export_kwargs=None):
154+
nbconvert_export_kwargs=None,
155+
warn_on_ipynb=True):
156+
self._warn_on_ipynb = warn_on_ipynb
155157
self._suffix = Path(path_to_output).suffix
156158

157159
if exporter_name is None:
@@ -185,8 +187,8 @@ def __init__(self,
185187
self._nbconvert_export_kwargs = nbconvert_export_kwargs or {}
186188

187189
def convert(self):
188-
189-
if self._exporter is None and self._nbconvert_export_kwargs:
190+
if (self._warn_on_ipynb and self._exporter is None
191+
and self._nbconvert_export_kwargs):
190192
warnings.warn(
191193
f'Output {self._path_to_output!r} is a '
192194
'notebook file. nbconvert_export_kwargs '
@@ -738,8 +740,10 @@ def __init__(self,
738740
exporter = nbconvert_exporter_name.get(
739741
key) if nbconvert_exporter_name else None
740742
self._converter.append(
741-
NotebookConverter(product_nb, exporter,
742-
nbconvert_export_kwargs))
743+
NotebookConverter(product_nb,
744+
exporter,
745+
nbconvert_export_kwargs,
746+
warn_on_ipynb=False))
743747

744748
@property
745749
def debug_mode(self):

tests/tasks/test_notebook.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from pathlib import Path, PurePosixPath
33
from unittest.mock import ANY, Mock
4+
import warnings
45

56
import jupytext
67
import nbconvert
@@ -488,36 +489,33 @@ def test_can_execute_when_product_is_metaproduct(tmp_directory):
488489
dag.build()
489490

490491

491-
# should not have warning when have multiple exports and
492-
# nbconvert_export_kwargs set
493-
@pytest.mark.parametrize('product, nb_product_key, nbconvert_exporter_name', [
494-
({
495-
'nb': File(Path('out.pdf')),
496-
'file': File(Path('another', 'data', 'file.txt')),
497-
}, 'nb', 'webpdf')
498-
])
499-
def test_multiple_nb_no_kwargs_warning(product, nb_product_key,
500-
nbconvert_exporter_name):
492+
def test_do_not_warn_on_nbconvert_export_kwargs_if_multiple_outputs(
493+
tmp_directory):
501494
dag = DAG()
502495

503496
code = """
504497
# + tags=["parameters"]
505-
var = None
498+
upstream = None
506499
507500
# +
508-
from pathlib import Path
509-
Path(product['file']).touch()
501+
1 + 1
510502
"""
511503

512504
NotebookRunner(code,
513-
product=product,
505+
product={
506+
'nb': File('out.ipynb'),
507+
'report': File('out.html'),
508+
},
514509
dag=dag,
515510
ext_in='py',
516-
nbconvert_exporter_name=nbconvert_exporter_name,
517-
nb_product_key=nb_product_key,
511+
nb_product_key=['nb', 'report'],
518512
nbconvert_export_kwargs=dict(exclude_input=True),
519513
name='nb')
520-
dag.build()
514+
515+
with warnings.catch_warnings():
516+
# fail the test if this displays a warnings
517+
warnings.simplefilter("error")
518+
dag.build()
521519

522520

523521
@pytest.mark.parametrize('product, nb_product_key, nbconvert_exporter_name', [
@@ -555,7 +553,7 @@ def test_multiple_nb_no_kwargs_warning(product, nb_product_key,
555553
'file': File(Path('another', 'data', 'file.txt')),
556554
}, 'nb', 'webpdf')
557555
])
558-
def test_multiple_nb_product_success(product, nb_product_key,
556+
def test_multiple_nb_product_success(tmp_directory, product, nb_product_key,
559557
nbconvert_exporter_name):
560558
dag = DAG()
561559

0 commit comments

Comments
 (0)