Contents

Google like python on vscode

python formatter configuration on vscode

Describes python google style editor settings on vscode


tl;dr

full settings.json settings.json

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
    "security.workspace.trust.banner": "always",
    "security.workspace.trust.untrustedFiles": "open",
    "python.formatting.yapfPath": "/Library/Frameworks/Python.framework/Versions/3.7/bin/yapf",
    "python.sortImports.path": "/Library/Frameworks/Python.framework/Versions/3.7/bin/isort",
    "python.linting.pylintPath": "/Library/Frameworks/Python.framework/Versions/3.7/bin/pylint",
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "text.html.markdown.journal.task.open.bullet",
                "settings": {
                    "foreground": "#FFFF00"
                }
            },
            {
                "scope": "text.html.markdown.journal.task.open.marker",
                "settings": {
                    "foreground": "#FFFF00"
                }
            },
            {
                "scope": "text.html.markdown.journal.task.open.keyword",
                "settings": {
                    "fontStyle": "italic"
                }
            },
            {
                "scope": "text.html.markdown.journal.task.open.text",
                "settings": {}
            },
            {
                "scope": "text.html.markdown.journal.task.completed.keyword",
                "settings": {
                    "fontStyle": "italic"
                }
            },
            {
                "scope": "text.html.markdown.journal.task.completed.marker",
                "settings": {
                    "foreground": "#AAAAAA"
                }
            },
            {
                "scope": "text.html.markdown.journal.task.completed.text",
                "settings": {
                    "foreground": "#AAAAAA"
                }
            },
            {
                "scope": "text.html.markdown.journal.task.completed.bullet",
                "settings": {
                    "foreground": "#FFFF00"
                }
            },
            {
                "scope": "text.html.markdown.journal.memo.keyword",
                "settings": {
                    "fontStyle": "italic"
                }
            },
            {
                "scope": "text.html.markdown.journal.memo.bullet",
                "settings": {
                    "foreground": "#FFFF00"
                }
            },
            {
                "scope": "text.html.markdown.journal.scope",
                "settings": {
                    "foreground": "#FFFF00"
                }
            },
            {
                "scope": "text.html.markdown.journal.link.keyword",
                "settings": {
                    "fontStyle": "italic"
                }
            },
            {
                "scope": "text.html.markdown.journal.link.bullet",
                "settings": {
                    "foreground": "#FFFF00"
                }
            }
        ]
    },
    "editor.fontSize": 13,
    "terminal.integrated.fontFamily": "'MesloLGS NF'",
    "editor.fontFamily": "Menlo, Monaco, 'Courier New', monospace",
    "editor.tabCompletion": "on",
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "[markdown]": {
        "editor.tabCompletion": "onlySnippets",
        "editor.quickSuggestions": {
            "other": "on",
            "comments": "on",
            "strings": "on"
        }

    },
    "[python]": {
        "editor.defaultFormatter": "ms-python.python",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
        "editor.rulers": [
            {
                "column": 80,
                "color": "#5a5a5a80"
            },
        ]
    },

    "python.formatting.provider": "yapf",
    // or "python.linting.pylintPath": "${workspaceFolder}/.venv/bin/yapf",
    "python.formatting.yapfArgs": [
        "--style",
        "google",
    ],
    // or "python.sortImports.path": "${workspaceFolder}/.venv/bin/isort",
    "python.sortImports.args": [
        "--settings-file=${workspaceFolder}/.isort.cfg",
    ],
    "python.linting.enabled": true,
    "python.linting.lintOnSave": true,
    "python.linting.pylintEnabled": true,
    // or "python.linting.pylintPath": "${workspaceFolder}/.venv/bin/pylint",
    "python.linting.pylintArgs": [
        "--load-plugins",
        "pylint_django",
        "pylint_quotes", // related string quotes
    ],
    "workbench.colorTheme": "Community Material Theme Palenight High Contrast",
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
}

Yapf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
    ...
    "python.formatting.provider": "yapf",
    // or "python.linting.pylintPath": "${workspaceFolder}/.venv/bin/yapf",
    "python.formatting.yapfPath": "/Library/Frameworks/Python.framework/Versions/3.7/bin/yapf",
    ...
    "python.formatting.yapfArgs": [
        "--style",
        "google",
    ],
}

Isort

It helps to sort automatically whenever file is saved

vscode’s settings.json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
...

    "python.sortImports.path": "/Library/Frameworks/Python.framework/Versions/3.7/bin/isort",
    // or
    // "python.sortImports.path": "${workspaceFolder}/.venv/bin/isort",
    "python.sortImports.args": [
        "--settings-file=${workspaceFolder}/.isort.cfg",
    ],
...
}

${workspaceFolder}/.isort.cfg

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[settings]
py_version=37
profile=google
src_paths=api,common,core,infra,logs,tests,universe_z

# 3 - Vertical Hanging Indent
multi_line_output=3
include_trailing_comma=True
force_single_line=False

# profile google default
# force_single_line: True
# force_sort_within_sections: True
# lexicographical: True
# single_line_exclusions: ('typing',)
# order_by_type: False
# group_by_package: True

readable references below

Pylint

TODO: force to avoid string double quotes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
{
    ...

    "python.linting.enabled": true,
    "python.linting.lintOnSave": true,
    "python.linting.pylintEnabled": true,
    // or "python.linting.pylintPath": "${workspaceFolder}/.venv/bin/pylint",
    "python.linting.pylintPath": "/Library/Frameworks/Python.framework/Versions/3.7/bin/pylint",
    "python.linting.pylintArgs": [
        "--load-plugins",
        "pylint_django",
        "pylint_quotes", // related string quotes
    ],
    ...
}

IntelliSense

general term for various code editing features including: code completion, parameter info, quick info, and member lists