Skip to content

Commit

Permalink
Drop backwards compability with IPython.nbformat for IPython <4
Browse files Browse the repository at this point in the history
nbformat has been split out of the core IPython package as of version 4, released in August 2015.
  • Loading branch information
kynan committed Feb 4, 2024
1 parent 4ec325f commit 728b88c
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions nbstripout/_nbstripout.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,9 @@
import sys
import warnings

from nbstripout._utils import strip_output, strip_zeppelin_output
try:
# Jupyter >= 4
from nbformat import read, write, NO_CONVERT
from nbformat.reader import NotJSONError
except ImportError:
# IPython 3
try:
from IPython.nbformat import read, write, NO_CONVERT
from IPython.nbformat.reader import NotJSONError
except ImportError:
# IPython < 3
from IPython.nbformat import current
from IPython.nbformat.reader import NotJSONError

# Dummy value, ignored anyway
NO_CONVERT = None
import nbformat

def read(f, as_version):
return current.read(f, 'json')

def write(nb, f):
return current.write(nb, f, 'json')
from nbstripout._utils import strip_output, strip_zeppelin_output

__all__ = ["install", "uninstall", "status", "main"]
__version__ = '0.6.2'
Expand Down Expand Up @@ -364,7 +344,7 @@ def process_notebook(input_stream, output_stream, args, extra_keys, filename='in
return
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
nb = read(input_stream, as_version=NO_CONVERT)
nb = nbformat.read(input_stream, as_version=nbformat.NO_CONVERT)

nb = strip_output(nb, args.keep_output, args.keep_count, args.keep_id,
extra_keys, args.drop_empty_cells,
Expand All @@ -376,9 +356,9 @@ def process_notebook(input_stream, output_stream, args, extra_keys, filename='in
else:
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
write(nb, output_stream)
nbformat.write(nb, output_stream)
output_stream.flush()
except NotJSONError:
except nbformat.reader.NotJSONError:
print('No valid notebook detected', file=sys.stderr)
raise SystemExit(1)

Expand Down

0 comments on commit 728b88c

Please sign in to comment.