【问题标题】:How to get black - the python formatter - to work on vscode dev container?如何变黑 - python 格式化程序 - 在 vscode 开发容器上工作?
【发布时间】:2021-09-13 04:25:39
【问题描述】:

我目前是开发容器中的开发人员,我正在尝试使用黑色作为 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]
}

【问题讨论】:

标签: python python-black vscode-devcontainer


【解决方案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]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多