From 0827828ee94fd975c5405c25973805c9bc20501f Mon Sep 17 00:00:00 2001 From: ZHUO Qiang Date: Fri, 20 Dec 2019 13:44:24 +0800 Subject: [PATCH 1/4] fix multiline comments instruction for percent --- docs/formats.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/formats.md b/docs/formats.md index 98ebbee1c..9f8bb86ff 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -195,14 +195,14 @@ that uses multiline comments """ ``` -By default Jupytext will use line comments when it converts your Jupyter notebooks for `percent` scripts. If you prefer to use multiline comments for all text cells, add a `{"jupytext": '{"cell_markers": "\\"\\"\\""}'}` metadata to your notebook, either with the notebook metadata editor in Jupyter, or at the command line: +By default Jupytext will use line comments when it converts your Jupyter notebooks for `percent` scripts. If you prefer to use multiline comments for all text cells, add a `{"jupytext": '{"cell_markers": "\"\"\",\"\"\""}'}` metadata to your notebook, either with the notebook metadata editor in Jupyter, or at the command line: ```bash -jupytext --update-metadata '{"jupytext": {"cell_markers": "\\"\\"\\""}}' notebook.ipynb --to py:percent +jupytext --update-metadata '{"jupytext": {"cell_markers": "\"\"\",\"\"\""}}' notebook.ipynb --to py:percent ``` If you want to use multiline comments for all your paired notebooks, you could also add ```python -c.ContentsManager.default_cell_markers = '"""' +c.ContentsManager.default_cell_markers = '""","""' ``` to your `.jupyter/jupyter_notebook_config.py` file. From 641791b3ae314a8eb3edc79f495866590102a142 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Mon, 23 Dec 2019 08:01:45 +0100 Subject: [PATCH 2/4] Three quotes (x1) are sufficient to trigger multiline comments --- docs/formats.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/formats.md b/docs/formats.md index 9f8bb86ff..c077a9e14 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -195,14 +195,14 @@ that uses multiline comments """ ``` -By default Jupytext will use line comments when it converts your Jupyter notebooks for `percent` scripts. If you prefer to use multiline comments for all text cells, add a `{"jupytext": '{"cell_markers": "\"\"\",\"\"\""}'}` metadata to your notebook, either with the notebook metadata editor in Jupyter, or at the command line: +By default Jupytext will use line comments when it converts your Jupyter notebooks for `percent` scripts. If you prefer to use multiline comments for all text cells, add a `{"jupytext": {"cell_markers": "\"\"\""}}` metadata to your notebook, either with the notebook metadata editor in Jupyter, or at the command line: ```bash -jupytext --update-metadata '{"jupytext": {"cell_markers": "\"\"\",\"\"\""}}' notebook.ipynb --to py:percent +jupytext --update-metadata '{"jupytext": {"cell_markers": "\"\"\""}}' notebook.ipynb --to py:percent ``` If you want to use multiline comments for all your paired notebooks, you could also add ```python -c.ContentsManager.default_cell_markers = '""","""' +c.ContentsManager.default_cell_markers = '"""' ``` to your `.jupyter/jupyter_notebook_config.py` file. From 6a4210c1a214504432b0c6ee737e8b56837f9663 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Mon, 23 Dec 2019 19:52:31 +0100 Subject: [PATCH 3/4] Test that jupytext can read a py:percent script with triple quotes x1 --- jupytext/cell_reader.py | 2 +- tests/test_read_simple_percent.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/jupytext/cell_reader.py b/jupytext/cell_reader.py index ed6e595fb..472706f64 100644 --- a/jupytext/cell_reader.py +++ b/jupytext/cell_reader.py @@ -509,7 +509,7 @@ def __init__(self, fmt=None, default_language=None): self.comment = script['comment'] self.ignore_end_marker = True self.explicit_end_marker_required = False - if fmt and 'cell_markers' in fmt and fmt['cell_markers'] != '+,-': + if fmt and fmt.get('format_name', 'light') == 'light' and 'cell_markers' in fmt and fmt['cell_markers'] != '+,-': self.cell_marker_start, self.cell_marker_end = fmt['cell_markers'].split(',', 1) self.start_code_re = re.compile('^' + self.comment + r'\s*' + self.cell_marker_start + r'(.*)$') self.end_code_re = re.compile('^' + self.comment + r'\s*' + self.cell_marker_end + r'\s*$') diff --git a/tests/test_read_simple_percent.py b/tests/test_read_simple_percent.py index 642d3a849..f007c4e85 100644 --- a/tests/test_read_simple_percent.py +++ b/tests/test_read_simple_percent.py @@ -389,3 +389,20 @@ def test_default_cell_markers_in_contents_manager_does_not_impact_light_format(t nb2 = jupytext.read(tmp_py) compare_notebooks(nb, nb2) + + +def test_single_triple_quote_works(no_jupytext_version_number, text= +'''# --- +# jupyter: +# jupytext: +# cell_markers: '"""' +# formats: ipynb,py:percent +# text_representation: +# extension: .py +# format_name: percent +# --- + +# %% +print("hello") +''', notebook=new_notebook(cells=[new_code_cell('print("hello")')])): + compare_notebooks(jupytext.reads(text, 'py'), notebook) From 4535f787a355addf17806cccdc2bba93a1eae39e Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Mon, 23 Dec 2019 20:56:54 +0100 Subject: [PATCH 4/4] fix flake8 --- tests/test_read_simple_percent.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_read_simple_percent.py b/tests/test_read_simple_percent.py index f007c4e85..42af38894 100644 --- a/tests/test_read_simple_percent.py +++ b/tests/test_read_simple_percent.py @@ -391,8 +391,7 @@ def test_default_cell_markers_in_contents_manager_does_not_impact_light_format(t compare_notebooks(nb, nb2) -def test_single_triple_quote_works(no_jupytext_version_number, text= -'''# --- +def test_single_triple_quote_works(no_jupytext_version_number, text='''# --- # jupyter: # jupytext: # cell_markers: '"""'