Open Saltsmart opened 5 months ago
@Saltsmart it would really be helpful to get the logs for this. The way this works is we pass each cell to black
via stdin, and we use .py
extension to tell black to treat the contents sent via stdin as Python text. This was a workaround as VS Code previously did not have a way to trigger formatting on the ipynb
itself. The notebook formatting command triggered formatting on individual cells in parallel.
The upcoming release of VS Code, introduced a new way to register formatters as ipynb
formatters. We will adopt that here when it is in stable.
As for this issue, if you want to try and replicate it vial command line, then do this:
.py
type <file-path> | black —stdin-filename <file-path> -
That simulates what happens inside the extension. We don’t create a file, but feed each cell content in.
@Saltsmart it would really be helpful to get the logs for this. The way this works is we pass each cell to
black
via stdin, and we use.py
extension to tell black to treat the contents sent via stdin as Python text. This was a workaround as VS Code previously did not have a way to trigger formatting on theipynb
itself. The notebook formatting command triggered formatting on individual cells in parallel.The upcoming release of VS Code, introduced a new way to register formatters as
ipynb
formatters. We will adopt that here when it is in stable.As for this issue, if you want to try and replicate it vial command line, then do this:
- Copy contents of the cell to a file with extension
.py
- Then use this command:
type <file-path> | black —stdin-filename <file-path> -
That simulates what happens inside the extension. We don’t create a file, but feed each cell content in.
This issue only happens in Jupyter so I can't reproduce it in py file, and it's not always happening. Even a large file with no-import-statement cell sometimes triggers this bug.
This is what happens to my code (I switch 'format cell on execution' on and running a cell is just the same as formating it, for this issue). I will be willing to upload the log if this happens the next time.
Diagnostic Data
Behaviour
Expected Behavior
Just like these code in one cell:
When formatting, it should produce a line break after the import statement. Other line breaks are unnecessary and annoying.
Actual Behavior
It Sometimes produce formatted output like this:
Reproduction Steps:
It will Sometimes happen in large jupyter notebooks with many cells. I find this issue in several notebooks containing private content. Here are an example file that could be shared:
main.zip
If it's hard to reproduce, I'm willing to help.
Logs:
I have set log level to trace but this issue disappears now. Logs will be given when it happens again.
Outcome When Attempting Debugging Steps:
Did running it from the command line work?
The command is something like
D:/anaconda3/Scripts/black.exe --stdin-filename e:\Project\battery\datapreprocessing_and_plots.py -
It will get stuck since the file isdatapreprocessing_and_plots.ipynb
and there is no such file asdatapreprocessing_and_plots.py
.Extra Details
e:\Project\battery
.These are from settings.json of the profile:
There is no specific setting related to black or python in user settings.json.