Repository: mwouts/jupytext (python)

Issue:
`jupytext --sync` should ignore unpaired notebooks
Using v1.1.7, when doing `jupytext --sync *.ipynb`, an exception is thrown when it encounters an unpaired notebook. (https://github.com/mwouts/jupytext/blob/1.1.7/jupytext/cli.py#L446) However, it would be better if unpaired notebooks were skipped.

Pull request:
Jupytext sync ignores unpaired notebooks
Fixes #281

Patch:
diff --git a/README.md b/README.md
index f722c6bb..a2677d90 100755
--- a/README.md
+++ b/README.md
@@ -101,7 +101,7 @@ Select the pairing for a given notebook using either the [Jupytext menu](#jupyte
 
 Alternatively, the pairing information for one or multiple notebooks can be set on the command line:
 ```
-jupytext --set-formats ipynb,py [--sync] notebook.ipynb
+jupytext --set-formats ipynb,py notebook.ipynb
 ```
 
 For more information see [the jupytext documentation](https://jupytext.readthedocs.io).
diff --git a/jupytext/cli.py b/jupytext/cli.py
index b3a5626b..72df6964 100644
--- a/jupytext/cli.py
+++ b/jupytext/cli.py
@@ -324,7 +324,11 @@ def jupytext(args=None):
             # 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


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index ce475b7b..b38d5dbd 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'