Skip to content

Commit

Permalink
Update format with format options in the notebook metadata (md:myst a…
Browse files Browse the repository at this point in the history
…nd md:pandoc)
  • Loading branch information
mwouts committed Mar 25, 2021
1 parent 0a8b180 commit 3d75792
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Jupytext ChangeLog
==================

1.11.1 (2021-03-26)
-------------------

**Fixed**
- Format options stored in the notebook itself are now taken into account (Fixes [#757](https://github.com/mwouts/jupytext/issues/757))


1.11.0 (2021-03-18)
-------------------

Expand Down
2 changes: 2 additions & 0 deletions jupytext/jupytext.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def reads(self, s, **_):
def writes(self, nb, metadata=None, **kwargs):
"""Return the text representation of the notebook"""
if self.fmt.get("format_name") == "pandoc":
self.update_fmt_with_notebook_options(nb.metadata)
metadata = insert_jupytext_info_and_filter_metadata(
metadata, self.fmt, self.implementation
)
Expand Down Expand Up @@ -215,6 +216,7 @@ def writes(self, nb, metadata=None, **kwargs):
pygments_lexer = metadata.get("language_info", {}).get(
"pygments_lexer", None
)
self.update_fmt_with_notebook_options(nb.metadata)
metadata = insert_jupytext_info_and_filter_metadata(
metadata, self.fmt, self.implementation
)
Expand Down
2 changes: 1 addition & 1 deletion jupytext/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Jupytext's version number"""

__version__ = "1.11.0"
__version__ = "1.11.1"
49 changes: 49 additions & 0 deletions tests/test_metadata_filter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from copy import deepcopy

import pytest
from nbformat.v4.nbbase import new_code_cell, new_notebook

from jupytext import reads, writes
from jupytext.cli import jupytext as jupytext_cli
from jupytext.compare import compare, compare_notebooks
from jupytext.metadata_filter import filter_metadata, metadata_filter_as_dict

from .utils import requires_myst


def to_dict(keys):
return {key: None for key in keys}
Expand Down Expand Up @@ -168,3 +173,47 @@ def test_default_config_has_priority_over_current_metadata(
1 + 1
"""
)


@requires_myst
def test_metadata_filter_in_notebook_757():
md = """---
jupytext:
cell_metadata_filter: all,-hidden,-heading_collapsed
notebook_metadata_filter: all,-language_info,-toc,-jupytext.text_representation.jupytext_version,-jupytext.text_representation.format_version
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: Python 3
language: python
name: python3
nbhosting:
title: 'Exercice: Taylor'
---
```python
1 + 1
```
""" # noqa
nb = reads(md, fmt="md:myst")
assert nb.metadata["jupytext"]["notebook_metadata_filter"] == ",".join(
[
"all",
"-language_info",
"-toc",
"-jupytext.text_representation.jupytext_version",
"-jupytext.text_representation.format_version",
]
)
md2 = writes(nb, fmt="md:myst")
compare(md2, md)

for fmt in ["py:light", "py:percent", "md"]:
text = writes(nb, fmt=fmt)
nb2 = reads(text, fmt=fmt)
compare_notebooks(nb2, nb, fmt=fmt)
ref_metadata = deepcopy(nb.metadata)
del ref_metadata["jupytext"]["text_representation"]
del nb2.metadata["jupytext"]["text_representation"]
compare(nb2.metadata, ref_metadata)

0 comments on commit 3d75792

Please sign in to comment.