1

I am currently developer in a dev container and I am trying to use black as a formatter for python. However, I failed to make it work. Here is my .devcontainer.json

{
    "name": "api",
    "dockerComposeFile": ["../docker-compose.yml", "../docker-compose.devcontainer.yml"],
    "service": "api",
    "workspaceFolder": "/workspace/api",

    "settings": {
        "python.defaultInterpreterPath": "/usr/local/lib/python3.8",
        "python.formatting.provider":"black",
        "python.formatting.blackPath":"/usr/local/lib/python3.8/site-packages/black",
        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
        "python.linting.mypyEnabled":true,
        "editor.insertSpaces": true,
        "editor.tabSize": 4,
        "editor.detectIndentation":false,
        "editor.formatOnSave":true,
    },
    "shutdownAction": "none",
    "extensions": ["ms-python.python", "ms-python.vscode-pylance","ms-azuretools.vscode-docker"],
    //this is port forwarding for the debugger
    "forwardPorts": [8000]
}
Sami Al-Subhi
  • 4,406
  • 9
  • 39
  • 66

1 Answers1

2

I updated paths to python and black and rebuilt the container and then there was a little dot on the bell situated to the bottom right. I clicked on it. I cannot remember the message correctly but it asking me to switch to python formatting (something like that) I clicked ok and it worked!

{
    "name": "api",
    "dockerComposeFile": ["../docker-compose.yml", "../docker-compose.devcontainer.yml"],
    "service": "api",
    "workspaceFolder": "/workspace/api",

    "settings": {
        "python.defaultInterpreterPath": "/usr/local/bin/python",
        "python.formatting.provider":"black",
        "python.formatting.blackPath":"/usr/local/bin/black",
        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
        "python.linting.mypyEnabled":true,
        "editor.insertSpaces": true,
        "editor.tabSize": 4,
        "editor.detectIndentation":false,
        "editor.formatOnSave":false,
        "[python]": {
            "editor.formatOnSave": true
        },
        "python.testing.pytestPath":"/usr/local/bin/pytest",
        "python.testing.pytestEnabled":true
    },
    "shutdownAction": "none",
    "extensions": ["ms-python.python", "ms-python.vscode-pylance","ms-azuretools.vscode-docker"],
    //this is port forwarding for the debugger
    "forwardPorts": [8000]
}
Sami Al-Subhi
  • 4,406
  • 9
  • 39
  • 66