-
Notifications
You must be signed in to change notification settings - Fork 298
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
Always use LF instead of CRLF for *.ipynb files regardless of platform and when sending code to the kernel #4576
Comments
Hi @claforte, does toggling the following VS Code setting stop the line ending conversions? You can get to this UI with Ctrl+Shift+P to open the Command Palette, then type 'Open Settings (UI)'. |
If you open a freshly cloned ipynb after setting the files.eol setting to your preferred setting, do the endings still get converted? The default line ending on Windows is '\r\n' (this is most likely what you are getting with the 'auto' setting), so I believe that is what VSCode is applying to your files. I don't believe changing that setting results in existing '\r\n' being converted to the new '\n', so unfortunately I think you'd need to do a find and replace on the files that have already been converted. |
Hi Joyce, I tried what you suggested (set vscode-insiders eol to \n, manually replaced all \r\n by \n in notepad++, restarted vscode-insiders, modified a cell, saved) and it looks like no new \r\n appeared. Still it would be great if vscode-jupyter made sure it never added \r\n at the end of code line, since Jupyter notebook, AFAIK, never uses \r\n, and a lot of tools probably assume that. Thanks, Christian |
Great to hear the setting change stops the conversions. Thank you for highlighting this. From related issues like jupyter/nbconvert#1062 it does seem that Jupyter notebooks tend to default to LF even on Windows. The |
Thanks a lot for your responsiveness Joyce, I appreciate it! |
The Jupyter extension is responsible for writing out the contents of the file, not the user. Hence we are in full control over whether we use \n or \r\n. I don't see any need for a VS Code update here. @joyceerhl /cc |
This is honestly very annoying behavior (I mean conversion of LF to CRLF). After such a notebook uploaded to Jupyter Lab server, I start to have incorrect character typed. This is another bug of Jupyter Lab, which unfortunately destroy your DEV experience. See here: |
exactly true !!! |
I have used several different jupyter notebook editors. When running "jupyter notebook" on both Windows and linux based systems, the notebook output consistently uses "\n" in the double-quoted lines of each cell -- not "\r\n". The only editor that I've seen output "\r\n" is The VS Code jupyter notebook extension. This inconsistency causes headaches when diff'ing notebook file versions stored in git repositories. The issue is not the same as the common problem of Windows based systems insisting upon ending text file lines with the control characters \r\n and other systems just using \n. (git has features to help cope with this, which you are probably aware.) So, in my opinion, the "File:EOL" setting in VS Code should not be used to control the line ending characters of the notebook cell double-quoted lines. I think the simple answer is to just follow the convention of "\n" to represent line end in the double-quoted lines. |
Is there any way that we could prioritize resolving this bug? Destroying the diff makes it impossible to sanely understand changes to notebook files during code review -- which will be even more important as we encourage folks to use version control for their |
Users can configure the |
Sound like somethign for debt week. |
This is causing problems for many Jupyter users: jupyterlab/jupyterlab#2951 Can you please fix this? |
FYI, it looks like microsoft/vscode#133762 fixed the line endings in cell sources in ipynb files. |
The verification doesn't appear to be testing the end-of-line representation for each line of notebook cell. You would need to make a notebook cell with at least two lines to see this. Attached is a small notebook file with two cells each with multiple lines. (File name extension changed to
|
@mburghart-qualitrol my screenshot was just to show no /r in the file happened to have open. It works with multiple lines in a cell too: |
I many cases the files itself looks like one line, is there a way to tell VS Code to parse it correctly? |
@RoyiAvital sorry not sure what you're saying. That the json for your ipynb file has no linefeeds in it? |
@rchiodo , Indeed. Any way to enforce VS Code to save it a multi line manner? |
You mean your code cells all have a single line in them? What does the ipynb look like? Cells usually have a format like so: {
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"import os\n",
"\n",
"a,b,c = 'hihi', os, tf.__version__\n",
"print(a, b, c)"
]
}, And I believe you're saying your notebook looks like so?:
Or does it have the \n in the source lines? |
Are you saying VS code can't open that file? It looks fine to me. If it doesn't open then the JSON is likely invalid. Or are you asking VS code to format it so that it isn't one line? It shouldn't be doing that. Although that would be an issue on VS code itself, not the jupyter extension. I believe the code is here: |
@rchiodo , Can open and display it correctly. I wonder abut 2 things:
|
@RoyiAvital what is your version of VS Code and the jupyter extension? We might have at one time saved the file as a single line, but the code that saves a file now should write it out with linefeeds. |
My version is |
I'm creating a new issue. This shouldn't be happening: |
Environment data
Expected behaviour
When editing a notebook, lines ending in "\n" shouldn't be modified to "\r\n"
Actual behaviour
It appears as soon as I modify the content of a cell, the editor is replacing all "\n" by "\r\n". I don't understand why, and it's causing downstream tools (e.g. nbdev/nbparse) to no longer be able to parse the .ipynb properly.
Steps to reproduce:
This seems to happen for any .ipynb file on my PC. I did a git clone of nbdev (
https://github.com/fastai/nbdev/blob/master/nbs/00_export.ipynb
) and ran the notebook, but chances are you only need to open a file:Logs
Output for
Jupyter
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toJupyter
)The text was updated successfully, but these errors were encountered: