web developer & system programmer

coder . cl

ramblings and thoughts on programming...


integrating pycheckers and emacs

published: 09-08-2011 / updated: 09-08-2011
posted in: development, emacs, programming, python, tips
by Daniel Molina Wegener

There are many versions of the pycheckers.py script. It is wrapper between various static analysis tools for Python code. I have my own modified version of the pycheckers script and it is running pep8, pychecker, pyflakes and pylint. I have that script integrated with Emacs, so I run the compile command to verify the code quality. My code should meet all Python standards to pass all checks that are made by those tools.

You can download my version of the pycheckers.py script and you must put it on path available from the PATH environment variable scope. You must be sure that Emacs finds the pycheckers.py command in your PATH.


;;; load the python mode.
(autoload 'python-mode
          "python-mode"
          "Mode for editing Python source files")

;;; autoload the python-mode on each opened python file.
(setq auto-mode-alist
		(append '(("\.py" . python-mode)) auto-mode-alist)))

;;; we ensure that we will use the font-lock mode
;;; on Python files.
(setq font-lock-auto-mode-list
      (list 'python-mode))

;;; finally we create the python mode hook function.
(defun dmw-python-mode-hook ()
  (setq py-indent-offset 4
        py-smart-indentation nil
        py-continuation-offset 4
        indent-tabs-mode nil
        py-pychecker-command "pycheckers"
        py-pychecker-command-args (quote ("")))
  (setq interpreter-mode-alist(cons '("python" . python-mode)
                                    interpreter-mode-alist))
  (eldoc-mode 1)
  (define-key py-mode-map "C-cC-w" (lambda ()
                                      (interactive)
                                      (command-execute
                                       'py-pychecker-run)))
  (message ">>> done dmw-python-mode-hook..."))

;;; then we add the hook function.
(add-hook 'python-mode-hook 'dmw-python-mode-hook)

I hope that you will enjoy checking your code. You just need to install pep8, pylint, pychecker and pyflakes.


No coments yet.

post a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>