Coder Social home page Coder Social logo

Comments (10)

arcivanov avatar arcivanov commented on May 25, 2024

I have no idea what you're talking about, sorry πŸ˜„

from pybuilder.

nskmda avatar nskmda commented on May 25, 2024

Hmm.
The SonarQube plugin is one of the core plugins, right?
I know, I might struggle to word my questions clearly.
Let me try again.

  1. SonarQube is a protected resource (at least at my company). So, there are credentials needed to connect to it to publish code coverage and code scan results. Even if an external application is used for that. One of the credentials used (and I'm using it all the time at work) is 'authentication token' (it's just some long value). If it's not used (as per the plugin's code) then some other authentication information should be provided to the sonar-scanner, right?
  2. I feel like there's a typo in the documentation. Instead of 'sonar-scanner' it says 'sonar-runner'. That what made me confused. But okay, the code references correct app (from the SQ site's downloads). I guess I need to make it available in the PATH so that plugin would run the command w/o path (though I would appreciate if the full path to the sonar-scanner was exposed as a plugin parameter).

One side note. I see you are building the command to run that 'scanner'. But you don't expose an attribute to point to the code coverage report file. This somewhat limits the applicability of the plugin, because w/o knowledge of the code nobody knows where the coverage report is expected to be located/placed.

from pybuilder.

arcivanov avatar arcivanov commented on May 25, 2024

SonarQube is one of the plugins yes, but I haven't heard of anybody using it and you're the first person to ask about it in years.
I think I've interacted with it in early 2010s in Java context but that's about it.
As far as the current plugin it invokes sonar-scanner.
From the sonar-scanner documentation, the environmental variable can be set to authenticate using token: https://docs.sonarsource.com/sonarqube/latest/user-guide/user-account/generating-and-using-tokens/#using-a-token

from pybuilder.

arcivanov avatar arcivanov commented on May 25, 2024

One side note. I see you are building the command to run that 'scanner'. But you don't expose an attribute to point to the code coverage report file. This somewhat limits the applicability of the plugin, because w/o knowledge of the code nobody knows where the coverage report is expected to be located/placed.

Yeah we do:
https://github.com/pybuilder/pybuilder/blob/master/src/main/python/pybuilder/plugins/python/sonarqube_plugin.py#L65

from pybuilder.

nskmda avatar nskmda commented on May 25, 2024

How can I add the path of the executable I downloaded so that your plugin actually discovers the scanner?
I tried a naΓ―ve

    if not os.environ['PATH'].endswith(scannerPath):
        os.environ['PATH'] += os.pathsep + scannerPath

in the analyze task (which seems to b called b4 the SQ plugin's run_sonar_analysis) but was still getting the Missing prerequisite sonar-scanner...

because if i sun the scanner from command line w/scannerPath prefixed (like some/path/to/scanner/sonar-scanner) then everything works as expected.
I'm just confused how to make sure the OS PATH var (which I update in my task) is used by PyBuilder plugin.

from pybuilder.

arcivanov avatar arcivanov commented on May 25, 2024

Set your environment outside the PyBuilder. It's why it's called "the environment".

from pybuilder.

nskmda avatar nskmda commented on May 25, 2024

You mean, the external process you call from the plugin disregards any PATH manipulations in the Python code?

from pybuilder.

arcivanov avatar arcivanov commented on May 25, 2024

No, I mean PATH=/path/to/scanner:$PATH pyb -vX. Please google "using environmental variables".

Listen, I don't mean to be unfriendly, but this isn't "how do I learn programming" forum or a PyB support forum.
Please limit the issues to reporting actual purported product failures, attaching error logs, steps to reproduce and the description of the environment where the issue reproduces.

Otherwise I can offer you a consulting price list with hourly billable in 1 hour increments per incident.

from pybuilder.

nskmda avatar nskmda commented on May 25, 2024

@arcivanov That's totally fine. Apologies for sounding like I was asking for programming help.
In fact, I do know about the env vars etc. Tho, yes I'm relatively new to the Python world (and might not understand how everything works compared to much travelled Java world).

If you don't mind, I can open another discussion (still have a question about how you guys implement executing external processes from plugins).
My only issue w/that was there were almost no responses to the discussions.

from pybuilder.

Famondir avatar Famondir commented on May 25, 2024

All right. As a novice it took me a while to get everything running. I'ld appreciate if there would have been minimal working examples or tutorials on how to use every plugin. (I struggled with SonarQube and pytest.) Here is what I've done for SonarCube:

Assuming you are following the PyBuilder Tutorial you will have a virtual Python environment. (First learning: It's not a virtual environment specific for Linux but from Python and thus will work on Windows as well.)

You should add these two lines to the venv/bin/activate file (replace the path and token):

export SONAR_TOKEN=YOUR_TOKEN_HERE
export PATH="/home/simon/Dokumente/data_science/1st_semester/software_engineering/sonar-scanner-5.0.1.3006-linux/bin:$PATH"

This adds the required environment variables to the virtual environment every time you source it.

Then you should add the uncommented line to you build.py to the set_poperties. Replace the :

@init
def set_properties(project):
    project.set_property("sonarqube_project_key", "musicsuitmusicsuite:2024e")
    # project.set_property("sonarqube_project_name", "Music Suite")

This should do the trick as far as I can reconstruct my steps and filter out the important parts.

I'm running the analysis with pyb run_sonar_analysis. What is a little bit odd here is that SonarCube always states that the code passes even though test coverage is not met. Seems like the communication about the aimed for threshold is not working. You have to look at the output in your terminal therefore.

If you are using pytest instead of unittest you will want to add the following lines so the test coverage is shown correctly in SonarCube:

@init
def set_properties(project):
    project.set_property("sonarqube_project_key", "musicsuitmusicsuite:2024e")
    # project.set_property("sonarqube_project_name", "Music Suite")

    project.set_property("pytest_coverage_xml", True)

And at sonar-project.properties (set the path to test coverage file from pytest):

# must be unique in a given SonarQube instance
sonar.projectKey=musicsuite_2024
sonar.python.coverage.reportPaths=target/reports/pytest_coverage.xml

from pybuilder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.