Skip to content
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

Black formatter v2024.0.0 doesn't work in jupyter notebook #447

Closed
mika457 opened this issue Feb 5, 2024 · 8 comments
Closed

Black formatter v2024.0.0 doesn't work in jupyter notebook #447

mika457 opened this issue Feb 5, 2024 · 8 comments
Assignees
Labels
triage-needed Issue is not triaged.

Comments

@mika457
Copy link

mika457 commented Feb 5, 2024

After I updated Black formatter to v2024.0.0, whenever I save the notebook, a notification of "Saving xx.ipynb: formatting" will show up while the formatting will never be done. However, Black formatter v2023.6.0 still works well in terms of formatting on save.
Weixin Image_20240205133559

@github-actions github-actions bot added the triage-needed Issue is not triaged. label Feb 5, 2024
@mika457 mika457 changed the title Black formatter v2024.0.0 can't be activated in jupyter notebook Black formatter v2024.0.0 doesn't work in jupyter notebook Feb 5, 2024
@karthiknadig
Copy link
Member

@mika457 Can you check Output > Black Formatter? see if it actually triggers formatting.

@karthiknadig karthiknadig self-assigned this Feb 5, 2024
@mika457
Copy link
Author

mika457 commented Feb 6, 2024

@karthiknadig Hello! Thanks for your reply. Here are the logs of both v2023.6.0 and v2024.0.0.
v2023.6.0 works well while v2024.0.0 fails to work in jupyter notebook.

v2024.0.0:

2024-02-06 10:07:00.415 [info] e:\Python\python.exe -m black --skip-string-normalization --stdin-filename e:\VS Code Projects\Python & R\Scripts\jupyter_test.py -
2024-02-06 10:07:00.415 [info] CWD formatter: e:\VS Code Projects\Python & R
2024-02-06 10:07:00.425 [info] reformatted e:\VS Code Projects\Python & R\Scripts\jupyter_test.py

All done! ✨ 🍰 ✨
1 file reformatted.

2024-02-06 10:07:14.376 [info] [Info  - 10:07:14 AM] Connection to server got closed. Server will restart.
2024-02-06 10:07:14.376 [info] true
2024-02-06 10:07:14.509 [info] [Error - 10:07:14 AM] Server process exited with code 1.
2024-02-06 10:07:14.983 [info] CWD Server: e:\VS Code Projects\LaTeX
2024-02-06 10:07:14.990 [info] e:\Python\python.exe -m black --version
2024-02-06 10:07:14.990 [info] CWD formatter: e:\VS Code Projects\LaTeX
2024-02-06 10:07:15.132 [info] Version info for formatter running for E:\VS Code Projects\LaTeX:
black, 24.1.1 (compiled: no)
Python (CPython) 3.11.7

2024-02-06 10:07:15.132 [info] SUPPORTED black>=22.3.0
FOUND black==24.1.1

2024-02-06 10:07:15.133 [info] e:\Python\python.exe -m black --version
2024-02-06 10:07:15.133 [info] CWD formatter: e:\VS Code Projects\Markdown
2024-02-06 10:07:15.133 [info] Version info for formatter running for E:\VS Code Projects\Markdown:
black, 24.1.1 (compiled: no)
Python (CPython) 3.11.7

2024-02-06 10:07:15.134 [info] SUPPORTED black>=22.3.0
FOUND black==24.1.1

2024-02-06 10:07:15.134 [info] e:\Python\python.exe -m black --version
2024-02-06 10:07:15.134 [info] CWD formatter: e:\VS Code Projects\Python & R
2024-02-06 10:07:15.135 [info] Version info for formatter running for E:\VS Code Projects\Python & R:
black, 24.1.1 (compiled: no)
Python (CPython) 3.11.7

2024-02-06 10:07:15.136 [info] SUPPORTED black>=22.3.0
FOUND black==24.1.1

