Skip to content

Commit

Permalink
Do not read paired files when the pair is being created
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Dec 24, 2019
1 parent 209f9c6 commit 3bd2b54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit 3bd2b54

Please sign in to comment.