Running pylint separately from sonar

scanner
python

(Rowan Harrison) #1

I am trying to cut down the build time that Sonar takes, and decided to run pylint before sonar-scanner on a few directories (as it seems that the ignore options in pylint are finicky).
However when I run the sonar scanner with the sonar.python.pylint.reportPath=pylint-report.txt flag, it looks to still run pylint as it take roughly the same amount as time as before. From the docs page this doesn’t look like the default behaviour, and I was wondering if I was doing something incorrectly or if pylint is now being run twice, once by me and once by sonar scanner?

I’m running pylint in the way that sonar suggests in the docs, with the msg-template format, and sonar logs:

INFO: Sensor Python Squid Sensor [python]
INFO: Python test coverage
INFO: Parsing report ‘progs/coverage.xml’
INFO: Sensor Python Squid Sensor [python] (done) | time=8085ms
INFO: Sensor PylintSensor [python]
WARN: Pylint rule ‘C0303’ is unknown in Sonar
INFO: Sensor PylintSensor [python] (done) | time=421818ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=203ms


(Pierre-Yves Nicolas) #2

If the value of sonar.python.pylint.reportPath was taken into account by SonarPython, you should see PylintImportSensor somewhere in the logs.
Either you use a very very old version of SonarPython or you don’t set sonar.python.pylint.reportPath correctly.
What’s the command you run? Do you use a sonar-project.properties file?


(Rowan Harrison) #3

We’re not using a properties file, as we found that while the scanner picks it up, it doesn’t actually use the values specified in it, so we ended up passing in options as flags. We’re using version 3.2.0.1227-linux which we download from https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.2.0.1227-linux.zip

The scanner command we run is

./sonar-scanner/bin/sonar-scanner
-Dsonar.projectKey=X
-Dsonar.organization=X
-Dsonar.projectBaseDir=progs/
-Dsonar.sources=progs/
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.login=$SONAR_KEY
-Dsonar.branch.name=$CI_BRANCH
-Dsonar.python.coverage.reportPath=progs/coverage.xml
-Dsonar.cfamily.build-wrapper-output.bypass=true
-Dsonar.branch.target=${TARGET_BRANCH}
-Dsonar.python.pylint.report_path=./python-report.txt
-Dsonar.exclusions=X


(Pierre-Yves Nicolas) #4

It seems that your command uses sonar.python.pylint.report_path instead of sonar.python.pylint.reportPath.


(Rowan Harrison) #5

Oh dammit, I guess I must have changed it from pylint_config.

Thanks very much for your help.