参考:GitHub - google/yapf: A formatter for Python files
pip install yapf
yapf --style-help > yapf_style.cfg
vim yapf_style.cfg
将yapf_style.cfg放在工程目录下,或者与要格式化的文件在同一目录
如果想一劳永逸的话,可以将yapf_style.cfg改名为style,直接放入$HOME/.config/yapf/下,其中HOME目录在windows上需要自己设置添加进PATH,Linux和Mac os就是~,这时vscode配置里yapfArgs可以不写入。
YAPF Github上的说明:
YAPF will search for the formatting style in the following manner:
If none of those files are found, the default style is used (PEP8).
详细可以参考YAPF的Github主页
"python.formatting.provider": "yapf",
"python.formatting.yapfArgs": [
"--sytle={based_on_style: yapf, indent_width: 4, column_limit: 120}"
],
"python.formatting.autopep8Args": [
"--max-line-length=120",
],
"python.linting.flake8Enabled": true,
"python.linting.lintOnSave": true,
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E501, E262",
],
"python.linting.blackArgs": [
"--line-length", "120",
"--skip-string-normalization",
],