Skip to end of metadata
Go to start of metadata

Live example

Icon

If you want to see a live example of the capabilities of the Python plugin, you can have a look at the analysis of the PyFFI project on Nemo.

Description / Features

This plugin enables the analysis of Python.

Prerequisite

Pylint must be installed to check Pylint coding rules.

Installation

  1. Install the plugin through the Update Center or download it into the SONARQUBE_HOME/extensions/plugins directory
  2. Restart the SonarQube server

Usage

Run an Analysis with the SonarQube Runner (Recommended Method)

To run an analysis of your Python project, use the SonarQube Runner.

A sample project is available on github that can be browsed or downloaded/projects/languages/python/python-sonar-runner.

Run an Analysis with the other Analyzers

Maven and Ant can also be used to launch analysis on Python projects.

Advanced Settings

 

Property

Scope

Example

Description

sonar.python.pylintSystem-wide/usr/local/bin/pylint

Path to the pylint executable to use in pylint analysis. Set to empty to use the default one.

It has to be set on Windows, use either masked backslashes or slashes as path separators; examples: C:\\Python26\\Scripts\\pylint.bat or C:/Python/26/Scripts/pylint.bat

sonar.python.pylint_configProject-wide.pylintrc

Path to the pylint configuration file (relative to project root or absolute) to use in pylint analysis. Set to empty to use the default.

sonar.python.xunit.reportPathProject-widenosetests.xml

Since version 1.1.

Ant pattern describing the path to unit test execution reports, relative to projects root. Leave unset to use the default ("xunit-reports/xunit-result-*.xml"). The reports have to conform to the junitreport XML format.

sonar.python.coverage.reportPathProject-widecoverage.xml

Since version 1.1.

Ant pattern describing the path to coverage reports, relative to projects root. Leave unset to use the default ("coverage-reports/coverage-*.xml"). The reports have to conform to the Cobertura XML format.

sonar.python.coverage.itReportPathProject-wideit-coverage.xml

Since version 1.1.

 Ant pattern describing the path to coverage reports for integration tests, relative to projects root. Leave unset to use the default ("coverage-reports/it-coverage-*.xml"). The reports have to conform to the Cobertura XML format.

Make sure to set up the environment properly (PYTHONPATH etc.) before running the analyzer, if your project requires it.

External report generation

Here is a quick guide how to generate the reports using external tools.

Test execution

nosetests --with-xunit [tests to execute]

To get a more accurate execution time statistics make sure to use nose 1.1.0 or newer.

Coverage

Use Ned Batchelders coverage package like this:

coverage erase
coverage run --branch --sources=<python packages> <program> 
coverage xml -i

Make sure to put all packages to measure into the --source parameter. That ensures that coverage will report zero coverage on all untouched files, as you most probably want to. To make this work, make sure to meet two prerequisites:

  • use coverage => 3.4
  • the packages should be packages, i.e. every directory on the way to the sources should contain an __init__.py file.

Metrics

See Metrics documentation page.

Extending Coding Rules using XPath

New coding rules can be added using XPath. See the related documentation.

To navigate the AST, download the SSLR Python Toolkit.

Change Log

Loading
Key Summary T P
SONARPY-4 update issue management link in pom.xml Improvement Major
SONARPY-27 Deprecate pylint: C0321 "More than one statement on a single line" New Feature Major
SONARPY-9 Rule: Class names should comply with a naming convention New Feature Major
SONARPY-10 Rule: Files should not have too many lines New Feature Major
SONARPY-29 Rule: New-style classes should be used New Feature Major
SONARPY-25 Rule: Docstrings should be defined New Feature Major
SONARPY-20 Rule: Class names should comply with a naming convention New Feature Major
SONARPY-23 Rule: Function names should comply with a naming convention New Feature Major
SONARPY-24 Rule: Method names should comply with a naming convention New Feature Major
SONARPY-32 deprecate pylint:C0301 Improvement Major
SONARPY-33 Pylint failure due to invalid "-i" argument in pylint 1.0.0 and 1.1.0 Bug Major
SONARPY-31 Add missing Pylint rules Improvement Major
SONARPY-34 Allow relative file names in coverage reports Improvement Major
SONARPY-14 Rule: Control flow statements ["if", "for", "while", "switch" and "try"|"IF", "CASE", "DO", "LOOP", "SELECT", "WHILE" and "PROVIDE"] should not be nested too deeply New Feature Major
SONARPY-2 Do not embed Ant as a library for plugin Improvement Major
SONARPY-28 Rule: Parentheses should not be used after control flow statements New Feature Major
SONARPY-11 Rule: [Functions|Methods|Lambdas] should not have too many parameters New Feature Major
SONARPY-17 Rule: Collapsible "if" statements should be merged New Feature Major
SONARPY-19 Rule: "\" should only be used as an escape character outside of raw strings New Feature Major
SONARPY-12 Rule: Nested blocks of code should not be left empty New Feature Major
SONARPY-15 Rule: Comments should not be located at the end of lines of code New Feature Major
SONARPY-36 Update SQALE model for new rules Improvement Major
SONARPY-35 Parse error in list comprehension with literal list Bug Major

 

Loading

Version 1.2 (unreleased) (8 issues)

 

Loading

Version 1.1 (12 issues)

 

Loading

Version 1.0 (26 issues)

Showing 20 out of 26 issues Refresh

 

Loading

Version 0.1 (5 issues)

 

  • No labels