Repository: mwouts/jupytext
Pull request #407 (2019-12-24 07:27:44)

Do not read paired files when the pair is being created

codecov[bot]: # [Codecov](https://codecov.io/gh/mwouts/jupytext/pull/407?src=pr&el=h1) Report
> Merging [#407](https://codecov.io/gh/mwouts/jupytext/pull/407?src=pr&el=desc) into [master](https://codecov.io/gh/mwouts/jupytext/commit/209f9c6093fbb6a6fd3a27154150e57cf730c99a?src=pr&el=desc) will **decrease** coverage by `11.04%`.
> The diff coverage is `100%`.

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

```diff
@@             Coverage Diff             @@
##           master     #407       +/-   ##
===========================================
- Coverage   99.05%   88.01%   -11.05%     
===========================================
  Files          75       75               
  Lines        7545     7393      -152     
===========================================
- Hits         7474     6507      -967     
- Misses         71      886      +815
```


| [Impacted Files](https://codecov.io/gh/mwouts/jupytext/pull/407?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [jupytext/cli.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-anVweXRleHQvY2xpLnB5) | `94.98% <100%> (-1.4%)` | :arrow_down: |
| [tests/test\_cli.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9jbGkucHk=) | `77.94% <100%> (-22.06%)` | :arrow_down: |
| [tests/test\_hide\_remove\_input\_outputs\_rmarkdown.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9oaWRlX3JlbW92ZV9pbnB1dF9vdXRwdXRzX3JtYXJrZG93bi5weQ==) | `28.57% <0%> (-71.43%)` | :arrow_down: |
| [tests/test\_black.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9ibGFjay5weQ==) | `31.53% <0%> (-68.47%)` | :arrow_down: |
| [tests/test\_mirror.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9taXJyb3IucHk=) | `36.84% <0%> (-63.16%)` | :arrow_down: |
| [tests/test\_cell\_metadata.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9jZWxsX21ldGFkYXRhLnB5) | `40.5% <0%> (-59.5%)` | :arrow_down: |
| [tests/test\_read\_simple\_pandoc.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9yZWFkX3NpbXBsZV9wYW5kb2MucHk=) | `44.82% <0%> (-55.18%)` | :arrow_down: |
| [jupytext/pandoc.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-anVweXRleHQvcGFuZG9jLnB5) | `40.81% <0%> (-55.11%)` | :arrow_down: |
| [tests/test\_knitr\_spin.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9rbml0cl9zcGluLnB5) | `45.45% <0%> (-54.55%)` | :arrow_down: |
| [tests/test\_active\_cells.py](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9hY3RpdmVfY2VsbHMucHk=) | `52.54% <0%> (-47.46%)` | :arrow_down: |
| ... and [32 more](https://codecov.io/gh/mwouts/jupytext/pull/407/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/mwouts/jupytext/pull/407?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/407?src=pr&el=footer). Last update [209f9c6...36b941d](https://codecov.io/gh/mwouts/jupytext/pull/407?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

mwouts: Closes #399 

Patch:
diff --git a/jupytext/cli.py b/jupytext/cli.py
index cba93155..7ea41118 100644
--- a/jupytext/cli.py
+++ b/jupytext/cli.py
@@ -243,7 +243,7 @@ def jupytext(args=None):
             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)


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 2e5fd1cd..bb2059f1 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_script_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])