Skip to content

freeze_metadata and ipynb files #124

Closed
@kiendang

Description

My understanding is that

c.ContentsManager.freeze_metadata = True

is equivalent to

c.ContentsManager.default_notebook_metadata_filter = "-all"
c.ContentsManager.default_cell_metadata_filter = "-all"

However, when using the later, when create a new ipynb file, metadata_filter is set

{
  "jupytext": {
    "metadata_filter": {
      "notebook": {
        "excluded": "all"
      },
      "cells": {
        "excluded": "all"
      }
    }
  },
  "kernelspec": {
    "name": "python3",
    "display_name": "Python 3",
    "language": "python"
  },
  "language_info": {
    "name": "python",
    "version": "3.6.5",
    "mimetype": "text/x-python",
    "codemirror_mode": {
      "name": "ipython",
      "version": 3
    },
    "pygments_lexer": "ipython3",
    "nbconvert_exporter": "python",
    "file_extension": ".py"
  }
}

while if using the former, metadata_filter is not set

{
  "jupytext": {},
  "kernelspec": {
    "name": "python3",
    "display_name": "Python 3",
    "language": "python"
  },
  "language_info": {
    "name": "python",
    "version": "3.6.5",
    "mimetype": "text/x-python",
    "codemirror_mode": {
      "name": "ipython",
      "version": 3
    },
    "pygments_lexer": "ipython3",
    "nbconvert_exporter": "python",
    "file_extension": ".py"
  }
}

This leads to some confusing behavior when setting c.ContentsManager.freeze_metadata = True and creating a paired notebook from a ipynb file.
i.e If I set c.ContentsManager.freeze_metadata = True then create a .ipynb file, e.g with 1 cell import functools, then create a paired notebook by adding "formats": "ipynb,py" I would expect the corresponding .py file would be just

import functools

instead I get

# ---
# jupyter:
#   jupytext:
#     formats: ipynb,py:light
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.3'
#       jupytext_version: 0.8.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
#   language_info:
#     codemirror_mode:
#       name: ipython
#       version: 3
#     file_extension: .py
#     mimetype: text/x-python
#     name: python
#     nbconvert_exporter: python
#     pygments_lexer: ipython3
#     version: 3.6.5
# ---

import functools

This does not happen if I use

c.ContentsManager.default_notebook_metadata_filter = "-all"
c.ContentsManager.default_cell_metadata_filter = "-all"

or create the py file first.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions