Skip to content

Commit

Permalink
Update the timestamp of the py file only
Browse files Browse the repository at this point in the history
if it is older than that of the nb file
  • Loading branch information
mwouts committed May 5, 2024
1 parent 7963f5f commit bd50cbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Jupytext ChangeLog
- Temporary text notebooks for the `--pipe` or `--check` commands are now created in the notebook directory ([#1206](https://github.com/mwouts/jupytext/issues/1206))
- Jupytext uses the standard library `tomllib` in Python 3.11, or `tomli` in Python 3.10 or older, to match JupyterLab's dependencies ([#1195](https://github.com/mwouts/jupytext/issues/1195))
- The dependencies of the JupyterLab extension were updated ([#1216](https://github.com/mwouts/jupytext/issues/1216), [#1218](https://github.com/mwouts/jupytext/issues/1218), [#1231](https://github.com/mwouts/jupytext/issues/1231))
- `jupytext --sync` will not update the timestamp of text notebooks if their content is unchanged ([#1215](https://github.com/mwouts/jupytext/issues/1215))


**Fixed**
Expand Down
15 changes: 12 additions & 3 deletions src/jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,9 +858,18 @@ def lazy_write(path, fmt=None, action=None, update_timestamp_only=False):
f"[jupytext] Setting the timestamp of {shlex.quote(path)} equal to that of {shlex.quote(nb_file)}"
)
os.utime(path, (os.stat(path).st_atime, os.stat(nb_file).st_mtime))
elif not modified and not path.endswith(".ipynb"):
log(f"[jupytext] Updating the timestamp of {shlex.quote(path)}")
os.utime(path, None)
elif not modified:
if path.endswith(".ipynb"):
# No need to update the timestamp of ipynb files
log(f"[jupytext] Unchanged {shlex.quote(path)}")
elif args.sync:
# if the content is unchanged (and matches ipynb), we don't need
# to update the timestamp as the contents manager will not throw in
# that case (see the try/catch on read_pair(... must_match=True))
log(f"[jupytext] Unchanged {shlex.quote(path)}")
else:
log(f"[jupytext] Updating the timestamp of {shlex.quote(path)}")
os.utime(path, None)

if args.pre_commit:
system("git", "add", path)
Expand Down

0 comments on commit bd50cbe

Please sign in to comment.