예제 #1
0
language = None
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '**.ipynb_checkpoints']
pygments_style = 'sphinx'

# -- Options for HTML output ----------------------------------------------

html_theme = "sphinx_rtd_theme"
html_theme_options = {
    'display_version': False,
    'prev_next_buttons_location': 'bottom',
    'style_external_links': False,
    'vcs_pageview_mode': '',
    'style_nav_header_background': 'white',
    # Toc options
    'collapse_navigation': False,
    'sticky_navigation': True,
    'navigation_depth': 4,
    'includehidden': True,
    'titles_only': False,
    'conf_py_path':'/',
}

# -- Strip output ----------------------------------------------

import nbclean, glob

for filename in glob.glob('examples/*.ipynb', recursive=True):
    ntbk = nbclean.NotebookCleaner(filename)
    ntbk.clear('stderr')
    ntbk.save(filename)
예제 #2
0
    f for f in cwd.parent.glob('**/*') if f.suffix in {'.ipynb', '.rst'}
    and 'ipynb_checkpoints' not in str(f) and 'docs' not in str(f)
]
for f in paths:
    time = f.stat().st_mtime
    if time > last_build_time:
        print(f)
        if 'ipynb_checkpoints' in str(f):
            continue
        # newfile is same file but in docs directory
        newfile = Path(str(f).replace(str(cwd.parent), str(cwd)))
        os.makedirs(newfile.parent, exist_ok=True)
        if f.suffix == '.rst':  # copy file
            Path(newfile).write_text(f.read_text())
        elif f.suffix == '.ipynb':  # copy and strip file
            ntbk = nbclean.NotebookCleaner(str(f))
            ntbk.clear('stderr')
            ntbk.save(str(newfile))

# write time of this build
from datetime import datetime
(Path.cwd() / '.last_sphinx_build').write_text(str(datetime.now().timestamp()))

# -- actually move all ----------------------------------------------

project = 'sunny'
copyright = '2019, Cellarity.'
author = 'Sunny Sun'

version = ''
release = version
예제 #3
0
import nbclean as nbc

path_original_notebook = 'D:/tyang/fastai/courses/dl1/lesson1-breeds.ipynb'
path_save = 'D:/tyang/fastai/courses/dl1/lesson1-breeds.ipynb'
ntbk = nbc.NotebookCleaner(path_original_notebook)
ntbk.clear('output')
ntbk.save(path_save)
예제 #4
0
import nbclean as nbc
import pytest
import os

# We'll use the test notebook in `examples`
path = os.path.dirname(__file__)
path_notebook = path + '/../../examples/test_notebooks/test_notebook.ipynb'
HIDE_TEXT = '# HIDDEN'

# Clear different parts of the notebook cells based on tags
ntbk = nbc.NotebookCleaner(path_notebook)
ntbk.clear(kind='output', tag='hide_output')
ntbk.clear(kind='content', tag='hide_content')
ntbk.clear(kind=['stderr'], tag='hide_stderr')

with pytest.raises(ValueError):
    ntbk.clear(kind='foo')
with pytest.raises(ValueError):
    ntbk.clear(kind=[])

# Removing entire cells
ntbk.remove_cells(tag='remove')
ntbk.remove_cells(tag='remove_if_empty', empty=True)
ntbk.remove_cells(search_text=HIDE_TEXT)

# Replacing text
text_replace_begin = '### SOLUTION BEGIN'
text_replace_end = '### SOLUTION END'
ntbk.replace_text(text_replace_begin, text_replace_end)