How to use the nbstripout._utils.MetadataError function in nbstripout

To help you get started, we’ve selected a few nbstripout examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kynan / nbstripout / nbstripout / _utils.py View on Github external
Based on whether the metadata has "init_cell": true,
    "keep_output": true, or the tags contain "keep_output" """
    if 'metadata' not in cell:
        return default
    if 'init_cell' in cell.metadata:
        return bool(cell.metadata.init_cell)

    has_keep_output_metadata = 'keep_output' in cell.metadata
    keep_output_metadata = bool(cell.metadata.get('keep_output', False))

    has_keep_output_tag = 'keep_output' in cell.metadata.get('tags', [])

    # keep_output between metadata and tags should not contradict each other
    if has_keep_output_metadata and has_keep_output_tag and not keep_output_metadata:
        raise MetadataError(
            "cell metadata contradicts tags: "
            "\"keep_output\": false, but keep_output in tags"
        )

    if has_keep_output_metadata or has_keep_output_tag:
        return keep_output_metadata or has_keep_output_tag
    return default

nbstripout

Strips outputs from Jupyter and IPython notebooks

MIT
Latest version published 5 days ago

Package Health Score

88 / 100
Full package analysis

Similar packages