简体   繁体   English

在macOS / OSX上配置flake8

[英]Configuring flake8 on macOS/OSX

I'm trying to change the line length for flake8 (version 3.7.7) on OSX (10.14.5), so that it matches the line length used in Black (the Python auto formatter). 我正在尝试在OSX(10.14.5)上更改flake8(版本3.7.7)的行长,以使其与Black(Python自动格式化程序)中使用的行长匹配。 I'm using Sublimetext 3 with the SublimeLinter-flake8 plugin. 我正在将Sublimetext 3与SublimeLinter-flake8插件一起使用。

What I've tried to do is create a folder ~/.config/flake8 and then placed a file in it with the settings: 我试图做的是创建一个文件夹〜/ .config / flake8,然后使用以下设置将文件放入其中:

[flake8]
max-line-length = 88

I have called this file config.flake8. 我将此文件称为config.flake8。 In addition, I've tried naming it 'flake8', 'flake8.rc', placing it in both ~/.config and ~/.config/flake8. 另外,我尝试将其命名为“ flake8”,“ flake8.rc”,并将其放置在〜/ .config和〜/ .config / flake8中。

However, this hasn't worked. 但是,这没有用。 I get 我懂了

./lorenz.py:13:80: E501 line too long (81 > 79 characters)

both when I run flake8 in the terminal (so this is not an ST3 problem) and when I have the code open on Sublimetext3. 当我在终端中运行flake8时(这不是ST3问题),以及当我在Sublimetext3上打开代码时。

I've looked at the documentation for flake8 and haven't really been able to get much out of it. 我看了关于flake8的文档,但实际上并不能从中得到很多。

Can anyone let me know where I'm going wrong? 谁能让我知道我要去哪里错了?

Instead of putting a file into the directory ~/.config/flake8 , the name of the file should be flake8 and it should be placed in the ~/.config directory: 不要将文件放在目录~/.config/flake8 ,而应将文件名命名为flake8并将其放置在~/.config目录中:

For example with the config in the following location: 例如,配置位于以下位置:

$ cat ~/.config/flake8 
[flake8]
max-line-length = 88

I can now see that flake8 gives warnings about 88 line length lines: 现在我可以看到flake8给出了有关88行长度的警告:

$ python3 -m flake8 
./pinpoint-poc-db-listener.py:17:89: E501 line too long (96 > 88 characters)
./pinpoint-poc-db-listener.py:18:89: E501 line too long (248 > 88 characters)

Reference: https://flake8.pycqa.org/en/latest/user/configuration.html 参考: https : //flake8.pycqa.org/en/latest/user/configuration.html

Does it have to be a system-wide configuration, or could it be just for that one project? 它必须是系统范围的配置,还是仅用于那个项目? If the latter applies, you could try saving it to a file called .flake8 in your project's root folder. 如果适用后者,则可以尝试将其保存到项目的根文件夹中的.flake8文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM