我最近一直在尝试熟悉google/yapf 。但不知何故,我无法设置 .style.yapf
甚至 setup.cfg
。我不确定将这些文件放在哪里。目前,我正在使用当前目录中的任何/或两个文件,但全局设置始终覆盖我的 .style.yapf/setup.cfg
文件。有人可以帮我吗,我使用他们的旋钮和 github/yapf 上给出的示例没有得到预期的结果
最佳答案
来自the docs :
YAPF will search for the formatting style in the following manner:
- Specified on the command line
- In the [style] section of a .style.yapf file in either the current directory or one of its parent directories.
- In the [yapf] section of a setup.cfg file in either the current directory or one of its parent directories.
- In the ~/.config/yapf/style file in your home directory.
If none of those files are found, the default style is used (PEP8).
如果我使用以下 Python 输入进行测试:
class Example: # This is an example
def __init__(self):
pass
运行yapf example.py
不会产生任何变化:
class Example: # This is an example
def __init__(self):
pass
但是如果我在当前目录中创建 .style.yapf
并包含以下内容:
[style]
SPACES_BEFORE_COMMENT=5
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=true
然后重新运行yapf example.py
,我得到:
class Example: # This is an example
def __init__(self):
pass
如果我希望这些更改全局应用,我会创建具有相同内容的 ~/.config/yapf/style
。
我还可以在当前目录(或父目录)中创建一个名为 setup.cfg
的文件,其中包含以下内容:
[yapf]
SPACES_BEFORE_COMMENT=5
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=true
关于python - 无法使用 yapf(谷歌的 python 格式化程序)设置/使用旋钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55574427/