[go: up one dir, main page]

File: nb_to_doc.py

package info (click to toggle)
seaborn 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,124 kB
  • sloc: python: 18,293; makefile: 171; sh: 2
file content (33 lines) | stat: -rwxr-xr-x 929 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env python
"""
Convert empty IPython notebook to a sphinx doc page.

"""
import sys
from subprocess import check_call as sh


def convert_nb(nbname):

    # Execute the notebook
    sh(["jupyter", "nbconvert", "--to", "notebook",
        "--execute", "--inplace", nbname])

    # Convert to .rst for Sphinx
    sh(["jupyter", "nbconvert", "--to", "rst", nbname,
        "--TagRemovePreprocessor.remove_cell_tags={'hide'}",
        "--TagRemovePreprocessor.remove_input_tags={'hide-input'}",
        "--TagRemovePreprocessor.remove_all_outputs_tags={'hide-output'}"])

    # Clear notebook output
    sh(["jupyter", "nbconvert", "--to", "notebook", "--inplace",
        "--ClearOutputPreprocessor.enabled=True", nbname])

    # Touch the .rst file so it has a later modify time than the source
    sh(["touch", nbname + ".rst"])


if __name__ == "__main__":

    for nbname in sys.argv[1:]:
        convert_nb(nbname)