Sunday, September 22, 2013

SonarQube to analyze python code on mac

SonarQube is an open platform to manage code quality. As such, it covers the 7 axes of code quality:
- architecture & design
- duplications
- unit tests
- complexity
- potential bugs
- coding rules
- comments


This is the minimum configured way to install SonarQube and start analyzing your python code on your mac (I run 10.8.5 but I think this should work on older os x as well)
Estimated time of completion: 10 min


  1. Install SonarQube (server to host result)
    1. go to http://www.sonarqube.org/downloads/ and click "Download" link and unarchived (I downloaded sonar-3.7)
    2. move unarchived directory to wherever you want to place (I created dir called sonar. so far, i have sonar/sonar-3.7/ and I will reference this dir as SONARQUBE_HOME) 
    3. cd SONARQUBE_HOME/bin/macosx-universal-64
    4. to start server: $ sh sonar.sh start
      1. at this point, if you start server (), you should be able to see interface via browser @ http://localhost:9000/
  2. Install SonarQube Runner (server to host result) 
    1. Download from here (at the time of writing 2.2 is the latest version) and unarchived it
    2. move unarchived directory to wherever you want to place (I moved under sonar I created at step 1. I now have sonar/sonar-runner-2.3/ and I will reference this dir as SONAR_RUNNER_HOME)
    3. Edit SONAR_RUNNER_HOME/conf/sonar-project.properties
      • sonar.projectKey=my:project
      • sonar.projectName=project
      • sonar.projectVersion=1.0
      • sonar.projectDescription=project description
      • sonar.source=path-to-project-dir
      • sonar.language=py
  3.  Install python plugin
    1. Download from here (at the time of writing 1.1 is the latest)
    2. copy downloaded jar file to SONARQUBE_HOME/extensions/plugins/
  4. Restart the SonarQube server
  5. Run SonarQube Runner to analyze
    1. note: I was getting "Java heap space" error. In my case, runner needed 269m. You can solve this by increasing limit and run as follows (example shows to set it to 1g but you can do 512m etc as well): SONAR_RUNNER_OPTS=-Xmx1024m bin/sonar-runner
    2. now you can review your result @ http://localhost:9000/

2 comments: