diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e39deaea3..eb529114f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,7 +1,7 @@ Jupytext ChangeLog ================== -1.11.2 (2021-05-??) +1.11.2 (2021-05-02) ------------------- **Changed** @@ -14,6 +14,9 @@ Jupytext ChangeLog cell metadata like `lines_to_next_cell` from the text file rather than ipynb ([#761](https://github.com/mwouts/jupytext/issues/761)) - The timestamp of the source file is not updated any more when the destination file is not in the pair ([#765](https://github.com/mwouts/jupytext/issues/765), [#767](https://github.com/mwouts/jupytext/issues/767)) +**Added** +- A new test documents when the `ipython3` pygment lexer appears in MyST Markdown files ([#759](https://github.com/mwouts/jupytext/issues/759)) + 1.11.1 (2021-03-26) ------------------- diff --git a/jupytext/version.py b/jupytext/version.py index 9c33c67d7..c08262ebd 100644 --- a/jupytext/version.py +++ b/jupytext/version.py @@ -1,3 +1,3 @@ """Jupytext's version number""" -__version__ = "1.11.1+dev" +__version__ = "1.11.2" diff --git a/tests/test_ipynb_to_myst.py b/tests/test_ipynb_to_myst.py index feae16ef3..b97cf475a 100644 --- a/tests/test_ipynb_to_myst.py +++ b/tests/test_ipynb_to_myst.py @@ -1,3 +1,4 @@ +import json import unittest.mock as mock from textwrap import dedent @@ -7,6 +8,7 @@ import jupytext from jupytext.cli import jupytext as jupytext_cli +from jupytext.compare import compare from jupytext.formats import ( JupytextFormatError, get_format_implementation, @@ -193,3 +195,58 @@ def test_meaningfull_error_open_myst_missing(tmpdir): with pytest.raises(HTTPError, match=PLEASE_INSTALL_MYST): cm.get("notebook.md") + + +@requires_myst +@pytest.mark.parametrize("language_info", ["none", "std", "no_pygments_lexer"]) +def test_myst_representation_same_cli_or_contents_manager( + tmpdir, cwd_tmpdir, notebook_with_outputs, language_info +): + """This test gives some information on #759. As of Jupytext 1.11.1, in the MyST Markdown format, + the code cells have an ipython3 lexer when the notebook "language_info" metadata has "ipython3" + as the pygments_lexer. This information comes from the kernel and ATM it is not clear how the user + can choose to include it or not in the md file.""" + + nb = notebook_with_outputs + if language_info != "none": + nb["metadata"]["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.7.3", + } + if language_info == "no_pygments_lexer": + del nb["metadata"]["language_info"]["pygments_lexer"] + + # Writing the notebook with the Python API + text_api = jupytext.writes(nb, fmt="md:myst") + + # How do code cells look like? + code_cells = set( + line for line in text_api.splitlines() if line.startswith("```{code-cell") + ) + + if language_info == "std": + assert code_cells == {"```{code-cell} ipython3"} + else: + assert code_cells == {"```{code-cell}"} + + # We get the same file with the command line jupytext + tmpdir.mkdir("cli").join("notebook.ipynb").write(json.dumps(nb)) + jupytext_cli(["--to", "md:myst", "cli/notebook.ipynb"]) + text_cli = tmpdir.join("cli").join("notebook.md").read() + + compare(text_cli, text_api) + + # Or with the contents manager + cm = jupytext.TextFileContentsManager() + cm.formats = "ipynb,md:myst" + cm.root_dir = str(tmpdir.mkdir("contents_manager")) + + cm.save(model=dict(content=nb, type="notebook"), path="notebook.ipynb") + text_cm = tmpdir.join("contents_manager").join("notebook.md").read() + + compare(text_cm, text_api)