Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Sonar
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<table class="wysiwyg-macro" data-macro-name="unmigrated-inline-wiki-markup" data-macro-parameters="atlassian-macro-output-type=BLOCK" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3VubWlncmF0ZWQtaW5saW5lLXdpa2ktbWFya3VwOmF0bGFzc2lhbi1tYWNyby1vdXRwdXQtdHlwZT1CTE9DS30&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>{iframe:src=http://update.sonarsource.org/plugins/python.html|width=700|height=220|frameborder=0} Your browser does not support iframes. {iframe}</pre></td></tr></table><table class="wysiwyg-macro" data-macro-name="tip" data-macro-parameters="title=Live example" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3RpcDp0aXRsZT1MaXZlIGV4YW1wbGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>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 <a href="http://nemo.sonarsource.org/dashboard/index/pyffi">PyFFI project on Nemo</a>.</p></td></tr></table><h1>Description / Features</h1><p>This plugin enables the analysis of <a href="http://www.python.org/">Python</a> projects.</p><p>It is compatible with the <a href="http://docs.codehaus.org/display/SONAR/Using+Sonar+in+Eclipse">Sonar Eclipse plugin</a> to track violations while coding. I<span>t is also compatible with </span><span>the </span><a href="http://docs.codehaus.org/display/SONAR/Issues+Report+Plugin">Issues Report plugin</a><span> to run pre-commit local analysis.</span></p><h1>Dependencies</h1><p>This plugin has the following dependencies:</p><ul><li><a href="http://pypi.python.org/pypi/pylint">Pylint</a> must be installed to check Pylint coding rules.</li></ul><h1>Installation</h1><ol><li>Install the Python plugin through the <a class="confluence-link" href="/display/SONAR/Update+Center" data-linked-resource-id="185598091" data-linked-resource-type="page" data-linked-resource-default-alias="Update Center" data-base-url="http://docs.codehaus.org">Update Center</a> or download it into the SONAR_HOME/extensions/plugins directory</li><li>Restart the Sonar server</li></ol><h1>Usage</h1><h3>Run a Sonar Analysis with the Sonar Runner (Recommended Way)</h3><p>To launch a Sonar analysis of your Python project, use the <a class="confluence-link" href="/display/SONAR/Analyzing+with+Sonar+Runner" data-linked-resource-id="192872482" data-linked-resource-type="page" data-linked-resource-default-alias="Analyzing with Sonar Runner" data-base-url="http://docs.codehaus.org">Sonar Runner</a>.</p><p>A sample project is available on github that can be <a class="external-link" href="https://github.com/SonarSource/sonar-examples" rel="nofollow">browsed</a> or <a class="external-link" href="https://github.com/SonarSource/sonar-examples/zipball/master" rel="nofollow">downloaded</a>: /projects/languages/python/python-sonar-runner.</p><h3>Run a Sonar Analysis with the other Analyzers</h3><p><a class="confluence-link" href="/display/SONAR/Analyzing+with+Maven" data-linked-resource-id="193888393" data-linked-resource-type="page" data-linked-resource-default-alias="Analyzing with Maven" data-base-url="http://docs.codehaus.org">Maven</a> and <a class="confluence-link" href="/display/SONAR/Analyzing+with+Sonar+Ant+Task" data-linked-resource-id="210174228" data-linked-resource-type="page" data-linked-resource-default-alias="Analyzing with Sonar Ant Task" data-base-url="http://docs.codehaus.org">Ant</a> can also be used to launch analysis on Python projects.</p><h3>Advanced Settings</h3><div><p> </p><table class="confluenceTable"><tbody><tr><th class="confluenceTh"><p>Property</p></th><th colspan="1" class="confluenceTh"><p>Scope</p></th><th class="confluenceTh"><p>Example</p></th><th class="confluenceTh"><p>Description</p></th></tr><tr><td class="confluenceTd">sonar.python.pylint</td><td colspan="1" class="confluenceTd">System-wide</td><td class="confluenceTd">/usr/local/bin/pylint</td><td class="confluenceTd"><p>Path to the pylint executable to use in pylint analysis. Set to empty to use the default one.</p><p>It <strong>has </strong>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</p></td></tr><tr><td class="confluenceTd">sonar.python.pylint_config</td><td colspan="1" class="confluenceTd">Project-wide</td><td class="confluenceTd">.pylintrc</td><td class="confluenceTd"><p>Path to the pylint configuration file (relative to project root or absolute) to use in pylint analysis. Set to empty to use the default.</p></td></tr><tr><td colspan="1" class="confluenceTd"><span>sonar.python.xunit.reportPath</span></td><td colspan="1" class="confluenceTd"><span>Project-wide</span></td><td colspan="1" class="confluenceTd"><span>nosetests.xml</span></td><td colspan="1" class="confluenceTd"><p><span>Since version 1.1.</span></p><p><span>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.</span></p></td></tr><tr><td colspan="1" class="confluenceTd"><span>sonar.python.coverage.reportPath</span></td><td colspan="1" class="confluenceTd"><span>Project-wide</span></td><td colspan="1" class="confluenceTd"><span>coverage.xml</span></td><td colspan="1" class="confluenceTd"><p><span>Since version 1.1.</span></p><p><span>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.</span></p></td></tr><tr><td colspan="1" class="confluenceTd"><span>sonar.python.coverage.itReportPath</span></td><td colspan="1" class="confluenceTd"><span>Project-wide</span></td><td colspan="1" class="confluenceTd"><span>it-coverage.xml</span></td><td colspan="1" class="confluenceTd"><p><span><span>Since version 1.1.</span></span></p><p><span><span> </span>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.</span></p></td></tr></tbody></table><p>Make sure to set up the environment properly (PYTHONPATH etc.) before running the analyzer, if your project requires it.</p><h3>External report generation</h3><p><span>Here is a quick guide how to generate the reports using external tools.</span></p><h4>Test execution</h4><table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>nosetests --with-xunit [tests to execute]</pre></td></tr></table><p>To get a more accurate execution time statistics make sure to use nose 1.1.0 or newer.</p><h4>Coverage</h4><p><span>Use Ned Batchelders coverage package like this:</span></p><table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>coverage erase coverage run --branch --sources=<python packages> <program> coverage xml -i</pre></td></tr></table><p>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:</p><ul><li>use coverage => 3.4</li><li>the packages should be packages, i.e. every directory on the way to the sources should contain an __init__.py file.</li></ul><h1>Metrics</h1><p>See <a class="confluence-link" href="/display/SONAR/Metric+definitions" data-linked-resource-id="230397406" data-linked-resource-type="page" data-linked-resource-default-alias="Metric definitions" data-base-url="http://docs.codehaus.org">Metrics documentation page</a>.</p><h1>Extending Coding Rules using XPath</h1></div><div><div class="syntaxhighlighter nogutter java"><p>New coding rules can be added using XPath. See the related <a class="confluence-link" href="/display/SONAR/Extending+Coding+Rules#ExtendingCodingRules-extendingRulesXPath" data-anchor="extendingRulesXPath" data-linked-resource-id="183205932" data-linked-resource-type="page" data-linked-resource-default-alias="Extending Coding Rules#extendingRulesXPath" data-base-url="http://docs.codehaus.org">documentation</a>.</p><p>To navigate the AST, download the <a href="http://repository.codehaus.org/org/codehaus/sonar-plugins/python/sslr-python-toolkit/1.1/sslr-python-toolkit-1.1.jar">SSLR Python Toolkit</a>.</p><h1>Change Log</h1><p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2ppcmFpc3N1ZXM6YW5vbnltb3VzPXRydWV8dGl0bGU9VmVyc2lvbiAxLjIgKHVucmVsZWFzZWQpfHJlbmRlck1vZGU9c3RhdGljfGNvbHVtbnM9dHlwZTtrZXk7c3VtbWFyeTtwcmlvcml0eTtzdGF0dXN8dXJsPWh0dHA6Ly9qaXJhLmNvZGVoYXVzLm9yZy9zci9qaXJhLmlzc3Vldmlld3M6c2VhcmNocmVxdWVzdC14bWwvdGVtcC9TZWFyY2hSZXF1ZXN0LnhtbD9maXhmb3I9MTg4MjYmcGlkPTExOTExJnNvcnRlci9maWVsZD1wcmlvcml0eSZzb3J0ZXIvb3JkZXI9REVTQyZ0ZW1wTWF4PTEwMDB9&locale=en_GB&version=2" data-macro-name="jiraissues" data-macro-parameters="anonymous=true|columns=type;key;summary;priority;status|renderMode=static|title=Version 1.2 (unreleased)|url=http://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor\=18826&pid\=11911&sorter/field\=priority&sorter/order\=DESC&tempMax\=1000"></p><p> </p><p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2ppcmFpc3N1ZXM6YW5vbnltb3VzPXRydWV8dGl0bGU9VmVyc2lvbiAxLjF8cmVuZGVyTW9kZT1zdGF0aWN8Y29sdW1ucz10eXBlO2tleTtzdW1tYXJ5O3ByaW9yaXR5fHVybD1odHRwOi8vamlyYS5jb2RlaGF1cy5vcmcvc3IvamlyYS5pc3N1ZXZpZXdzOnNlYXJjaHJlcXVlc3QteG1sL3RlbXAvU2VhcmNoUmVxdWVzdC54bWw_Zml4Zm9yPTE4NzE2JnBpZD0xMTkxMSZzb3J0ZXIvZmllbGQ9cHJpb3JpdHkmc29ydGVyL29yZGVyPURFU0MmdGVtcE1heD0xMDAwfQ&locale=en_GB&version=2" data-macro-name="jiraissues" data-macro-parameters="anonymous=true|columns=type;key;summary;priority|renderMode=static|title=Version 1.1|url=http://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor\=18716&pid\=11911&sorter/field\=priority&sorter/order\=DESC&tempMax\=1000"></p><p> </p><p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2ppcmFpc3N1ZXM6YW5vbnltb3VzPXRydWV8dGl0bGU9VmVyc2lvbiAxLjB8cmVuZGVyTW9kZT1zdGF0aWN8Y29sdW1ucz10eXBlO2tleTtzdW1tYXJ5O3ByaW9yaXR5fHVybD1odHRwOi8vamlyYS5jb2RlaGF1cy5vcmcvc3IvamlyYS5pc3N1ZXZpZXdzOnNlYXJjaHJlcXVlc3QteG1sL3RlbXAvU2VhcmNoUmVxdWVzdC54bWw_Zml4Zm9yPTE4NjM2JnBpZD0xMTkxMSZzb3J0ZXIvZmllbGQ9cHJpb3JpdHkmc29ydGVyL29yZGVyPURFU0MmdGVtcE1heD0xMDAwfQ&locale=en_GB&version=2" data-macro-name="jiraissues" data-macro-parameters="anonymous=true|columns=type;key;summary;priority|renderMode=static|title=Version 1.0|url=http://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor\=18636&pid\=11911&sorter/field\=priority&sorter/order\=DESC&tempMax\=1000"></p><p> </p><p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e2ppcmFpc3N1ZXM6YW5vbnltb3VzPXRydWV8dGl0bGU9VmVyc2lvbiAwLjF8cmVuZGVyTW9kZT1zdGF0aWN8Y29sdW1ucz10eXBlO2tleTtzdW1tYXJ5O3ByaW9yaXR5fHVybD1odHRwOi8vamlyYS5jb2RlaGF1cy5vcmcvc3IvamlyYS5pc3N1ZXZpZXdzOnNlYXJjaHJlcXVlc3QteG1sL3RlbXAvU2VhcmNoUmVxdWVzdC54bWw_Zml4Zm9yPTE4MDc4JnBpZD0xMTkxMSZzb3J0ZXIvZmllbGQ9cHJpb3JpdHkmc29ydGVyL29yZGVyPURFU0MmdGVtcE1heD0xMDAwfQ&locale=en_GB&version=2" data-macro-name="jiraissues" data-macro-parameters="anonymous=true|columns=type;key;summary;priority|renderMode=static|title=Version 0.1|url=http://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor\=18078&pid\=11911&sorter/field\=priority&sorter/order\=DESC&tempMax\=1000"></p><p> </p></div></div>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced