🕌
VSCode 保存時+Cell実行時にnotebookをblackでformatする設定
保存時+Cell 実行時に black で format する
ついでに.py では isort で import も自動 sort させる
.vscode/settings.json
{
...
"notebook.formatOnSave.enabled": true,
"notebook.formatOnCellExecution": true
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"isort.args": [
"--profile",
"black"
],
...
}
最初の 2 行が jupyter
isort.args は isort と black の config を統合するためのもの
jupyter では sort がうまく働かない。なぜ?
参考
-
Visual Studio Code March 2023
- 保存時
-
Visual Studio Code May 2023
- Cell 実行時
-
visual studio code - black formatter won't be called when editing notebooks in VSCode - Stack Overflow
- SO
- [Setup Black and Isort in VSCode. Assuming you have installed VSCode and… | by cereblanco | Medium https://cereblanco.medium.com/setup-black-and-isort-in-vscode-514804590bf9]
- isort で import を整形
-
Migration to Python Tools Extensions · microsoft/vscode-python Wiki
- Python エクステンションから black や isort は独立しはじめた
Discussion