Skip to content
Permalink
Browse files

Fix #1938 -- Jupyter compatibility

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Nov 21, 2015
1 parent d49f024 commit 70109b62961d0a3d14ba00e5220eadc72bffa2f2
Showing with 29 additions and 16 deletions.
  1. +1 −0 CHANGES.txt
  2. +27 −15 nikola/plugins/compile/ipynb.py
  3. +1 −1 requirements-extras.txt
@@ -4,6 +4,7 @@ New in master
Features
--------

* Use Jupyter instead of IPython shims (Issue #1938)
* Automatically open gallery images colorbox based on URL fragment (Issue #2146)

Bugfixes
@@ -32,21 +32,33 @@
import sys

try:
import IPython
from IPython.nbconvert.exporters import HTMLExporter
if IPython.version_info[0] >= 3: # API changed with 3.0.0
from IPython import nbformat
current_nbformat = nbformat.current_nbformat
from IPython.kernel import kernelspec
else:
import IPython.nbformat.current as nbformat
current_nbformat = 'json'
kernelspec = None

from IPython.config import Config
from nbconvert.exporters import HTMLExporter
import nbformat
current_nbformat = nbformat.current_nbformat
from jupyter_client import kernelspec
from traitlets.config import Config
flag = True
ipy_modern = True
except ImportError:
flag = None
try:
import IPython
from IPython.nbconvert.exporters import HTMLExporter
if IPython.version_info[0] >= 3: # API changed with 3.0.0
from IPython import nbformat
current_nbformat = nbformat.current_nbformat
from IPython.kernel import kernelspec
ipy_modern = True
else:
import IPython.nbformat.current as nbformat
current_nbformat = 'json'
kernelspec = None
ipy_modern = False

from IPython.config import Config
flag = True
except ImportError:
flag = None
ipy_modern = None

from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER
@@ -118,7 +130,7 @@ def create_post(self, path, **kw):
# imported .ipynb file, guaranteed to start with "{" because it’s JSON.
nb = nbformat.reads(content, current_nbformat)
else:
if IPython.version_info[0] >= 3:
if ipy_modern:
nb = nbformat.v4.new_notebook()
nb["cells"] = [nbformat.v4.new_markdown_cell(content)]
else:
@@ -151,7 +163,7 @@ def create_post(self, path, **kw):
nb["metadata"]["nikola"] = metadata

with io.open(path, "w+", encoding="utf8") as fd:
if IPython.version_info[0] >= 3:
if ipy_modern:
nbformat.write(nb, fd, 4)
else:
nbformat.write(nb, fd, 'ipynb')
@@ -7,7 +7,7 @@ pygal>=2.0.0
typogrify>=2.0.4
phpserialize>=1.3
webassets>=0.10.1
ipython[notebook]>=2.0.0
jupyter>=1.0.0
ghp-import2>=1.0.0
ws4py==0.3.4
watchdog==0.8.3

0 comments on commit 70109b6

Please sign in to comment.
You can’t perform that action at this time.