|
1 | 1 | # pysonar-scanner |
2 | | -A wrapper around SonarScanner CLI, available on PyPI. |
| 2 | +**DEPRECATION NOTICE:** |
3 | 3 |
|
4 | | -# Disclaimer |
| 4 | +This application is no longer actively maintained and has been deprecated in favor of `pysonar`. `pysonar` offers a more Python-centric experience and support for newer versions of SonarQube. |
5 | 5 |
|
6 | | -This project is currently in beta and APIs are subject to change. |
7 | | -These changes include configuration parameter names. |
| 6 | +**Please migrate to `pysonar` for all future usage.** |
8 | 7 |
|
9 | | -# Requirements |
10 | | - |
11 | | - - SonarQube v9.9 or higher |
12 | | - - Python 3.8 or above |
13 | | - |
14 | | -# Installation |
15 | | - |
16 | | -Install with pip: |
17 | | -``` |
18 | | -pip install pysonar-scanner |
19 | | -``` |
20 | | - |
21 | | -# Usage |
22 | | - |
23 | | -Once installed, the `pysonar-scanner` can be run from the command line to perform an analysis. |
24 | | -It assumes a running SonarQube server or a project configured on SonarCloud. |
25 | | - |
26 | | -## Setting up analysis properties |
27 | | - |
28 | | -In order for the analysis to run, analysis properties need to be defined. |
29 | | -There are multiple ways of providing these properties, described below in descending order of priority: |
30 | | - |
31 | | -* Through CLI arguments to the `pysonar-scanner` command |
32 | | -* Under the `[tool.sonar]` key of the `pyproject.toml` file |
33 | | -* Through common properties extracted from the `pyproject.toml` |
34 | | -* In a dedicated `sonar-project.properties` file |
35 | | -* Through environment variables |
36 | | - |
37 | | -### Through CLI arguments |
38 | | - |
39 | | -Analysis properties can be provided as CLI arguments to the `pysonar-scanner` command. |
40 | | -They follow the same convention as when running the SonarScanner CLI directly |
41 | | -(see [documentation](https://docs.sonarsource.com/sonarqube/9.9/analyzing-source-code/scanners/sonarscanner/#running-from-zip-file)). |
42 | | -This means that analysis properties provided that way should be prepended with `-D`, for instance: |
43 | | - |
44 | | -``` |
45 | | -$ pysonar-scanner -Dsonar.login=myAuthenticationToken |
46 | | -``` |
47 | | - |
48 | | -You can use all the argument allowed by __SonarScanner__. |
49 | | -For more information on __SonarScanner__ please refer to the [SonarScanner documentation](https://docs.sonarsource.com/sonarqube/9.9/analyzing-source-code/scanners/sonarscanner/) |
50 | | - |
51 | | -### With a pyproject.toml file |
52 | | - |
53 | | -Inside a `pyproject.toml`, Sonar analysis properties can be defined under the `tool.sonar` table. |
54 | | - |
55 | | -``` |
56 | | -[tool.sonar] |
57 | | -# must be unique in a given SonarQube/SonarCloud instance |
58 | | -projectKey=my:project |
59 | | -
|
60 | | -# --- optional properties --- |
61 | | -# defaults to project key |
62 | | -#projectName=My project |
63 | | -# defaults to 'not provided' |
64 | | -#projectVersion=1.0 |
65 | | - |
66 | | -# Path is relative to the pyproject.toml file. Defaults to . |
67 | | -#sources=. |
68 | | - |
69 | | -# Encoding of the source code. Default is default system encoding |
70 | | -#sourceEncoding=UTF-8 |
71 | | -``` |
72 | | - |
73 | | -The configuration parameters can be found in the [SonarQube documentation](https://docs.sonarsource.com/sonarqube/9.9/analyzing-source-code/analysis-parameters/). |
74 | | - |
75 | | -In the `pyproject.toml` file the prefix `sonar.` for parameter keys should be omitted. |
76 | | -For example, `sonar.scm.provider` in the documentation will become `scm.provider` in the `pyproject.toml` file. |
77 | | - |
78 | | -By default, the scanner will expect the `pyproject.toml` file to be present in the current directory. |
79 | | -However, its path can be provided manually through the `toml.path` ([PYSCAN-40](https://sonarsource.atlassian.net/jira/software/c/projects/PYSCAN/issues/PYSCAN-40)) CLI argument as well as through the `sonar.projectHome` argument. For instance: |
80 | | - |
81 | | -``` |
82 | | -pysonar-scanner -Dtoml.path="path/to/pyproject.toml" |
83 | | -``` |
84 | | - |
85 | | -Or: |
86 | | - |
87 | | -``` |
88 | | -pysonar-scanner -Dsonar.projectHome="path/to/projectHome" |
89 | | -``` |
90 | | - |
91 | | - |
92 | | -### Through project properties extracted from the `pyproject.toml` |
93 | | - |
94 | | -When a `pyproject.toml` file is available, it is possible to set the `-read-project-config` flag |
95 | | -to allow the scanner to deduce analysis properties from the project configuration. |
96 | | - |
97 | | -This is currently supported only for projects using `poetry`. |
98 | | - |
99 | | -The Sonar scanner will then use the project name and version defined through Poetry, they won't have to be duplicated under a dedicated `tool.sonar` section. |
100 | | - |
101 | | -### With a sonar-project.properties file |
102 | | - |
103 | | -Exactly like [__SonarScanner__](https://docs.sonarsource.com/sonarqube/9.9/analyzing-source-code/scanners/sonarscanner/), |
104 | | -the analysis can also be configured with a `sonar-project.properties` file: |
105 | | - |
106 | | -``` |
107 | | -# must be unique in a given SonarQube/SonarCloud instance |
108 | | -sonar.projectKey=my:project |
109 | | -
|
110 | | -# --- optional properties --- |
111 | | -
|
112 | | -# defaults to project key |
113 | | -#sonar.projectName=My project |
114 | | -# defaults to 'not provided' |
115 | | -#sonar.projectVersion=1.0 |
116 | | - |
117 | | -# Path is relative to the sonar-project.properties file. Defaults to . |
118 | | -#sonar.sources=. |
119 | | - |
120 | | -# Encoding of the source code. Default is default system encoding |
121 | | -#sonar.sourceEncoding=UTF-8 |
122 | | -``` |
123 | | - |
124 | | -### Through environment variables |
125 | | - |
126 | | -It is also possible to define configure the scanner through environment variables: |
127 | | - |
128 | | -``` |
129 | | -$ export SONAR_HOST_URL="http://localhost:9000" |
130 | | -$ pysonar-scanner |
131 | | -``` |
132 | | - |
133 | | -See the __SonarScanner__ [documentation](https://docs.sonarsource.com/sonarqube/9.9/analyzing-source-code/scanners/sonarscanner/) for more information. |
134 | | - |
135 | | -# Installation from testPyPI |
136 | | - |
137 | | -To install the latest pre-released version of Sonar Scanner Python. Execute the following command: |
138 | | - |
139 | | -```shell |
140 | | -pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ pysonar-scanner |
141 | | -``` |
| 8 | +You can install it via pip: |
| 9 | +`pip install pysonar` |
142 | 10 |
|
143 | 11 | # License |
144 | 12 |
|
|
0 commit comments