visual-studio-codejupyter-notebookwindows-subsystem-for-linuxpython-black

Task to formate an ipynb notebook using the black command-line tool


I am using vscode on windows and wsl (Ubuntu-22.04).

I am trying to define a task to formate an ipynb file using the black command-line tool (not the vscode extension), to workaround my issue https://github.com/microsoft/vscode-black-formatter/issues/515 (the extension deletes the trailing semicolons on notebooks, which I want to avoid).

Let's say :

{
    [
        {
            "label": "notebook-black-format",
            "type": "shell",
            "command": "python3 -m black /mnt/d/python/${fileBasename}",
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": []
        }
    ]
}

That tasks.json works only for files on the working directory as I hardcoded /mnt/d/python. I did that because for example "command": "ls ${workspaceFolder}" would not work (ls: cannot access 'D:\python': No such file or directory), as it expects a path like /mnt/d/python.

I thought about using the command wslpath with the variables ${workspaceFolder} and ${relativeFile}, but I can't make it work on my tasks.json.

So my question is : what should my tasks.json look like so that the task is well running on my 3 notebooks ?


Solution

  • Finally, I gave up the idea of using tasks. I just now use the Ruff extension that formats the notebooks without removing the trailing semicolons.