File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 11""" Utilities for processing Jupyter notebooks. """
22
33import json
4+ import warnings
45from pathlib import Path
6+ from typing import Any
57
68
79def process_notebook (file : Path ) -> str :
@@ -24,7 +26,23 @@ def process_notebook(file: Path) -> str:
2426 If an unexpected cell type is encountered.
2527 """
2628 with file .open (encoding = "utf-8" ) as f :
27- notebook = json .load (f )
29+ notebook : dict [str , Any ] = json .load (f )
30+
31+ # Check if the notebook contains worksheets
32+ if worksheets := notebook .get ("worksheets" ):
33+ # https://github.com/ipython/ipython/wiki/IPEP-17:-Notebook-Format-4#remove-multiple-worksheets
34+ # "The `worksheets` field is a list, but we have no UI to support multiple worksheets.
35+ # Our design has since shifted to heading-cell based structure, so we never intend to
36+ # support the multiple worksheet model. The worksheets list of lists shall be replaced
37+ # with a single list, called `cells`."
38+ warnings .warn ("Worksheets are deprecated as of IPEP-17." , DeprecationWarning )
39+
40+ if len (worksheets ) > 1 :
41+ warnings .warn (
42+ "Multiple worksheets are not supported. Only the first worksheet will be processed." , UserWarning
43+ )
44+
45+ notebook = worksheets [0 ]
2846
2947 result = []
3048
You can’t perform that action at this time.
0 commit comments