question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Always use LF instead of CRLF for *.ipynb files regardless of platform and when sending code to the kernel

See original GitHub issue

Environment data

  • VS Code version: 1.53.0-insider (2021-01-29T05:13:48.533Z)
  • Jupyter Extension version (available under the Extensions sidebar): v2020.12.414227025
  • Python Extension version (available under the Extensions sidebar): 2021.2.518958983-dev
  • OS (Windows | Mac | Linux distro) and version: Windows 10
  • Python and/or Anaconda version: Python 3.8.5 using Anaconda
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Jupyter server running: Local

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:

  1. download https://github.com/fastai/nbdev/blob/master/nbs/00_export.ipynb
  2. open the file in vscode
  3. modify a cell
  4. do a diff on the cell.
  5. notice that the newlines are messed up. image

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)
User belongs to experiment group 'pythonJoinMailingListVar1'
User belongs to experiment group 'jupyterTest'
User belongs to experiment group 'NativeNotebookEditor'
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import jupyter"
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import notebook"
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py jupyter kernelspec --version
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> D:\Users\claforte\Anaconda3\envs\tensorflow\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
Started kernel Python 3
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> D:\Users\claforte\Anaconda3\envs\fastai\python.exe c:\Users\claforte\.vscode-insiders\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v

XXX

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:28 (13 by maintainers)

github_iconTop GitHub Comments

5reactions
msveshnikovcommented, Jul 11, 2021

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: https://github.com/jupyterlab/jupyterlab/issues/2951 (bug reproduced in latest Jupyter Lab) So basically after editing of a notebook in VSCode you have destroyed notebook in any external server!

4reactions
joyceerhlcommented, Aug 25, 2021

Users can configure the files.eol setting as a temporary workaround, and we can consider fixing this in the builtin ipynb extension. Note also that Colab always uses LF (they just fixed this behavior) https://github.com/jupyterlab/jupyterlab/issues/9465#issuecomment-802215114 /cc @roblourens @DonJayamanne

Read more comments on GitHub >

github_iconTop Results From Across the Web

CRLF vs. LF: Normalizing Line Endings in Git
A better solution is to add a .gitattributes file to your repo so you can enforce line endings consistently in your codebase regardless...
Read more >
LF will be replaced by CRLF in git - What is that and is it ...
The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in <filename>. What's the...
Read more >
How to Ensure Always LF not CRLF on Windows
I am using PhpStorm 2016.2.2 on Windows 10 and want to only ever have Unix ... Warning: LF will be replaced by CRLF...
Read more >
Messaging in Jupyter — jupyter_client 7.4.8 documentation
This document explains the basic communications design and messaging specification for how Jupyter frontends and kernels communicate. The ZeroMQ library ...
Read more >
How to Version Control Jupyter Notebooks - Nextjournal
Jupyter notebooks generate files that may contain metadata, source code, formatted text, ... Jupyter notebook files are human-readable JSON .ipynb files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found