Skip to content

Commit

Permalink
Only update the timestamp (not the content) of the text input file
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jan 19, 2021
1 parent d2898da commit 22d6961
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 4 additions & 3 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ Jupytext ChangeLog
---------------

**Changed**
- Jupytext does not work properly with the new cell ids of the version 4.5 of `nbformat>=5.1.0` yet, so we added the requirement `nbformat<=5.0.8` (#715)
- Jupytext does not work properly with the new cell ids of the version 4.5 of `nbformat>=5.1.0` yet, so we added the requirement `nbformat<=5.0.8` ([#715](https://github.com/mwouts/jupytext/issues/715))
- `jupytext --sync` only updates the timestamp of the text file (not the file itself) when that file is the most recent ([#698](https://github.com/mwouts/jupytext/issues/698))

**Fixed**
- Indented magic commands are supported (#694)
- Indented magic commands are supported ([#694](https://github.com/mwouts/jupytext/issues/694))

**Added**
- Added a test that ensures that `py:percent` scripts end with exactly one blank line (#682)
- Added a test that ensures that `py:percent` scripts end with exactly one blank line ([#682](https://github.com/mwouts/jupytext/issues/682))


1.9.1 (2021-01-06)
Expand Down
11 changes: 8 additions & 3 deletions jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,15 @@ def jupytext_single_file(nb_file, args, log):
inputs_nb_file = outputs_nb_file = None

def write_function(path, fmt):
# Do not write the ipynb file if it was not modified
# But, always write text representations to make sure they are the most recent
if path == inputs_nb_file and path == outputs_nb_file:
if path == inputs_nb_file:
# We update the timestamp of the text file to make sure it remains more recent than the ipynb
if path != outputs_nb_file:
log("[jupytext] Sync timestamp of '{}'".format(nb_file))
os.utime(nb_file, None)

# We don't write the ipynb file if it was not modified
return

log("[jupytext] Updating '{}'".format(path))
write(notebook, path, fmt=fmt)
if args.pre_commit:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_metadata_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,11 @@ def test_default_config_has_priority_over_current_metadata(

cfg_file = tmpdir.join("jupytext.toml")
cfg_file.write(
"""default_jupytext_formats = "ipynb,py:percent"
default_cell_metadata_filter = "-some_metadata_key"
"""default_cell_metadata_filter = "-some_metadata_key"
"""
)

jupytext_cli([str(py_file), "--sync"])
jupytext_cli([str(py_file), "--to", "py"])
assert (
py_file.read()
== """# %%
Expand Down

0 comments on commit 22d6961

Please sign in to comment.