如何在PyCharm中为flake8启用自动代码格式化 [英] How do I enable auto code formatting for flake8 in PyCharm

查看:1232
本文介绍了如何在PyCharm中为flake8启用自动代码格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Tox来运行单元测试,并使用flake8命令检查代码格式错误.每次我在PyCharm中编写代码时,我都会运行tox,然后意识到我有很多烦人的格式错误,我必须返回并手动修复.我希望PyCharm自动格式化代码(根据flake8 google的代码,每次我在停止输入后自动保存该代码.

I use Tox to run unit tests, with a flake8 command that checks for code formatting errors. Each time I code in PyCharm, I run tox then realise I have a bunch of annoying formatting errors I have to back and manually fix. I would like PyCharm to automatically format the code (according to flake8 google for me each time it auto-saves after I stop typing.

我的tox testenv看起来像这样:

my tox testenv looks like this:

[testenv:flake8]
commands=flake8 <my_code_directory>
deps =     
  flake8==2.4.1    
  flake8-import-order==0.11    
  pep8-naming==0.4.1 

[flake8] 
max-line-length = 120 
import-order-style = google

这可能吗?我必须在某个地方下载特定的插件吗?如果不使用flake8,那么PEP-8怎么办?

Is this possible? Do I have to download a specific plugin somewhere? If not with flake8, what about just PEP-8?

推荐答案

Flake8和导入顺序无法按照您所看到的方式自动修复.您可以使用autopep8自动修复pep8.

Flake8 and import ordering are not auto-fixable in a way that complies with what you're seeing. You can auto-fix pep8 with autopep8.

尽管有关于此处的讨论,但有关为Flake8实现此操作.

There are discussions here about implementing this for Flake8 though.

这篇关于如何在PyCharm中为flake8启用自动代码格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