-
Notifications
You must be signed in to change notification settings - Fork 394
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
Wrong paired paths when syncing with the --pre-commit flag #506
Comments
Hello @slideclimb , thank you for reporting this. I will have a look soon. |
Hi @slideclimb , I have extracted a test from your report (thanks again), see ff5b466 . Here at least, the test runs OK, so I am sorry I have not yet reproduced your issue. Do you think there is remaining difference, either
Also, it you can, let me know if the same test works for you, or not, and/or if you can tweak it to reproduce the issue. |
Thanks for taking the time to create a detailed example! The only difference I see is that you have the notebook file tracked in git, whereas I have the Python file tracked. This seems to be the problem, tracking only the Python file throws an exception, but tracking (only) the notebook file works fine. We don't have any difference in the other points you mentioned. The metadata is the same and Now I'm starting to doubt if I'm using jupytext the way it is intended... I use jupytext to create a paired Python file that I put in git, so I don't have to put the notebook file in git to avoid cumbersome and useless diffs/commits. Does that make sense? |
Oh I see... So, indeed now I can reproduce what you see (and I'll try to fix it). Now, the question is what you want to do with the pre-commit. If you have the Python file tracked, then the |
I have added the test above to the collection of Jupytext test. Following the changes made at #508 , the test now works, so I'll close this issue, and let you know (soon) when I have published a release candidate so that you can test on your side. Thanks again for your report! |
@slideclimb , would you like to give a try to the latest RC, and hopefully confirm that the problem is gone? Thanks!
|
Thanks for the quick fix! I can confirm that the exception is gone 😄... But the pre-commit hook does nothing when I change the notebook file. (The list of Just to be sure we're on the same page, what I've just done is:
If I understand your test correctly, you first create the Python file and set it up with a paired notebook file? I think that's the only difference I see, as I create a notebook file and set it up paired Python file. When I have only notebook files in a repo, the git diff is always empty and therefore I can't commit. But usually I have other python files living next to it that have been edited, or I manually update one of the notebooks before committing which then takes care of the rest. |
Thanks @slideclimb for the follow-up. I'll adjust the test to match your use case, i.e. add One more question: which program do you use to edit the |
Thanks, I really hope we get it right this time :p I use PyCharm. |
@slideclimb, that's good to know. We don't have a plugin yet for PyCharm (cf. #147), but I was wondering if one couldn't use the File Watchers in PyCharm. Personnally, I do this for black, and it works well. So I tried the following: and it works partially, in the sense that, if you edit the Please pay attention however: with this settings, any change to the Let me know what you think! |
That's a great solution! Didn't know about file watchers. I suppose this works, and I guess the pre-commit hook then indeed is unnecessary. Nonetheless, I still think the pre-commit hook should work... About a plugin, I have some experience with JetBrains plugins, so if you want I could try to cook up a prototype some time? I guess it should be possible to register file watchers from within that plugin, and add something that does a |
I tried setting up the file watchers in an existing project. So the notebook and python files are already paired, and currently synced. I observed the following:
I'll edit this comment whenever I have been able to reproduce these issues. So far I have not been successful in reproducing either. Just putting it here so you know it exists and I will get reminded of it whenever I get back here :) |
Thank you @slideclimb for the update. Yes using Jupytext in a file watcher is super new and maybe not so safe... Maybe this is because a) In Jupyter, the plugin
b) In VIM, the jupytext-vim plugin does not use Also, I did not follow-up on the pre-commit. I agree that it should work. We left it at the point where it was not acting on changes on the |
I'm interested in the what the solution of unstaging the .ipynb file instead of .gitignore-ing it looks like, but i didn't see that in the link you shared. Can you point me to an example of that? Just starting in on jupytext and loving it already, so thanks for building it! |
Hi @benlindsay , I think in the comment above I was refering to the pre-commit script example at https://github.com/mwouts/jupytext/blob/v1.9.1/docs/using-pre-commit.md. We've removed it from the current version of the documentation as we think that pre-commit hooks are the way to go. By the way, our current documentation at https://jupytext.readthedocs.io/en/stable/using-pre-commit.html is a bit short. We plan to post a longer article about pre-commit hooks for notebooks in the near future. Until then the best documentation are the tests We have not included an example where we unstage the In you own use case, do you use Jupyter to edit notebooks? If so, and if you only commit the |
Thanks for the links! I plan to edit notebooks in jupyter and sometimes editing the .py files directly. The solution I'm trying out now is leaving .ipynb files |
I have the following directory structure, where the
nb/test.ipynb
is paired with thepy/test.py
.The notebook and Python file are paired with
"jupytext": {"formats": "py//py,nb//ipynb"}
. (usingjupytext --set-formats py//py,nb//ipynb nb/test.ipynb
)This works fine when syncing with
jupytext --sync nb/test.ipynb
, but when syncing withjupytext --sync --pre-commit
I get the following exception:I have tried all sorts of pairings (taken from/inspired by the comments in #180), among them:
..//py,ipynb (and
ipynb,..//py`)nb//ipynb,..//py
nb//ipynb,py//py
but they all throw a similar exception (and work fine with a regular sync).
Addition
As a current workaround I'm using
jupytext --sync nb/*.ipynb
in my pre-commit hook, which seems to work fine.The text was updated successfully, but these errors were encountered: