A Sphinx Extension for Generating Jupyter Notebooks
This sphinx extension can be used to build a collection of Jupyter notebooks for Sphinx Projects.
Note: It has mainly been written to support the use case of scientific publishing and hasn't been well tested outside of this domain. Please provide feedback as an issue to this repository.
pip install sphinxcontrib-jupyter
Update project conf.py
file to include the jupyter extension:
extensions = ["sphinxcontrib.jupyter"]
then run
make jupyter
To generate an In
style executable block you can use
.. code-block:: python
.. literalinclude::
To generate a notebook that looks precomputed you can specify output
using the :class: output
option.
.. code-block:: python
:class: output
To include code in the notebook that is not meant for execution can be
included using :class: no-execute
. This is useful when writing code
that is meant to throw errors, for example.
.. code-block:: python
:class: no-execute
this will generate a highlighted markdown cell of the contents of the
code-block. An alias for this is :class: skip-test
. This is used
in the context of a test environment that is using the collection of
notebooks to test a collection of code snippets.
The following additions must be made to conf.py
file.
# --------------------------------------------
# sphinxcontrib-jupyter Configuration Settings
# --------------------------------------------
# Conversion Mode Settings
# If "all", convert codes and texts into jupyter notebook
# If "code", convert code-blocks only
jupyter_conversion_mode = "all"
jupyter_write_metadata = True
# Location for _static folder
jupyter_static_file_path = ["_static"]
# Configure Jupyter Kernels
jupyter_kernels = {
"python3": {
"kernelspec": {
"display_name": "Python",
"language": "python3",
"name": "python3"
},
"file_extension": ".py",
},
"julia": {
"kernelspec": {
"display_name": "Julia 0.6.0",
"language": "julia",
"name": "julia-0.6"
},
"file_extension": ".jl"
}
}
# Prepend a Welcome Message to Each Notebook
jupyter_welcome_block = "welcome.rst"
This project is supported by QuantEcon
Many thanks to the lead developers of this project.
If you find this extension useful please let us know at contact@quantecon.org
Copyright © 2017 QuantEcon Development Team: BSD-3 All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.