mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.65k stars 386 forks source link

--sync: avoid updating timestamp of *.py if nothing changes #1215

Closed hhoppe closed 6 months ago

hhoppe commented 9 months ago

I use jupytext --sync frequently across many files to synchronize changes in either direction between .py and .ipynb. Often, no synchronization is necessary and it reports:

jupytext --sync **/*.ipynb
[jupytext] Reading notebook.ipynb in format ipynb
[jupytext] Loading notebook.py
[jupytext] Updating the timestamp of notebook.py

Is there any way to avoid updating the timestamp on the *.py file if no synchronization changes occur? Could this be made the default behavior?

(I have some later lint tool that unfortunately invalidates its cache as a result.) I see a flag --use-source-timestamp but I'm not sure if it is intended for bidirectional synchronization.

hhoppe commented 9 months ago

(Another minor annoyance of updating the *.py timestamp is that Emacs warns that it is "reverting the buffer" if it has loaded the file -- even though nothing has changed.)

mwouts commented 6 months ago

Hi @hhoppe , thank you for reporting this, and sorry for the delay in getting back to you. Sure that makes sense, let me see what I can do.

mwouts commented 6 months ago

A development version with a tentative fix is available at

pip install git+https://github.com/mwouts/jupytext.git@skip_update_timestamp

Would you mind confirming if it does what you are looking for?

hhoppe commented 6 months ago

Thanks for doing this! I'm away this weekend and will try it on Tuesday.

mwouts commented 6 months ago

You're welcome ! No hurry at all. Keep me posted, thanks

hhoppe commented 6 months ago

I'm having difficulty building the development branch -- maybe it's because I am using WSL. I first had to apt install nodejs, but even then I get a build error

YN0009: │ nx@npm:15.9.7 [9d75b] couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-9020d20b/build.log)

where the log contains

Error: Cannot find module 'fs/promises'

I may not be the best person to test this out.

mwouts commented 6 months ago

Oh I see - it's not obvious to build the Jupyter Lab extension, sorry about that. Thanks for giving it a try anyway! This should be much easier, and faster too:

HATCH_BUILD_HOOKS_ENABLE=false pip install git+https://github.com/mwouts/jupytext.git@skip_update_timestamp

(the drawback is that you won't get the Jupytext menu in JupyterLab, but maybe you mostly care about the command line?)

hhoppe commented 6 months ago

The new install command line unfortunately gives the same build error.

mwouts commented 6 months ago

No worries! I will test this a bit more on my end, and package the change with the next release, in a few days hopefully.

max-accenta commented 6 months ago

Hi, I was able to install from the skip_update_timestamp branch on my side (Fedora & python3.11). The feature seems to work as expected, thanks for the work.

mwouts commented 6 months ago

Hi, I was able to install from the skip_update_timestamp branch on my side (Fedora & python3.11). The feature seems to work as expected, thanks for the work.

Oh great, thank you @max-accenta for testing it, that's super helpful!