23

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?

Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
dixon
  • 1,265
  • 2
  • 9
  • 10

4 Answers4

36

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)))
Community
  • 1
  • 1
vaab
  • 9,685
  • 7
  • 55
  • 60
  • While I can see the errors hilited, emacs 23 is not displaying what the error actually IS. Can you help? – RichieHH Oct 22 '09 at 01:41
  • see manual of flymake under emacs. What you need is to be on the line and: M-x flymake-display-err-menu-for-current-line . You can bind this to a key. – vaab Oct 24 '09 at 17:59
  • 5
    The best way is to use flymake-cursor. needing to hit keys or hover mice to see what the error is on an already fontified error line is rather silly. flymake-cursor echoes the error in the status bar. My current set up is working superbly:- http://richardriley.net/projects/emacs/dotprogramming#sec-1.5 – RichieHH Oct 25 '09 at 17:35
  • 1
    I wrote a blog post covering this topic. Multi-checkers samples are given for different languages (python, php, javascript) http://goo.gl/xxkOY – vaab Sep 20 '12 at 10:51
  • @vaab where would the shell script be placed? Would it be invoked every time a py file is opened? – dustin Apr 18 '13 at 02:36
  • 2
    @dustin ensure that ``pycheckers`` binary is executable, and either specify full absolute path to it in emacs script or simpler, ensure that ``pycheckers`` is in one of the directories listed in your ``$PATH``. It'll be invoked at each changes you do to the file. For more information check http://goo.gl/xxkOY – vaab Apr 18 '13 at 19:34
  • Did you mean `pylint` instead of `epylint` ? – EoghanM Jan 16 '15 at 21:00
  • @EoghanM ``epylint`` is a wrapper around ``pylint`` for emacs flymake compatibility. It takes care that ``pylint`` is called with the correct options to stick to the standard output format and also try to be clever to run ``pylint`` in the correct location to avoid false positive upon some ``import`` cases. It's still bundled along ``pylint``, and to have more insight on what it does, you could look inside the script itself or look at this copy on github: https://github.com/geordanr/pylint/blob/master/epylint.py . – vaab Jan 19 '15 at 02:31
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:

(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)
        ))
RichieHH
  • 2,116
  • 4
  • 28
  • 30
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.

Vince
  • 7,608
  • 3
  • 41
  • 46
  • I try use pep8.py. The same problem - I can't correct merge two configs. Work only one - pyflakes or pep8.py. – dixon Aug 12 '09 at 07:02
0

Windows batch version of vaab's pychechker

@echo on
pylint %1
pep8 --ignore=E221,E701,E202 --repeat %1
pyflakes %1
Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74