From bc72eb31867a6b87ef6aa8a82313548d314468a0 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Tue, 26 Mar 2019 00:15:06 +0100 Subject: [PATCH] Last modified timestamp of a paired notebook is that of the file last written Fix #207 --- jupytext/contentsmanager.py | 3 +++ tests/test_contentsmanager.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jupytext/contentsmanager.py b/jupytext/contentsmanager.py index 194a17365..73d015f29 100644 --- a/jupytext/contentsmanager.py +++ b/jupytext/contentsmanager.py @@ -237,6 +237,7 @@ def save(self, model, path=''): # Save as ipynb first return_value = None + value = None for fmt in jupytext_formats[::-1]: if fmt['extension'] != '.ipynb': continue @@ -267,6 +268,8 @@ def save(self, model, path=''): if alt_path == path: return_value = value + # Update modified timestamp to match that of the pair #207 + return_value['last_modified'] = value['last_modified'] return return_value except Exception as err: diff --git a/tests/test_contentsmanager.py b/tests/test_contentsmanager.py index 14ddfc929..d629c28a2 100644 --- a/tests/test_contentsmanager.py +++ b/tests/test_contentsmanager.py @@ -1121,7 +1121,7 @@ def test_share_py_recreate_ipynb(tmpdir, nb_file): cm.default_cell_metadata_filter = "-all" nb = readf(nb_file) - cm.save(model=dict(content=nb, type='notebook'), path='nb.ipynb') + model_ipynb = cm.save(model=dict(content=nb, type='notebook'), path='nb.ipynb') assert os.path.isfile(tmp_ipynb) assert os.path.isfile(tmp_py) @@ -1134,3 +1134,6 @@ def test_share_py_recreate_ipynb(tmpdir, nb_file): # ipynb is re-created assert os.path.isfile(tmp_ipynb) + + # save time of ipynb is that of py file + assert model_ipynb['last_modified'] == model['last_modified']