如何通过 Nbsphinx 使用 Travis CI 和 Jupyter Notebooks

How to Travis CI and Jupyter Notebooks through Nbsphinx

我正在尝试在 github 存储库中使用 nbsphinx 和 travis 以及 Jupyter 笔记本。

存储库设置:

.
├── _docs
|   ├── config.py # I added nbsphinx extension here
|   ├── including.rst # File with .. include :: ../projects/testingjupyter.ipynb
|   └── index.rst # basically just toctree with "including" among other titles
├── _projects
|   └── testingjupyter.ipynb
├── tests
├── travis.yml
└── requirements.txt

travis.yml:

language: python
python:
     - "2.7.12"
     - "3.5"
     - "3.5"
     - "nightly"

install: 
    - pip install -r requirements.txt
    - sudo apt-get install pandoc

script:
    - py.test tests/
    - travis-sphinx --source ./docs build

after_success:
    - travis-sphinx --branches=master,Develop deploy

requirements.txt:

sphinx-rtd-theme==0.2.4
Sphinx==1.5.3
travis-sphinx==1.4.3
flask==0.12
jupyter
nbconvert
pandoc
nbsphinx
IPython
ipykernel

当 travis-sphinx 尝试构建时,出现以下错误:意外缩进

testingjupyter.ipynb :

{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Testing Jupyter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "print('Hello World')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

不适用于

.. include:: ../projects/testingjupyter.ipynb

据我所知,这仅适用于 *.rst 个文件(参见 docutils docs)。

您应该将笔记本添加到 toctree,例如

.. toctree::
    :maxdepth: 3

    testingjupyter

指定 .ipynb 扩展名是可选的。

或者,您可以将其包含在另一个带有 nbsphinx-toctree 元数据的笔记本中。

更新:

笔记本确实必须在源目录中。尽管在 https://github.com/spatialaudio/nbsphinx/pull/33.

中提出,但不支持使用源目录之外的笔记本