module cli.notebook

Short summary

module pyquickhelper.cli.notebook

Command line about noteboooks.

source on GitHub

Functions

function

truncated documentation

convert_notebook

Converts a notebook into a specific format.

run_notebook

Runs a notebook end to end, it is inspired from module runipy.

Documentation

Command line about noteboooks.

source on GitHub

pyquickhelper.cli.notebook.convert_notebook(filename, outfold=None, build=None, latex_path=None, pandoc_path=None, formats='html, python', exc=True, nblinks=None, remove_unicode_latex=False, fLOG=<built-in function print>)[source]

Converts a notebook into a specific format.

Parameters:
  • filename – notebook name

  • outfold – notebook is first copied into this directory to make some preprocessing. This directory must exist, directory _convertnb will be created otherwise.

  • build – can be the current one

  • latex_path – if format includes latex

  • pandoc_path – for word format

  • formats – list of formats to use (comma separated), full list is ipynb,html,python,rst,slides,pdf,github

  • exc – raises an exception of be silent

  • nblinks – to add some link

  • remove_unicode_latex – should not be necessary

Convert a notebook into a different format

The command line converts notebook into HTML, RST, PDF, slides… It calls nbconvert but adds some preprocessing before calling it.

<<<

python -m pyquickhelper convert_notebook --help

>>>

usage: convert_notebook [-h] [-f FILENAME] [-o OUTFOLD] [-b BUILD]
                        [-l LATEX_PATH] [-p PANDOC_PATH] [-fo FORMATS]
                        [--exc EXC] [-n NBLINKS] [-r REMOVE_UNICODE_LATEX]

Converts a notebook into a specific format.

optional arguments:
  -h, --help            show this help message and exit
  -f FILENAME, --filename FILENAME
                        notebook name (default: None)
  -o OUTFOLD, --outfold OUTFOLD
                        notebook is first copied into this directory to make
                        some preprocessing. This directory must exist,
                        directory ``_convertnb`` will be created otherwise.
                        (default: )
  -b BUILD, --build BUILD
                        can be the current one (default: )
  -l LATEX_PATH, --latex_path LATEX_PATH
                        if format includes latex (default: )
  -p PANDOC_PATH, --pandoc_path PANDOC_PATH
                        for word format (default: )
  -fo FORMATS, --formats FORMATS
                        list of formats to use (comma separated), full list is
                        ``ipynb,html,python,rst,slides,pdf,github`` (default:
                        html,python)
  --exc EXC             raises an exception of be silent (default: True)
  -n NBLINKS, --nblinks NBLINKS
                        to add some link (default: )
  -r REMOVE_UNICODE_LATEX, --remove_unicode_latex REMOVE_UNICODE_LATEX
                        should not be necessary (default: False)

source on GitHub

pyquickhelper.cli.notebook.run_notebook(filename, profile_dir='', working_dir='', skip_exceptions=False, outfilename='', additional_path='', kernel_name='python', log_level=30, startup_timeout=300, verbose=0, raise_exception=True, fLOG=<built-in function print>)[source]

Runs a notebook end to end, it is inspired from module runipy.

Parameters:
  • filename – notebook filename

  • profile_dir – profile directory

  • working_dir – working directory

  • skip_exceptions – skip exceptions

  • outfilename – if not None, saves the output in this notebook

  • additional_path – additional paths for import (comma separated)

  • kernel_name – kernel name, it can be None

  • log_level – Choices: (0, 10, 20, 30=default, 40, 50, ‘DEBUG’, ‘INFO’, ‘WARN’, ‘ERROR’, ‘CRITICAL’)

  • detailed_log – a second function to log more information when executing the notebook, this should be a function with the same signature as print or None

  • startup_timeout – wait for this long for the kernel to be ready, see wait_for_ready

  • verbose – 0 for standard logging, 1 for more

  • raise_exception – raise an exception if a cell raises one

  • fLOG – logging function

Returns:

tuple (statistics, output)

Run a notebook

The command line runs a notebook and stores the modified notebook.

<<<

python -m pyquickhelper run_notebook --help

>>>

usage: run_notebook [-h] [-f FILENAME] [-p PROFILE_DIR] [-w WORKING_DIR]
                    [-s SKIP_EXCEPTIONS] [-o OUTFILENAME] [-a ADDITIONAL_PATH]
                    [-k KERNEL_NAME] [-l LOG_LEVEL] [-st STARTUP_TIMEOUT]
                    [-v VERBOSE] [-r RAISE_EXCEPTION]

Runs a notebook end to end, it is inspired from module runipy.

optional arguments:
  -h, --help            show this help message and exit
  -f FILENAME, --filename FILENAME
                        notebook filename (default: None)
  -p PROFILE_DIR, --profile_dir PROFILE_DIR
                        profile directory (default: )
  -w WORKING_DIR, --working_dir WORKING_DIR
                        working directory (default: )
  -s SKIP_EXCEPTIONS, --skip_exceptions SKIP_EXCEPTIONS
                        skip exceptions (default: False)
  -o OUTFILENAME, --outfilename OUTFILENAME
                        if not None, saves the output in this notebook
                        (default: )
  -a ADDITIONAL_PATH, --additional_path ADDITIONAL_PATH
                        additional paths for import (comma separated)
                        (default: )
  -k KERNEL_NAME, --kernel_name KERNEL_NAME
                        kernel name, it can be None (default: python)
  -l LOG_LEVEL, --log_level LOG_LEVEL
                        Choices: (0, 10, 20, 30=default, 40, 50, 'DEBUG',
                        'INFO', 'WARN', 'ERROR', 'CRITICAL') (default: 30)
  -st STARTUP_TIMEOUT, --startup_timeout STARTUP_TIMEOUT
                        wait for this long for the kernel to be ready, see
                        `wait_for_ready <https://github.com/jupyter/jupyter_cl
                        ient/blob/master/jupyter_client/blocking/client.py#L84
                        >`_ (default: 300)
  -v VERBOSE, --verbose VERBOSE
                        0 for standard logging, 1 for more (default: 0)
  -r RAISE_EXCEPTION, --raise_exception RAISE_EXCEPTION
                        raise an exception if a cell raises one (default:
                        True)

source on GitHub