read

Reading a notebook, and initial bootstrapping for notebook exporting

mk_cell

 mk_cell (text, code=True)

Create a NbCell containing text


create_output

 create_output (txt, mime)

Add a cell output containing txt of the mime text MIME sub-type

Config

nbprocess uses a settings.ini file in the root of the project to store all configuration details. This file is in ConfigParser format, and can be read and written conveniently using fastcore’s Config class.


nbprocess_create_config

 nbprocess_create_config (user:str, lib_name:str=None,
                          description='TODOfillmein',
                          author='TODOfillmein',
                          author_email='[email protected]', path:str='.',
                          cfg_name:str='settings.ini',
                          branch:str='master', host:str='github', git_url:
                          str='https://github.com/%(user)s/%(lib_name)s/tr
                          ee/%(branch)s/', custom_sidebar:<functionbool_ar
                          gat0x7f9a16c5bd00>=False, nbs_path:str='.',
                          lib_path:str='%(lib_name)s',
                          doc_path:str='_docs', tst_flags:str='',
                          version:str='0.0.1', keywords='python',
                          license='apache2', copyright='', status='3',
                          min_python='3.6', audience='Developers',
                          language='English')

Creates a new config file for lib_name and user and saves it.

Type Default Details
user str Repo username
lib_name str None Name of library
description str TODO fill me in Description for pypi
author str TODO fill me in Author for pypi
author_email str [email protected] Email for pypi
path str . Path to create config file
cfg_name str settings.ini Name of config file to create
branch str master Repo branch
host str github Repo hostname
git_url str https://github.com/%(user)s/%(lib_name)s/tree/%(branch)s/ Repo URL
custom_sidebar bool_arg False Create custom sidebar?
nbs_path str . Name of folder containing notebooks
lib_path str %(lib_name)s Folder name of root module
doc_path str _docs Folder name containing docs
tst_flags str Test flags
version str 0.0.1 Version number
keywords str python Keywords for pypi
license str apache2 License for pypi
copyright str Copyright for pypi, defaults to author from current year
status str 3 Status for pypi
min_python str 3.6 Minimum python version for pypi
audience str Developers Audience for pypi
language str English Language for pypi

This is a wrapper for fastcore’s save_config_file which sets some nbprocess defaults. It is also installed as a CLI command.


get_config

 get_config (cfg_name='settings.ini', path=None)

Config for ini file found in path (defaults to cwd)

get_config searches for settings.ini in the current directory, and then in all parent directories, stopping when it is found.

nbprocess_create_config('fastai', path='..', nbs_path='nbs', tst_flags='tst', cfg_name='test_settings.ini')
cfg = get_config('test_settings.ini')
test_eq(cfg.lib_name, 'nbprocess')
test_eq(cfg.git_url, "https://github.com/fastai/nbprocess/tree/master/")
cwd = Path.cwd()
test_eq(cfg.config_path, cwd.parent.absolute())
test_eq(cfg.path('lib_path'), cwd.parent/'nbprocess')
test_eq(cfg.path('nbs_path'), cwd)
test_eq(cfg.path('doc_path'), cwd.parent/'_docs')

config_key

 config_key (c, default=None, path=True, missing_ok=False)

Look for key c in settings.ini and fail gracefully if not found and no default provided

Exporting a basic module


add_init

 add_init (path)

Add __init__.py in all subdirs of path containing python files if it’s not there already

Python modules require a __init.py__ file in all directories that are modules. We assume that all directories containing a python file (including in subdirectories of any depth) is a module, and therefore add a __init__.py to each.

with tempfile.TemporaryDirectory() as d:
    d = Path(d)
    (d/'a/b').mkdir(parents=True)
    (d/'a/b/f.py').touch()
    (d/'a/c').mkdir()
    add_init(d)
    assert not (d/'a/c'/_init).exists(), "Should not add init to dir without py file"
    for e in [d, d/'a', d/'a/b']: assert (e/_init).exists(),f"Missing init in {e}"

write_cells

 write_cells (cells, hdr, file, offset=0)

Write cells to file along with header hdr starting at index offset (mainly for nbprocess internal use)


basic_export_nb

 basic_export_nb (fname, name, dest=None)

Basic exporter to bootstrap nbprocess

This is a simple exporter with just enough functionality to correctly export this notebook, in order to bootstrap the creation of nbprocess itself.