如何使用带pyflakes和pylint检查代码的Emacs Flymake模式进行python?

时间:2020-12-23 17:26:51

For checking code in python mode I use flymake with pyflakes

为了检查python模式中的代码,我使用flymake和pyflakes

Also I want check code style (pep8) with pylint (description on the same page with pyflakes)

另外我想用pylint检查代码样式(pep8)(与pyflakes在同一页面上的描述)

This solutions work. But I can't configure flymake for work with pyflakes and pylint together. How can I do it?

此解决方案有效。但我无法配置flymake与pyflakes和pylint一起工作。我该怎么做?

4 个解决方案

#1


34  

Well, flymake is just looking for a executable command thats output lines in a predefined format. You can make a shell script for example that will call successively all the checkers you want...

好吧,flymake只是在寻找以预定义格式输出行的可执行命令。例如,您可以创建一个shell脚本,它将连续调用您想要的所有检查器...

You must also make sure that your script ends by returning errorlevel 0. So this is an example:

您还必须通过返回errorlevel 0来确保脚本结束。所以这是一个示例:

This is what I've done in a "pycheckers" script:

这就是我在“pycheckers”脚本中所做的:

#!/bin/bash

epylint "$1" 2>/dev/null
pyflakes "$1"
pep8 --ignore=E221,E701,E202 --repeat "$1"
true

For the emacs lisp part:

对于emacs lisp部分:

(when (load "flymake" t)
  (defun flymake-pyflakes-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
               'flymake-create-temp-inplace))
       (local-file (file-relative-name
            temp-file
            (file-name-directory buffer-file-name))))
      (list "pycheckers"  (list local-file))))
   (add-to-list 'flymake-allowed-file-name-masks
             '("\\.py\\'" flymake-pyflakes-init)))

#2


7  

Usually one can enable flymake mode in the python-mode-hook. Unfortunately that causes issues with things like py-execute-buffer which create temporary buffers which invoke the hook and then cause flymake mode to hiccup because of the lack of "real file". The solution is to modify the conditions where you add the hook:- e.g mine is:

通常可以在python-mode-hook中启用flymake模式。不幸的是,这会导致诸如py-execute-buffer之类的问题,它会创建临时缓冲区来调用钩子然后因为缺少“真实文件”而导致flymake模式打嗝。解决方案是修改添加钩子的条件: - 例如我的:

(add-hook 'python-mode-hook 
      (lambda () 
        (unless (eq buffer-file-name nil) (flymake-mode 1)) ;dont invoke flymake on temporary buffers for the interpreter
        (local-set-key [f2] 'flymake-goto-prev-error)
        (local-set-key [f3] 'flymake-goto-next-error)
        ))

#3


0  

You may want to check out the Lisp script here (http://charlie137-2.blogspot.com/2009/08/check-python-coding-style-on-fly-with.html), which should help with checking PEP8 a la pep8.py. I don't use pyflakes or pylint, but I imagine you could easily adjust this to work with other checkers.

您可以在这里查看Lisp脚本(http://charlie137-2.blogspot.com/2009/08/check-python-coding-style-on-fly-with.html),这有助于检查PEP8 la pep8.py.我不使用pyflakes或pylint,但我想你可以很容易地调整它以与其他跳棋一起工作。

#4


0  

Windows batch version of vaab's pychechker

Windows批量版本的vaab的pychechker

@echo on
pylint %1
pep8 --ignore=E221,E701,E202 --repeat %1
pyflakes %1

#1


34  

Well, flymake is just looking for a executable command thats output lines in a predefined format. You can make a shell script for example that will call successively all the checkers you want...

好吧,flymake只是在寻找以预定义格式输出行的可执行命令。例如,您可以创建一个shell脚本,它将连续调用您想要的所有检查器...

You must also make sure that your script ends by returning errorlevel 0. So this is an example:

您还必须通过返回errorlevel 0来确保脚本结束。所以这是一个示例:

This is what I've done in a "pycheckers" script:

这就是我在“pycheckers”脚本中所做的:

#!/bin/bash

epylint "$1" 2>/dev/null
pyflakes "$1"
pep8 --ignore=E221,E701,E202 --repeat "$1"
true

For the emacs lisp part:

对于emacs lisp部分:

(when (load "flymake" t)
  (defun flymake-pyflakes-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
               'flymake-create-temp-inplace))
       (local-file (file-relative-name
            temp-file
            (file-name-directory buffer-file-name))))
      (list "pycheckers"  (list local-file))))
   (add-to-list 'flymake-allowed-file-name-masks
             '("\\.py\\'" flymake-pyflakes-init)))

#2


7  

Usually one can enable flymake mode in the python-mode-hook. Unfortunately that causes issues with things like py-execute-buffer which create temporary buffers which invoke the hook and then cause flymake mode to hiccup because of the lack of "real file". The solution is to modify the conditions where you add the hook:- e.g mine is:

通常可以在python-mode-hook中启用flymake模式。不幸的是,这会导致诸如py-execute-buffer之类的问题,它会创建临时缓冲区来调用钩子然后因为缺少“真实文件”而导致flymake模式打嗝。解决方案是修改添加钩子的条件: - 例如我的:

(add-hook 'python-mode-hook 
      (lambda () 
        (unless (eq buffer-file-name nil) (flymake-mode 1)) ;dont invoke flymake on temporary buffers for the interpreter
        (local-set-key [f2] 'flymake-goto-prev-error)
        (local-set-key [f3] 'flymake-goto-next-error)
        ))

#3


0  

You may want to check out the Lisp script here (http://charlie137-2.blogspot.com/2009/08/check-python-coding-style-on-fly-with.html), which should help with checking PEP8 a la pep8.py. I don't use pyflakes or pylint, but I imagine you could easily adjust this to work with other checkers.

您可以在这里查看Lisp脚本(http://charlie137-2.blogspot.com/2009/08/check-python-coding-style-on-fly-with.html),这有助于检查PEP8 la pep8.py.我不使用pyflakes或pylint,但我想你可以很容易地调整它以与其他跳棋一起工作。

#4


0  

Windows batch version of vaab's pychechker

Windows批量版本的vaab的pychechker

@echo on
pylint %1
pep8 --ignore=E221,E701,E202 --repeat %1
pyflakes %1