diff --git a/jupytext/cli.py b/jupytext/cli.py index b3a5626b7..72df6964c 100644 --- a/jupytext/cli.py +++ b/jupytext/cli.py @@ -324,7 +324,11 @@ def writef_git_add(notebook_, nb_file_, fmt_): # Read paired notebooks if args.sync: set_prefix_and_suffix(fmt, notebook, nb_file) - notebook, inputs_nb_file, outputs_nb_file = load_paired_notebook(notebook, fmt, nb_file, log) + try: + notebook, inputs_nb_file, outputs_nb_file = load_paired_notebook(notebook, fmt, nb_file, log) + except NotAPairedNotebook as err: + sys.stderr.write('[jupytext] Warning: ' + str(err) + '\n') + continue # II. ### Apply commands onto the notebook ### # Pipe the notebook into the desired commands @@ -473,12 +477,17 @@ def set_prefix_and_suffix(fmt, notebook, nb_file): continue +class NotAPairedNotebook(ValueError): + """An error raised when a notebook is not a paired notebook""" + pass + + def load_paired_notebook(notebook, fmt, nb_file, log): """Update the notebook with the inputs and outputs of the most recent paired files""" formats = notebook.metadata.get('jupytext', {}).get('formats') if not formats: - raise ValueError("'{}' is not a paired notebook".format(nb_file)) + raise NotAPairedNotebook("'{}' is not a paired notebook".format(nb_file)) max_mtime_inputs = None max_mtime_outputs = None diff --git a/tests/test_cli.py b/tests/test_cli.py index ce475b7b5..b38d5dbd5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -590,16 +590,17 @@ def test_paired_paths(nb_file, tmpdir, capsys): @pytest.mark.parametrize('nb_file', list_notebooks('ipynb_py')) -def test_sync(nb_file, tmpdir): +def test_sync(nb_file, tmpdir, capsys): tmp_ipynb = str(tmpdir.join('notebook.ipynb')) tmp_py = str(tmpdir.join('notebook.py')) tmp_rmd = str(tmpdir.join('notebook.Rmd')) nb = read(nb_file) write(nb, tmp_ipynb) - # Test that sync fails when notebook is not paired - with pytest.raises(ValueError, match='is not a paired notebook'): - jupytext(['--sync', tmp_ipynb]) + # Test that sync issues a warning when the notebook is not paired + jupytext(['--sync', tmp_ipynb]) + _, err = capsys.readouterr() + assert 'is not a paired notebook' in err # Now with a pairing information nb.metadata.setdefault('jupytext', {})['formats'] = 'py,Rmd,ipynb' @@ -641,15 +642,16 @@ def test_sync(nb_file, tmpdir): @requires_pandoc @pytest.mark.parametrize('nb_file', list_notebooks('ipynb_py', skip='(Notebook with|flavors)')) -def test_sync_pandoc(nb_file, tmpdir): +def test_sync_pandoc(nb_file, tmpdir, capsys): tmp_ipynb = str(tmpdir.join('notebook.ipynb')) tmp_md = str(tmpdir.join('notebook.md')) nb = read(nb_file) write(nb, tmp_ipynb) - # Test that sync fails when notebook is not paired - with pytest.raises(ValueError, match='is not a paired notebook'): - jupytext(['--sync', tmp_ipynb]) + # Test that sync issues a warning when the notebook is not paired + jupytext(['--sync', tmp_ipynb]) + _, err = capsys.readouterr() + assert 'is not a paired notebook' in err # Now with a pairing information nb.metadata.setdefault('jupytext', {})['formats'] = 'ipynb,md:pandoc'