-
Notifications
You must be signed in to change notification settings - Fork 391
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
pre-commit removes # -*- coding: utf-8 -*-
pragma
#907
Comments
Thank you @stephanecollot for reporting this. My expectation is that this encoding line should be preserved by Jupytext. Also I was curious to see if there is still a reason nowadays to declare explicitly the utf-8 encoding on Python files, and indeed on this SO question I see this comment:
|
Hi @mwouts I looked more in details, and I was referring to the wrong hook, it is not And this config
I looked into pyupgrade and they actually force to remove it, and there is no option to disable only this. Relevant links: So maybe a better idea to remove it from jupytext, or add an option? |
Hi @stephanecollot , I am wondering if the issue you encounter here is not a particular case of a larger problem. I don't have experience with jupytext/tests/test_pre_commit_3_sync_black_nbstripout.py Lines 28 to 37 in f8e8352
I think you'll have to do the same for
I am sorry I don't have time to test this atm, but hopefully next week I'll cover this with a new test (and if that turns out to solve the issue we will also add this to the documentation). |
Hi, I tried to remove the line below the highlighted line, but not difference, it still add the encoding file in the py file after modification of the notebook. |
I see! To summarise,
thus the two representations are not consistent. My expectation is that, when you click on "save" in Jupyter Lab, you should get a warning that the notebook has changed on disk, and you are asked if you want to "reload" or "overwrite". Is this the case? Now, if you click on "reload", then the latest edit from the pre-commit hook will be reloaded and the encoding removed, but if you click on overwrite obviously you get the encoding back. So, since you want to take the edits from the pre-commit hook, you should use "reload", not "overwrite"... Does this make sense? |
Yes exactly. But every single time I modify the notebook the encoding is back. |
I read your unit test quickly, nice. But somehow I think it does work on my side.
jupytext version 1.13.6 |
Thanks @stephanecollot for the additional inputs. Rather than "revert", you need to "reload", to make sure that you get the version of the notebook without the encoding. I would have expected a "reload" button on the dialog when Jupyter detects that the file has changed on disk. Anyway, you can also click on "File -> Reload", or even close and reopen your notebook in Jupyter. After a reload you should not have the
I guess you are using text notebooks. Why not use paired notebooks and ignore |
I just look into the code and I saw: Lines 63 to 67 in cbfe2ff
I just tried now with an empty notebook, and it works, no first encoding line added. Sorry! |
Oh that's interesting - maybe it's time to remove this - I'll give it a try and keep you posted. |
Hello,
My CICD is running
pre-commit run
And it wants to remove the first line of percent file generate with
jupytext --to py notebook.ipynb --set-formats "ipynb,py:percent"
The first line is:
# -*- coding: utf-8 -*-
Related to the following hook: https://github.com/pre-commit/pre-commit-hooks/blob/master/pre_commit_hooks/fix_encoding_pragma.py
I would like to know what is the best way to handle this issue? Remove the line? Add some setting in pre-commit or jupytext?
The text was updated successfully, but these errors were encountered: