-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jupyterlab adds jupytext metadata, but then jupytext --sync
removes it again
#900
Comments
Hi @jli , thank you for reporting this. Well that is interesting! May I ask you to run this Python command? from jupytext.config import find_jupytext_configuration_file
find_jupytext_configuration_file('.') in the folder where you have the notebook? If any configuration file is found, can you share its content? Note: It may happen that Jupytext CLI and Jupyter Lab are using different configurations, as Jupyter Lab cannot access files above the Jupyter root. |
@mwouts Thanks for the quick response! Yep, I do have a formats = "ipynb,py:percent" (With further experimentation, I've found that without this config file, jupyterlab won't automatically create the companion I've also put together a small demo repo for this issue: https://github.com/jli/jupytext_sync_900 Thanks! |
Thank you @jli for the detailed information! I will make sure I can reproduce this, and then we will fix the issue. I'll keep you posted. |
Hi again @jli , I am working on a test at https://github.com/mwouts/jupytext/compare/new_test_for_pre_commit_sync, but at the moment I have not been able yet to reproduce the issue. The test looks like what you reported by maybe I have missed something. Do you think you could evolve that test into something that better reproduces the problematic flow? Thanks! |
I believe the difference between that test and my situation is that when I modify the notebook file, something is adding the This is what's happening in my case:
So in your test after updating the notebook, this assert should be true in order to match my situation: assert "text_representation" in tmpdir.join("test.ipynb").read() I tried adding this, and the assert fails. So, the test isn't reproducing the part where editing the notebook adds the |
Thanks @jli for the additional information. I'll add steps 1. and 2. to the test and hopefully we'll reproduce this problematic |
Indeed with the new version of the test at 8e2f3bb I can reproduce the issue that you documented above (thanks for pointing out at the exact pattern!)
|
Hi @jli , this should be fixed in the new version 1.13.6 that is being published on pypi. Would you mind giving it a try and report if the problem disappears? Thanks |
@mwouts I confirmed that with 1.13.6, the problem goes away: now edits in jupyter-lab no longer add the jupytext metadata. Thanks a lot! |
Use case
My team's use case: we edit
.ipynb
notebooks in Jupyterlab. We use jupytext to create companion.py
files for code review.Historically, we've relied on everyone installing jupytext locally to update the
.py
files after notebook edits. Now, we'd like to addjupytext --sync
via pre-commit to ensure the files are kept in sync.Issue
.py
file. jupyterlab/jupytext also adds ajupytext.text_representation
dict to the notebook'smetadata
.jupytext --sync
runs, it removesmetadata.jupytext.text_representation
from the notebook file again.jupytext
via pre-commit: it updates the .ipynb notebook file to remove the extra jupytext metadata and then fails because the index is outdated:Rerunning
git commit -a
works, since we add jupytext's change to the git index. However, this isn't ideal because it's confusing, and it's annoying to have to do this every time we edit notebooks.Details
I'm wondering why jupytext is adding this metadata in one context (editing via Jupyterlab) but removing it in another (called directly with
jupytext --sync
). I believe this is the code that removes the metadata:jupytext/jupytext/jupytext.py
Line 461 in 57d83aa
It also seems that this only happens when using
--sync
. If I use--from ipynb --to py
instead, then the original notebook isn't written, which avoids this issue. I'm using this as a workaround for now.Versions
This is happening with recent versions:
$ python -V Python 3.8.12 $ pip list | grep -i jup jupyter-client 7.1.0 jupyter-core 4.9.1 jupyter-server 1.13.1 jupyterlab 3.2.5 jupyterlab-pygments 0.1.2 jupyterlab-server 2.10.2 jupytext 1.13.5
The text was updated successfully, but these errors were encountered: