Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Emacs Flymake mode for python with pyflakes and pylint checking code?

For checking code in python mode I use flymake with pyflakes

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

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

like image 695
dixon Avatar asked Aug 11 '09 11:08

dixon


2 Answers

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...

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

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

#!/bin/bash

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

For the emacs lisp part:

(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)))
like image 58
vaab Avatar answered Nov 16 '22 04:11

vaab


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:

(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)
        ))
like image 7
RichieHH Avatar answered Nov 16 '22 03:11

RichieHH