python-sonarqube is a sample Python application that demonstrates how to integrate SonarQube for continuous code quality inspection. SonarQube is an open-source platform used to analyze and measure code quality and provide continuous code inspection.
python-sonarqube/
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── utils.py
├── tests/
│ ├── __init__.py
│ ├── test_main.py
│ ├── test_utils.py
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── sonar-project.properties
├── run_tests.sh
├── README.md
- Docker
- Python 3.x
pylint,pytest,pytest-cov, andrequestslibraries
-
Clone the repository:
git clone https://github.com/yourusername/python-sonarqube.git cd python-sonarqube -
Set up the Docker container:
docker-compose up -d
-
Install Python dependencies:
pip install -r requirements.txt
-
Run the application:
docker build -t python-app . docker run -it --rm python-app -
Run tests and generate coverage report:
./run_tests.sh
-
Analyze code with SonarQube:
- Open a browser and go to
http://localhost:9000 - Log in with the default credentials (
admin/admin) - Create a new project and obtain the project key and token
- Add the project key to
sonar-project.properties - Run the following command to analyze the project:
sonar-scanner -Dsonar.projectKey=PythonAppWithSonarQube -Dsonar.sources=./app -Dsonar.host.url=http://localhost:9000 -Dsonar.login=<your_token>
- Open a browser and go to
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a pull request.
For any questions or suggestions, please open an issue or contact the project maintainer.