From 3bd2b544decaaa2f4a3d1d8961217b5f100588c3 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Tue, 24 Dec 2019 08:25:48 +0100 Subject: [PATCH] Do not read paired files when the pair is being created --- jupytext/cli.py | 6 +++--- tests/test_cli.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/jupytext/cli.py b/jupytext/cli.py index cba931550..7ea411181 100644 --- a/jupytext/cli.py +++ b/jupytext/cli.py @@ -243,7 +243,7 @@ def log(text): and not args.pipe and not args.check \ and not args.update_metadata and not args.set_kernel \ and not args.execute: - raise ValueError('Please provide one of --to, --output, --sync, --pipe, ' + raise ValueError('Please provide one of --to, --output, --set-formats, --sync, --pipe, ' '--check, --update_metadata, --set-kernel or --execute') if args.output and len(args.notebooks) != 1: @@ -360,8 +360,8 @@ def jupytext_single_file(nb_file, args, log): if 'kernelspec' in args.update_metadata and 'main_language' in notebook.metadata.get('jupytext', {}): notebook.metadata['jupytext'].pop('main_language') - # Read paired notebooks - if args.sync: + # Read paired notebooks, except if the pair is being created + if args.sync and args.set_formats is None: set_prefix_and_suffix(fmt, notebook, nb_file) try: notebook, inputs_nb_file, outputs_nb_file = load_paired_notebook(notebook, fmt, nb_file, log) diff --git a/tests/test_cli.py b/tests/test_cli.py index 2e5fd1cdc..ffed2dd13 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1068,3 +1068,15 @@ def test_339_require_to(tmpdir): with pytest.raises(ValueError, match='--to'): jupytext([tmp_py, '--test-strict']) + + +def test_399_to_notebook_then_set_formats(tmpdir): + nb = new_notebook(cells=[new_code_cell('1 + 1')]) + tmp_py = str(tmpdir.join('notebook_first.py')) + tmp_ipynb = str(tmpdir.join('notebook_first.ipynb')) + nbformat.write(nb, tmp_ipynb) + + jupytext(['--to', 'py:percent', tmp_ipynb]) + assert os.path.isfile(tmp_py) + + jupytext(['--set-formats', 'ipynb,py:percent', tmp_ipynb])