Repository: mwouts/jupytext
Pull request #451 (2020-03-07 22:32:50)

Fix set format in folder
Cf. #450 

codecov[bot]: # [Codecov](https://codecov.io/gh/mwouts/jupytext/pull/451?src=pr&el=h1) Report
> Merging [#451](https://codecov.io/gh/mwouts/jupytext/pull/451?src=pr&el=desc) into [master](https://codecov.io/gh/mwouts/jupytext/commit/709c2a757a4cafc2b49f0bec7cd28ecff0c6dd05?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/mwouts/jupytext/pull/451/graphs/tree.svg?width=650&token=a1pNjsiILi&height=150&src=pr)](https://codecov.io/gh/mwouts/jupytext/pull/451?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #451      +/-   ##
==========================================
+ Coverage   98.91%   98.91%   +<.01%     
==========================================
  Files          77       77              
  Lines        7565     7573       +8     
==========================================
+ Hits         7483     7491       +8     
  Misses         82       82
```


| [Impacted Files](https://codecov.io/gh/mwouts/jupytext/pull/451?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [jupytext/cli.py](https://codecov.io/gh/mwouts/jupytext/pull/451/diff?src=pr&el=tree#diff-anVweXRleHQvY2xpLnB5) | `95.65% <100%> (+0.01%)` | :arrow_up: |
| [tests/test\_cli.py](https://codecov.io/gh/mwouts/jupytext/pull/451/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9jbGkucHk=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/mwouts/jupytext/pull/451?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/mwouts/jupytext/pull/451?src=pr&el=footer). Last update [709c2a7...4dd6e89](https://codecov.io/gh/mwouts/jupytext/pull/451?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 35d25cb0..d04825c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
 
 **Fixed**
 - Removed leading slash in notebook paths (#444)
+- Fixed `jupytext --set-formats` when using formats with prefix and/or suffix (#450)
 
 
 1.3.4 (2020-02-18)
diff --git a/jupytext/cli.py b/jupytext/cli.py
index 01001aae..e1bbac6f 100644
--- a/jupytext/cli.py
+++ b/jupytext/cli.py
@@ -382,13 +382,14 @@ def jupytext_single_file(nb_file, args, log):
             notebook.metadata['jupytext'].pop('main_language')
 
     # Read paired notebooks, except if the pair is being created
-    if args.sync and args.set_formats is None:
+    if args.sync:
         set_prefix_and_suffix(fmt, notebook, nb_file)
-        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')
-            return 0
+        if args.set_formats is None:
+            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')
+                return 0
 
     # II. ### Apply commands onto the notebook ###
     # Pipe the notebook into the desired commands


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 39b06a61..9779eefd 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1114,3 +1114,20 @@ def test_399_to_script_then_set_formats(tmpdir):
     assert os.path.isfile(tmp_py)
 
     jupytext(['--set-formats', 'ipynb,py:percent', tmp_ipynb])
+
+
+def test_set_format_with_subfolder(tmpdir):
+    """Here we reproduce issue #450"""
+    py = """# %% [markdown]
+# A short notebook
+"""
+
+    tmpdir.mkdir('python_scripts')
+
+    with open(str(tmpdir.join('python_scripts').join('01_tabular_data_exploration.py')), 'w') as fp:
+        fp.write(py)
+
+    os.chdir(str(tmpdir))
+    jupytext(['--set-formats',
+              'python_scripts//py:percent,notebooks//ipynb',
+              'python_scripts/01_tabular_data_exploration.py'])