From 894b9c5932a057f12889829210cf8957d312a74d Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Wed, 13 Mar 2019 00:35:02 +0100 Subject: [PATCH] "save" returns the value that corresponds to the current path #180 --- jupytext/contentsmanager.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/jupytext/contentsmanager.py b/jupytext/contentsmanager.py index 1020fa3ea..29fa5f016 100644 --- a/jupytext/contentsmanager.py +++ b/jupytext/contentsmanager.py @@ -237,7 +237,7 @@ def save(self, model, path=''): self.update_paired_notebooks(path, fmt, jupytext_formats) # Save as ipynb first - latest_result = None + return_value = None for fmt in jupytext_formats[::-1]: if fmt['extension'] != '.ipynb': continue @@ -245,7 +245,9 @@ def save(self, model, path=''): alt_path = full_path(base, fmt) self.create_prefix_dir(alt_path, fmt) self.log.info("Saving %s", os.path.basename(alt_path)) - latest_result = super(TextFileContentsManager, self).save(model, alt_path) + value = super(TextFileContentsManager, self).save(model, alt_path) + if alt_path == path: + return_value = value # And then to the other formats, in reverse order so that # the first format is the most recent @@ -262,9 +264,11 @@ def save(self, model, path=''): else: self.log.info("Saving %s", os.path.basename(alt_path)) with mock.patch('nbformat.writes', _jupytext_writes(fmt)): - latest_result = super(TextFileContentsManager, self).save(model, alt_path) + value = super(TextFileContentsManager, self).save(model, alt_path) + if alt_path == path: + return_value = value - return latest_result + return return_value except Exception as err: raise HTTPError(400, str(err))