0

我目前是开发容器中的开发人员,我正在尝试使用黑色作为 python 的格式化程序。但是,我未能使其工作。这是我的.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]
}
4

1 回答 1

1

我更新了 python 和 black 的路径并重建了容器,然后在右下角的铃铛上有一个小点。我点击了它。我无法正确记住该消息,但它要求我切换到 python 格式(类似的东西),我单击确定,它起作用了!

{
    "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]
}
于 2021-07-01T06:10:34.193 回答