Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install plone.recipe.codeanalysis

How to install plone.recipe.codeanalysis

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install plone.recipe.codeanalysis
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)
1.0b3 Available View build log
Lastest release
version 1.0b3 on Jan 9th, 2014


plone.recipe.codeanalysis provides static code analysis for Buildout-based Python projects, including flake8, JSHint, CSS Lint, zptlint, and other code checks.

This buildout recipe creates a script to run the code analysis:


By default plone.recipe.codeanalysis also creates a git pre-commit hook, in order to run the code analysis automatically before each commit.


Just add a code-analysis section to your buildout.cfg:

parts += code-analysis

recipe = plone.recipe.codeanalysis
directory = ${buildout:directory}/src

The directory option is not required. Though, if you don't specify a directory the code analysis will check every file in your buildout directory.

Supported options

The recipe supports the following options:

Directory that is subject to the code analysis.
If set to True, a git pre-commit hook is installed that runs the code analysis before each commit.
If set to True, run Flake8 code analysis. Default is True.
Skip errors or warnings. See Flake8 documentation for error codes. Default is none.
Comma-separated filename and glob patterns default. Say you want to exclude bootstrap.py, setup.py and all collective.* and plone.* packages. Just set "flake8-exclude=bootstrap.py,docs,*.egg,setup.py,collective.*, plone.*" in your buildout configuration. Default is bootstrap.py,docs,*.egg.
McCabe complexity threshold. Default is 10.
Set maximum allowed line length. Default is 79.
If set to True, jshint code analysis is run. Default is False. Note that plone.recipe.codeanalysis requires jshint >= 1.0.

JSHint executable. Default is jshint. If you have JSHint installed on your system and in your path, there is nothing to do. To install JSHint in your buildout, use the following:

recipe = gp.recipe.node
npms = jshint
scripts = jshint

set jshint-bin to '${buildout:directory}/bin/jshint'.

Allows you to specify directories which you don't want to be linted. Default is none. If you want JSHint to skip some files you can list them in a file named .jshintignore. See JSHint documentation for more details.

If set to True, CSS Lint code analysis is run. Default is False.

CSS Lint options should be configured using a .csslintrc file. A typical .csslintrc file will look like this:


This typical configuration includes a list of CSS rules that will be ignored as they are considered useless.

See CSS Lint documentation for a detailed list and description of the rules.


Set the path to a custom version of CSS Lint, e.g. "/usr/local/bin/csslint".

If you have CSS Lint installed in your system and path, there is usually nothing you have to do. To install CSS Lint with buildout, add the following section to your buildout and set csslint-bin to "{buildout:bin-directory}/csslint":

[csslint] recipe = gp.recipe.node npms = csslint scripts = csslint

If set to True, zptlint code analysis is run. Default is False.

Note that the buildout itself already depends on zptlint, so no extra configuration is needed.

Set the path to a custom version of zptlint. Default is bin/zptlint.
If set to True, warnings about deprecated methods will be printed. Default is False.
If set to True, Python files without a utf-8 header (like # -*- coding: utf-8 -*-) will cause a warning. Default is False.
If set to True, any file containing trailing spaces or tabs anywhere on the lines will cause a warning. Default is False.
If set to True, Python files will be scanned searching for strings quoted with double quote signs ("). Default is False.
If set to True, Python files will be scanned searching for old-style string formatting (i.e. '%s' % var). See PEP 3101. Default is False.
If set to True, checks that imports in Python files follow plone.api conventions. Default is False.
If set to True, scan Python files looking for debug-like statements. Default is False.
If set to True, the code-analysis script returns an error code that Continuous Integration servers (like Travis CI) can use to fail or pass a job, based on the code analyis output. Note that Jenkins usually does not need this option (this is better handled by the Jenkins Violations plugin).

Known Issues

JSHint "ERROR: Unknown option --verbose":

JSHint                [ OK ]
ERROR: Unknown option --verbose

Upgrade JSHint to latest version (>= 1.0) to fix this issue, e.g.:

$ sudo npm install -g jshint

Example usage

Minimal buildout:

>>> write('buildout.cfg',
... """
... [buildout]
... parts = code-analysis
... [code-analysis]
... recipe = plone.recipe.codeanalysis
... directory = %(directory)s
... """ % {
...     'directory' : '${buildout:directory}/plone/recipe/codeanalysis',
... })

Running the buildout gives us a 'code-analysis' script that runs the entire code analysis:

>>> buildout_output_lower = system(buildout).lower()
>>> '/sample-buildout/bin/code-analysis' in buildout_output_lower

It is also possible to run single code analysis scripts:

>>> '/sample-buildout/bin/code-analysis-flake8' in buildout_output_lower
>>> '/sample-buildout/bin/code-analysis-jshint' in buildout_output_lower

Flake 8 and ZPTLint are installed by the buildout script, there is no need to install them on the system:

>>> '/sample-buildout/bin/flake8' in buildout_output_lower

>>> '/sample-buildout/bin/zptlint' in buildout_output_lower

Deprecate method analysis script is installed:

>>> '/sample-buildout/bin/code-analysis-deprecated-methods' in buildout_output_lower

The script to check if python files have an utf-8 encoding header is installed:

>>> '/sample-buildout/bin/code-analysis-utf8-header' in buildout_output_lower

The script to warn about trailing spaces or tabs on files is installed:

>>> '/sample-buildout/bin/code-analysis-clean-lines' in buildout_output_lower

Double quotes checker script is installed:

>>> '/sample-buildout/bin/code-analysis-prefer-single-quotes' in buildout_output_lower

The script to check for old style string formatting is installed:

>>> '/sample-buildout/bin/code-analysis-string-formatting' in buildout_output_lower

The script to check for plone.api style imports is installed:

>>> '/sample-buildout/bin/code-analysis-imports' in buildout_output_lower

The script to check for debug-like statements in python code is installed:

>>> '/sample-buildout/bin/code-analysis-debug-statements' in buildout_output_lower

By default a git pre-commit hook is installed. Though, this does not work if the current directory is not a git repository:

>>> 'unable to create git pre-commit hook, this does not seem to be a git repository' in buildout_output_lower

If we have a git repository:

>>> import subprocess
>>> subprocess.call(['mkdir', '-p', '.git/hooks'])

And run buildout again:

>>> buildout_output_lower = system(buildout).lower()

Then the git pre-commit hook has been installed:

>>> 'install git pre-commit hook.' in buildout_output_lower
  • Timo Stollenwerk, Original Author
  • Gil Forcada
  • Héctor Velarde
Change history
1.0b3 (2013-09-12)
  • Add return-status-codes option that allows to fail a CI-build on Travis. [timo]
  • Make system wide installed csslint the default value for the csslint-bin option. [timo]
1.0b2 (2013-09-11)
  • Deprecate 'csslint-quiet', 'csslint-ignore' and 'csslint-exclude-list' options; CSS Lint must be configured now using a '.csslintrc' file. 'csslint-bin' option now defaults to bin/csslint; documentation was updated (closes #20). [hvelarde]
  • Implement removal of pre-commit hook (fixes #21). [hvelarde]
1.0b1 (2013-08-12)
  • Workaround over JSHint limitations to avoid displaying warning messages as errors (closes #13). [hvelarde]
  • Fix CSS Lint validation and implement new 'csslint-quiet' option. [hvelarde]
  • Fix package distribution. [hvelarde]
1.0a1 (2013-08-04)
  • Initial release. [timo]

Subscribe to package updates

Last updated Jan 9th, 2014

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.