Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2178 from getnikola/jupyter
Fix #1938 -- Jupyter compatibility
  • Loading branch information
Kwpolska committed Nov 21, 2015
2 parents cf14ca9 + 87cff84 commit 00ebeab
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -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
Expand Down
42 changes: 27 additions & 15 deletions nikola/plugins/compile/ipynb.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')
3 changes: 2 additions & 1 deletion requirements-extras.txt
Expand Up @@ -7,7 +7,8 @@ pygal>=2.0.0
typogrify>=2.0.4
phpserialize>=1.3
webassets>=0.10.1
ipython[notebook]>=2.0.0
notebook>=4.0.0
ipykernel>=4.0.0
ghp-import2>=1.0.0
ws4py==0.3.4
watchdog==0.8.3

0 comments on commit 00ebeab

Please sign in to comment.