From 49552ffed976feae15132d6445b2565a225085b9 2015-03-26 00:30:14 From: Thomas Kluyver Date: 2015-03-26 00:30:14 Subject: [PATCH] Shim IPython.nbformat so tests pass again --- diff --git a/IPython/nbformat.py b/IPython/nbformat.py new file mode 100644 index 0000000..e5d44e1 --- /dev/null +++ b/IPython/nbformat.py @@ -0,0 +1,22 @@ +""" +Shim to maintain backwards compatibility with old IPython.nbformat imports. +""" +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + +from __future__ import print_function + +# Stdlib +import sys +import types +from warnings import warn + +warn("The `IPython.nbformat` package has been deprecated. " + "You should import from jupyter_nbformat instead.") + +from IPython.utils.shimmodule import ShimModule + +# Unconditionally insert the shim into sys.modules so that further import calls +# trigger the custom attribute access above + +sys.modules['IPython.nbformat'] = ShimModule('nbformat', mirror='jupyter_nbformat') diff --git a/jupyter_nbformat/tests/base.py b/jupyter_nbformat/tests/base.py index 349006f..32a116c 100644 --- a/jupyter_nbformat/tests/base.py +++ b/jupyter_nbformat/tests/base.py @@ -30,13 +30,4 @@ class TestsBase(unittest.TestCase): def _get_files_path(self): - - #Get the relative path to this module in the IPython directory. - names = self.__module__.split(u'.')[1:-1] - - #Build a path using the IPython directory and the relative path we just - #found. - path = IPython.__path__[0] - for name in names: - path = os.path.join(path, name) - return path + return os.path.dirname(__file__) diff --git a/jupyter_nbformat/v3/convert.py b/jupyter_nbformat/v3/convert.py index c2857bb..04b44b7 100644 --- a/jupyter_nbformat/v3/convert.py +++ b/jupyter_nbformat/v3/convert.py @@ -8,7 +8,7 @@ from .nbbase import ( nbformat, nbformat_minor ) -from IPython.nbformat import v2 +from jupyter_nbformat import v2 def _unbytes(obj): """There should be no bytes objects in a notebook diff --git a/jupyter_nbformat/v4/convert.py b/jupyter_nbformat/v4/convert.py index a6c3f36..b25efd9 100644 --- a/jupyter_nbformat/v4/convert.py +++ b/jupyter_nbformat/v4/convert.py @@ -11,7 +11,7 @@ from .nbbase import ( NotebookNode, ) -from IPython.nbformat import v3 +from jupyter_nbformat import v3 from IPython.utils.log import get_logger def _warn_if_invalid(nb, version): diff --git a/setupbase.py b/setupbase.py index 382510a..481d557 100644 --- a/setupbase.py +++ b/setupbase.py @@ -196,11 +196,11 @@ def find_package_data(): 'preprocessors/tests/files/*.*', ], 'IPython.nbconvert.filters' : ['marked.js'], - 'IPython.nbformat' : [ - 'tests/*.ipynb', - 'v3/nbformat.v3.schema.json', - 'v4/nbformat.v4.schema.json', - ], + # 'IPython.nbformat' : [ + # 'tests/*.ipynb', + # 'v3/nbformat.v3.schema.json', + # 'v4/nbformat.v4.schema.json', + # ], 'IPython.kernel': ['resources/*.*'], }