2024-02-06 10:07:15.136 [info] e:\Python\python.exe -m black --version
2024-02-06 10:07:15.136 [info] CWD formatter: e:\VS Code Projects\Drawio
2024-02-06 10:07:15.138 [info] Version info for formatter running for E:\VS Code Projects\Drawio:
black, 24.1.1 (compiled: no)
Python (CPython) 3.11.7

2024-02-06 10:07:15.138 [info] SUPPORTED black>=22.3.0
FOUND black==24.1.1

2024-02-06 10:07:15.139 [info] Settings used to run Server:
[
    {
        "cwd": "e:\\VS Code Projects\\LaTeX",
        "workspace": "file:///e%3A/VS%20Code%20Projects/LaTeX",
        "args": [
            "--skip-string-normalization"
        ],
        "path": [],
        "interpreter": [
            "e:\\Python\\python.exe"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off"
    },
    {
        "cwd": "e:\\VS Code Projects\\Markdown",
        "workspace": "file:///e%3A/VS%20Code%20Projects/Markdown",
        "args": [
            "--skip-string-normalization"
        ],
        "path": [],
        "interpreter": [
            "e:\\Python\\python.exe"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off"
    },
    {
        "cwd": "e:\\VS Code Projects\\Python & R",
        "workspace": "file:///e%3A/VS%20Code%20Projects/Python%20%26%20R",
        "args": [
            "--skip-string-normalization"
        ],
        "path": [],
        "interpreter": [
            "e:\\Python\\python.exe"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off"
    },
    {
        "cwd": "e:\\VS Code Projects\\Drawio",
        "workspace": "file:///e%3A/VS%20Code%20Projects/Drawio",
        "args": [
            "--skip-string-normalization"
        ],
        "path": [],
        "interpreter": [
            "e:\\Python\\python.exe"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off"
    }
]

2024-02-06 10:07:15.139 [info] Global settings:
{
    "cwd": "E:\\Microsoft VS Code",
    "workspace": "E:\\Microsoft VS Code",
    "args": [
        "--skip-string-normalization"
    ],
    "path": [],
    "interpreter": [],
    "importStrategy": "useBundled",
    "showNotifications": "off"
}

2024-02-06 10:07:15.139 [info] sys.path used to run Server:
   c:\Users\ZedLv\.vscode\extensions\ms-python.black-formatter-2024.0.0\bundled\libs
   c:\Users\ZedLv\.vscode\extensions\ms-python.black-formatter-2024.0.0\bundled\tool
   e:\Python\python311.zip
   e:\Python\DLLs
   e:\Python\Lib
   e:\Python
   e:\Python\Lib\site-packages
   e:\Python\Lib\site-packages\win32
   e:\Python\Lib\site-packages\win32\lib
   e:\Python\Lib\site-packages\Pythonwin

v2023.6.0:

2024-02-06 10:09:49.721 [info] [Trace - 10:09:49 AM] Sending notification 'textDocument/didChange'.
2024-02-06 10:09:49.774 [info] [Trace - 10:09:49 AM] Sending notification 'textDocument/didChange'.
2024-02-06 10:09:49.784 [info] [Trace - 10:09:49 AM] Sending notification 'textDocument/didChange'.
2024-02-06 10:09:49.802 [info] [Trace - 10:09:49 AM] Sending request 'textDocument/formatting - (5)'.
2024-02-06 10:09:49.803 [info] [Trace - 10:09:49 AM] Sending request 'textDocument/formatting - (6)'.
2024-02-06 10:09:49.803 [info] [Trace - 10:09:49 AM] Sending request 'textDocument/formatting - (7)'.
2024-02-06 10:09:49.803 [info] [Trace - 10:09:49 AM] Sending request 'textDocument/formatting - (8)'.
2024-02-06 10:09:49.807 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.808 [info] e:\Python\python.exe -m black --skip-string-normalization --stdin-filename e:\VS Code Projects\Python & R\Scripts\jupyter_test.py -
2024-02-06 10:09:49.808 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.808 [info] CWD formatter: e:\VS Code Projects\Python & R
2024-02-06 10:09:49.813 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.813 [info] reformatted e:\VS Code Projects\Python & R\Scripts\jupyter_test.py

All done! ✨ 🍰 ✨
1 file reformatted.

2024-02-06 10:09:49.813 [info] [Trace - 10:09:49 AM] Received response 'textDocument/formatting - (5)' in 10ms.
2024-02-06 10:09:49.816 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.816 [info] e:\Python\python.exe -m black --skip-string-normalization --stdin-filename e:\VS Code Projects\Python & R\Scripts\jupyter_test.py -
2024-02-06 10:09:49.816 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.817 [info] CWD formatter: e:\VS Code Projects\Python & R
2024-02-06 10:09:49.829 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.829 [info] reformatted e:\VS Code Projects\Python & R\Scripts\jupyter_test.py

All done! ✨ 🍰 ✨
1 file reformatted.

2024-02-06 10:09:49.833 [info] [Trace - 10:09:49 AM] Received response 'textDocument/formatting - (6)' in 30ms.
2024-02-06 10:09:49.838 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.838 [info] e:\Python\python.exe -m black --skip-string-normalization --stdin-filename e:\VS Code Projects\Python & R\Scripts\jupyter_test.py -
2024-02-06 10:09:49.838 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.838 [info] CWD formatter: e:\VS Code Projects\Python & R
2024-02-06 10:09:49.847 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.847 [info] reformatted e:\VS Code Projects\Python & R\Scripts\jupyter_test.py

All done! ✨ 🍰 ✨
1 file reformatted.

2024-02-06 10:09:49.848 [info] [Trace - 10:09:49 AM] Received response 'textDocument/formatting - (7)' in 45ms.
2024-02-06 10:09:49.850 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.851 [info] e:\Python\python.exe -m black --skip-string-normalization --stdin-filename e:\VS Code Projects\Python & R\Scripts\jupyter_test.py -
2024-02-06 10:09:49.851 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.851 [info] CWD formatter: e:\VS Code Projects\Python & R
2024-02-06 10:09:49.855 [info] [Trace - 10:09:49 AM] Received notification 'window/logMessage'.
2024-02-06 10:09:49.855 [info] All done! ✨ 🍰 ✨
1 file left unchanged.

2024-02-06 10:09:49.855 [info] [Trace - 10:09:49 AM] Received response 'textDocument/formatting - (8)' in 52ms.
2024-02-06 10:09:49.913 [info] [Trace - 10:09:49 AM] Sending notification 'textDocument/didChange'.

Black Formatter v2023.6.0.log
Black Formatter v2024.0.0.log

@b-a0
Copy link

b-a0 commented Feb 7, 2024

Same here, I noticed that saving Jupyter notebooks became very slow as VS code was waiting for the black formatter to finish. It does format, but it takes a while as it's restarting the server process.

Te notebook I have has 2 cells and VS code is configured to format on save.

Unfold for Black Formatter output
2024-02-07 23:03:47.800 [info] [Trace - 11:03:47 PM] Sending request 'textDocument/formatting - (1)'.
2024-02-07 23:03:47.800 [info] [Trace - 11:03:47 PM] Sending request 'textDocument/formatting - (2)'.
2024-02-07 23:03:47.801 [info] [Trace - 11:03:47 PM] Sending request 'textDocument/formatting - (3)'.
2024-02-07 23:03:47.801 [info] [Trace - 11:03:47 PM] Sending request 'textDocument/formatting - (4)'.
2024-02-07 23:03:47.801 [info] [Trace - 11:03:47 PM] Sending request 'textDocument/formatting - (5)'.
2024-02-07 23:03:47.802 [info] [Trace - 11:03:47 PM] Sending request 'textDocument/formatting - (6)'.
2024-02-07 23:03:47.802 [info] [Trace - 11:03:47 PM] Sending request 'textDocument/formatting - (7)'.
2024-02-07 23:03:47.802 [info] [Trace - 11:03:47 PM] Sending request 'textDocument/formatting - (8)'.
2024-02-07 23:03:47.808 [info] [Trace - 11:03:47 PM] Received notification 'window/logMessage'.
2024-02-07 23:03:47.808 [info] C:\ProgramData\Anaconda3\python.exe -m black --line-length 110 --stdin-filename l:\UserData\<SNIP>\Repositories\<SNIP>\some-name\notebooks\plot_aggregated_kpi.py -
2024-02-07 23:03:47.809 [info] [Trace - 11:03:47 PM] Received notification 'window/logMessage'.
2024-02-07 23:03:47.809 [info] CWD formatter: l:\UserData\<SNIP>\Repositories\<SNIP>\some-name
2024-02-07 23:03:47.824 [info] [Trace - 11:03:47 PM] Received notification 'window/logMessage'.
2024-02-07 23:03:47.824 [info] reformatted l:\UserData\<SNIP>\Repositories\<SNIP>\some-name\notebooks\plot_aggregated_kpi.py

All done! ✨ 🍰 ✨
1 file reformatted.

2024-02-07 23:03:47.825 [info] [Trace - 11:03:47 PM] Received response 'textDocument/formatting - (1)' in 25ms.
2024-02-07 23:03:55.323 [info] [Info  - 11:03:55 PM] Connection to server got closed. Server will restart.
2024-02-07 23:03:55.323 [info] true
2024-02-07 23:03:55.499 [info] [Error - 11:03:55 PM] Server process exited with code 1.
2024-02-07 23:03:56.282 [info] CWD Server: l:\UserData\<SNIP>\Repositories\<SNIP>\some-name
2024-02-07 23:03:56.288 [info] C:\ProgramData\Anaconda3\python.exe -m black --version
2024-02-07 23:03:56.288 [info] CWD formatter: l:\UserData\<SNIP>\Repositories\<SNIP>\some-name
2024-02-07 23:03:56.463 [info] Version info for formatter running for L:\UserData\<SNIP>\Repositories\<SNIP>\some-name:
black, 24.1.1 (compiled: no)
Python (CPython) 3.9.18

2024-02-07 23:03:56.463 [info] SUPPORTED black>=22.3.0
FOUND black==24.1.1

2024-02-07 23:03:56.464 [info] Settings used to run Server:
[
    {
        "cwd": "l:\\UserData\\<SNIP>\\Repositories\\<SNIP>\\some-name",
        "workspace": "file:///l%3A/UserData/<SNIP>/Repositories/<SNIP>/some-name",
        "args": [
            "--line-length",
            "110"
        ],
        "path": [],
        "interpreter": [
            "C:\\ProgramData\\Anaconda3\\python.exe"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "onError"
    }
]

2024-02-07 23:03:56.464 [info] Global settings:
{
    "cwd": "C:\\Program Files\\Microsoft VS Code",
    "workspace": "C:\\Program Files\\Microsoft VS Code",
    "args": [
        "--line-length",
        "110"
    ],
    "path": [],
    "interpreter": [],
    "importStrategy": "useBundled",
    "showNotifications": "onError"
}

2024-02-07 23:03:56.464 [info] sys.path used to run Server:
   c:\Users\<SNIP>\.vscode\extensions\ms-python.black-formatter-2024.0.0\bundled\libs
   c:\Users\<SNIP>\.vscode\extensions\ms-python.black-formatter-2024.0.0\bundled\tool
   C:\ProgramData\Anaconda3\python39.zip
   C:\ProgramData\Anaconda3\DLLs
   C:\ProgramData\Anaconda3\lib
   C:\ProgramData\Anaconda3
   C:\ProgramData\Anaconda3\lib\site-packages
   C:\ProgramData\Anaconda3\lib\site-packages\oscillator_snap-1.0-py3.7.egg
   C:\ProgramData\Anaconda3\lib\site-packages\win32
   C:\ProgramData\Anaconda3\lib\site-packages\win32\lib
   C:\ProgramData\Anaconda3\lib\site-packages\Pythonwin

When I switch the black extension to the pre-release v2024.1.10371008 the extension works normally (it seems).

Unfold for Black Formatter output of pre-release version
2024-02-07 23:14:13.871 [info] [Trace - 11:14:13 PM] Sending notification 'textDocument/didChange'.
2024-02-07 23:14:13.875 [info] [Trace - 11:14:13 PM] Sending request 'textDocument/formatting - (17)'.
2024-02-07 23:14:13.875 [info] [Trace - 11:14:13 PM] Sending request 'textDocument/formatting - (18)'.
2024-02-07 23:14:13.878 [info] [Trace - 11:14:13 PM] Received notification 'window/logMessage'.
2024-02-07 23:14:13.878 [info] C:\ProgramData\Anaconda3\python.exe -m black --line-length 110 --stdin-filename l:\UserData\<SNIP>\Repositories\<SNIP>\some-name\notebooks\plot_aggregated_kpi.py -
2024-02-07 23:14:13.878 [info] [Trace - 11:14:13 PM] Received notification 'window/logMessage'.
2024-02-07 23:14:13.878 [info] CWD formatter: l:\UserData\<SNIP>\Repositories\<SNIP>\some-name
2024-02-07 23:14:13.890 [info] [Trace - 11:14:13 PM] Received notification 'window/logMessage'.
2024-02-07 23:14:13.890 [info] reformatted l:\UserData\<SNIP>\Repositories\<SNIP>\some-name\notebooks\plot_aggregated_kpi.py

All done! ✨ 🍰 ✨
1 file reformatted.

2024-02-07 23:14:13.890 [info] [Trace - 11:14:13 PM] Received response 'textDocument/formatting - (17)' in 15ms.
2024-02-07 23:14:13.891 [info] [Trace - 11:14:13 PM] Received notification 'window/logMessage'.
2024-02-07 23:14:13.891 [info] C:\ProgramData\Anaconda3\python.exe -m black --line-length 110 --stdin-filename l:\UserData\<SNIP>\Repositories\<SNIP>\some-name\notebooks\plot_aggregated_kpi.py -
2024-02-07 23:14:13.892 [info] [Trace - 11:14:13 PM] Received notification 'window/logMessage'.
2024-02-07 23:14:13.892 [info] CWD formatter: l:\UserData\<SNIP>\Repositories\<SNIP>\some-name
2024-02-07 23:14:13.901 [info] [Trace - 11:14:13 PM] Received notification 'window/logMessage'.
2024-02-07 23:14:13.901 [info] reformatted l:\UserData\<SNIP>\Repositories\<SNIP>\some-name\notebooks\plot_aggregated_kpi.py

All done! ✨ 🍰 ✨
1 file reformatted.

2024-02-07 23:14:13.901 [info] [Trace - 11:14:13 PM] Received response 'textDocument/formatting - (18)' in 25ms.

VS Code info:

Version: 1.86.0 (system setup)
Commit: 05047486b6df5eb8d44b2ecd70ea3bdf775fd937
Date: 2024-01-31T10:28:19.990Z
Electron: 27.2.3
ElectronBuildId: 26495564
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Windows_NT x64 10.0.14393

@karthiknadig
Copy link
Member

@mika457 try the pre-release version. This might also be related to psf/black#4205 where black just ignores formatting some files.

@mika457
Copy link
Author

mika457 commented Feb 9, 2024

@karthiknadig OK, thanks

@GF-Huang
Copy link

I don't know why the latest version can not detect the conda env what I choose.

image

@karthiknadig
Copy link
Member

@GF-Huang You have not selected a python for your workspace. Please select one using Python: Select Interpreter.

@karthiknadig
Copy link
Member

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.

@karthiknadig karthiknadig closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Issue is not triaged.
Projects
None yet
Development

No branches or pull requests

4 participants