How to use the jupytext.metadata_filter.filter_metadata function in jupytext

To help you get started, we’ve selected a few jupytext 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 mwouts / jupytext / tests / test_metadata_filter.py View on Github external
def test_metadata_filter_user_plus_default():
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), '-user', '-technical'
                           ) == to_dict(['preserve'])
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), 'all,-user', '-technical'
                           ) == to_dict(['preserve', 'technical'])
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), 'user', 'preserve,-all'
                           ) == to_dict(['user', 'preserve'])
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_ignore_metadata():
    metadata = {'trusted': True, 'tags': ['remove_input']}
    metadata = filter_metadata(metadata, None, _IGNORE_CELL_METADATA)
    assert metadata_to_rmd_options('R', metadata) == 'r echo=FALSE'
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_filter_metadata():
    assert filter_metadata({'scrolled': True}, None, _IGNORE_CELL_METADATA) == {}
github mwouts / jupytext / tests / test_metadata_filter.py View on Github external
def test_metadata_filter_default():
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), None, '-technical'
                           ) == to_dict(['user', 'preserve'])
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), None, 'preserve,-all'
                           ) == to_dict(['preserve'])
github mwouts / jupytext / tests / test_metadata_filter.py View on Github external
def test_metadata_filter_user_plus_default():
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), '-user', '-technical'
                           ) == to_dict(['preserve'])
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), 'all,-user', '-technical'
                           ) == to_dict(['preserve', 'technical'])
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), 'user', 'preserve,-all'
                           ) == to_dict(['user', 'preserve'])
github mwouts / jupytext / tests / test_metadata_filter.py View on Github external
def test_negative_cell_metadata_filter():
    assert filter_metadata(to_dict(['exectime']), '-linesto', '-exectime') == to_dict([])
github mwouts / jupytext / tests / test_metadata_filter.py View on Github external
def test_metadata_filter_default():
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), None, '-technical'
                           ) == to_dict(['user', 'preserve'])
    assert filter_metadata(to_dict(['technical', 'user', 'preserve']), None, 'preserve,-all'
                           ) == to_dict(['preserve'])
github mwouts / jupytext / jupytext / compare.py View on Github external
def filtered_notebook_metadata(notebook):
    """Notebook metadata, filtered for metadata added by Jupytext itself"""
    metadata = copy(notebook.metadata)
    metadata = filter_metadata(metadata,
                               notebook.metadata.get('jupytext', {}).get('notebook_metadata_filter'),
                               _DEFAULT_NOTEBOOK_METADATA)
    if 'jupytext' in metadata:
        del metadata['jupytext']
    return metadata
github mwouts / jupytext / jupytext / compare.py View on Github external
def filtered_cell(cell, preserve_outputs, cell_metadata_filter):
    """Cell type, metadata and source from given cell"""
    metadata = copy(cell.metadata)
    filter_metadata(metadata, cell_metadata_filter, _IGNORE_CELL_METADATA)

    filtered = {'cell_type': cell.cell_type,
                'source': cell.source,
                'metadata': metadata}

    if preserve_outputs:
        for key in ['execution_count', 'outputs']:
            if key in cell:
                filtered[key] = cell[key]

    return filtered
github mwouts / jupytext / jupytext / jupytext.py View on Github external
def writes(self, nb, metadata=None, **kwargs):
        """Return the text representation of the notebook"""
        if self.fmt.get('format_name') == 'pandoc':
            metadata = insert_jupytext_info_and_filter_metadata(metadata, self.ext, self.implementation)

            cells = []
            for cell in nb.cells:
                cell_metadata = filter_metadata(copy(cell.metadata),
                                                self.fmt.get('cell_metadata_filter'),
                                                _IGNORE_CELL_METADATA)
                if cell.cell_type == 'code':
                    cells.append(new_code_cell(source=cell.source, metadata=cell_metadata))
                else:
                    cells.append(NotebookNode(source=cell.source, metadata=cell_metadata, cell_type=cell.cell_type))

            return notebook_to_md(NotebookNode(
                nbformat=nb.nbformat,
                nbformat_minor=nb.nbformat_minor,
                metadata=metadata,
                cells=cells))

        # Copy the notebook, in order to be sure we do not modify the original notebook
        nb = NotebookNode(
            nbformat=nb.nbformat,