Repository: mwouts/jupytext
Pull request #410 (2020-01-08 03:45:57)

Ignore non notebook files in the pre-commit mode
This solves an issue reported by @lwasser at #338.

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

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

```diff
@@            Coverage Diff             @@
##           master     #410      +/-   ##
==========================================
- Coverage   99.06%   98.82%   -0.24%     
==========================================
  Files          75       75              
  Lines        7574     7423     -151     
==========================================
- Hits         7503     7336     -167     
- Misses         71       87      +16
```


| [Impacted Files](https://codecov.io/gh/mwouts/jupytext/pull/410?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tests/test\_cli.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9jbGkucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [jupytext/paired\_paths.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-anVweXRleHQvcGFpcmVkX3BhdGhzLnB5) | `97.5% <100%> (+0.13%)` | :arrow_up: |
| [jupytext/version.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-anVweXRleHQvdmVyc2lvbi5weQ==) | `100% <100%> (ø)` | :arrow_up: |
| [jupytext/kernels.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-anVweXRleHQva2VybmVscy5weQ==) | `76.66% <0%> (-13.34%)` | :arrow_down: |
| [jupytext/pep8.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-anVweXRleHQvcGVwOC5weQ==) | `95.23% <0%> (-4.77%)` | :arrow_down: |
| [jupytext/pandoc.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-anVweXRleHQvcGFuZG9jLnB5) | `91.83% <0%> (-4.09%)` | :arrow_down: |
| [jupytext/jupytext.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-anVweXRleHQvanVweXRleHQucHk=) | `98.59% <0%> (-1.41%)` | :arrow_down: |
| [jupytext/cli.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-anVweXRleHQvY2xpLnB5) | `95.54% <0%> (-0.84%)` | :arrow_down: |
| [jupytext/cell\_reader.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-anVweXRleHQvY2VsbF9yZWFkZXIucHk=) | `96.76% <0%> (-0.18%)` | :arrow_down: |
| [tests/test\_pep8.py](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9wZXA4LnB5) | `98.36% <0%> (-0.03%)` | :arrow_down: |
| ... and [26 more](https://codecov.io/gh/mwouts/jupytext/pull/410/diff?src=pr&el=tree-more) | |

------

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


Patch:
diff --git a/.travis.yml b/.travis.yml
index 3315e4a5..b0168a65 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,6 @@
 language: python
 python:
   - "3.6"
-  - "pypy"
   - "2.7"
   - "3.4"
   - "3.5"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f263c1d4..d0fec20a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+1.3.2 (2020-01-08)
+------------------
+
+**Fixed**
+- The `--pre-commit` mode now ignores non-notebook files in the index (#338).
+- `nbformat_minor` is taken from the notebook with outputs When inputs and outputs are merged.
+
 1.3.1 (2019-12-26)
 ------------------
 
diff --git a/LICENSE b/LICENSE
index d5d7ee38..d5ae6445 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2018, 2019 Marc Wouts
+Copyright (c) 2018-2020 Marc Wouts
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/jupytext/combine.py b/jupytext/combine.py
index ff8fde52..da0ecc8d 100644
--- a/jupytext/combine.py
+++ b/jupytext/combine.py
@@ -32,6 +32,12 @@ def combine_inputs_with_outputs(nb_source, nb_outputs, fmt=None):
     output_code_cells = [cell for cell in nb_outputs.cells if cell.cell_type == 'code']
     output_other_cells = [cell for cell in nb_outputs.cells if cell.cell_type != 'code']
 
+    # nbformat version number taken from the notebook with outputs
+    assert nb_outputs.nbformat == nb_source.nbformat, \
+        "The notebook with outputs is in format {}.{}, please upgrade it to {}.x".format(
+            nb_outputs.nbformat, nb_outputs.nbformat_minor, nb_source.nbformat)
+    nb_source.nbformat_minor = nb_outputs.nbformat_minor
+
     fmt = long_form_one_format(fmt)
     text_repr = nb_source.metadata.get('jupytext', {}).get('text_representation', {})
     ext = fmt.get('extension') or text_repr.get('extension')
diff --git a/jupytext/paired_paths.py b/jupytext/paired_paths.py
index 4fe2af3d..731a4c3f 100644
--- a/jupytext/paired_paths.py
+++ b/jupytext/paired_paths.py
@@ -3,6 +3,7 @@
 import os
 from .formats import long_form_one_format, long_form_multiple_formats
 from .formats import short_form_one_format, short_form_multiple_formats
+from .formats import NOTEBOOK_EXTENSIONS
 
 
 class InconsistentPath(ValueError):
@@ -13,7 +14,11 @@ class InconsistentPath(ValueError):
 def base_path(main_path, fmt):
     """Given a path and options for a format (ext, suffix, prefix), return the corresponding base path"""
     if not fmt:
-        return os.path.splitext(main_path)[0]
+        base, ext = os.path.splitext(main_path)
+        if ext not in NOTEBOOK_EXTENSIONS:
+            raise InconsistentPath("'{}' is not a notebook. Supported extensions are '{}'.".format(
+                main_path, "', '".join(NOTEBOOK_EXTENSIONS)))
+        return base
 
     fmt = long_form_one_format(fmt)
     fmt_ext = fmt['extension']
diff --git a/jupytext/version.py b/jupytext/version.py
index 79cfe35b..23792cbd 100644
--- a/jupytext/version.py
+++ b/jupytext/version.py
@@ -1,3 +1,3 @@
 """Jupytext's version number"""
 
-__version__ = '1.3.1'
+__version__ = '1.3.2'


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 414ae142..a12466b9 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -145,7 +145,7 @@ def test_error_not_notebook_ext_input(tmpdir, capsys):
     with open(tmp_file, 'w') as fp:
         fp.write('\n')
 
-    with pytest.raises(JupytextFormatError, match="Extension '.ext' is not a notebook extension. Please use one of"):
+    with pytest.raises(InconsistentPath, match="is not a notebook. Supported extensions are"):
         jupytext([tmp_file, '--to', 'py'])
 
 
@@ -430,6 +430,13 @@ def test_sync_with_pre_commit_hook(tmpdir):
     nb = read(tmp_ipynb)
     compare(nb.cells, [new_markdown_cell('Notebook was edited')])
 
+    # create and commit a jpg file
+    tmp_jpg = str(tmpdir.join('image.jpg'))
+    with open(tmp_jpg, 'wb') as fp:
+        fp.write(b'')
+    git('add', 'image.jpg')
+    git('commit', '-m', 'added image')
+
 
 @requires_jupytext_installed
 @skip_if_dict_is_not_ordered
diff --git a/tests/test_mirror.py b/tests/test_mirror.py
index d9e34d34..8143409b 100644
--- a/tests/test_mirror.py
+++ b/tests/test_mirror.py
@@ -48,7 +48,9 @@ def assert_conversion_same_as_mirror(nb_file, fmt, mirror_name, compare_notebook
 
     # Compare the text representation of the two notebooks
     if compare_notebook:
-        nb_mirror = jupytext.read(mirror_file)
+        # Read and convert the mirror file to the latest nbformat version if necessary
+        nb_mirror = jupytext.read(mirror_file, as_version=notebook.nbformat)
+        nb_mirror.nbformat_minor = notebook.nbformat_minor
         compare(nb_mirror, notebook)
         return
     elif ext == '.ipynb':