Skip to content

Commit a56c6ef

Browse files
authored
Toml-config (#1983)
* Move sonar-tools in subdir * Define toml file * Build with poetry * Remove old backup toml file * Create poetry lock file * Update dependecies with versions * Remove obsolete requirements.txt * Us epoetry to run tests * Update files in image with poetry * Add test for sonar-tools-help * Bump dependencies * Downgrade dependency for compatibility python 3.9 * formatting * Remove ruff python upgrade issues * Adjust to new ruff format * Remove deprecated sonar.login for new versions of SonarQube * Fix bug due to typo * Build on Windows * Tune ruff config * Add ruff formatting * Remove black
1 parent 1e412f8 commit a56c6ef

File tree

13 files changed

+1938
-117
lines changed

13 files changed

+1938
-117
lines changed

sonar-tools renamed to cli/sonar_tools.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424
from sonar import version
2525

26-
print(f'''
26+
27+
def main() -> None:
28+
"""Main entry point for sonar-tools"""
29+
print(
30+
f"""
2731
sonar-tools version {version.PACKAGE_VERSION}
2832
(c) Olivier Korach 2019-2025
2933
Collections of utilities for SonarQube Server and Cloud:
@@ -38,8 +42,13 @@
3842
- sonar-findings-sync: Synchronizes issues between 2 branches of a same project, a whole project
3943
branches of 2 different projects (potentially on different platforms).
4044
(also available as sonar-issues-sync for backward compatibility, but deprecated)
41-
- sonar-projects: Exports / Imports projects to/from zip file (Import works for EE and higher)
42-
- sonar-config: Exports and imports an entire (or subsets of a) SonarQube Server or Cloud platform configuration as code (JSON)
45+
- sonar-projects: Exports or imports projects to/from zip file (Import works for SonarQube Server EE and higher)
46+
- sonar-config: Exports or imports an entire (or subsets of a) SonarQube Server or Cloud platform configuration as code (JSON)
4347
- sonar-rules: Exports Sonar rules
4448
See tools built-in -h help and https://github.com/okorach/sonar-tools for more documentation
45-
''')
49+
"""
50+
)
51+
52+
53+
if __name__ == "__main__":
54+
main()

conf/build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ while [ $# -ne 0 ]; do
3838
done
3939

4040
echo "======= FORMATTING CODE ========="
41-
black --line-length=150 .
41+
ruff format
4242
echo "======= BUILDING PACKAGE ========="
4343
rm -rf "$ROOTDIR/build/lib/sonar" "$ROOTDIR/build/lib/cli" "$ROOTDIR"/build/scripts*/sonar-tools "$ROOTDIR"/dist/sonar_tools*
44-
python -m build
44+
# python -m build
45+
poetry build
4546

4647
if [ "$build_docs" == "1" ]; then
4748
echo "======= BUILDING DOCS ========="

conf/deploy.bat

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
:: build_docs=1
2222
:: release=0
2323

24-
black --line-length=150 .
24+
ruff format
25+
if %errorlevel% neq 0 exit /b %errorlevel%
26+
2527
rmdir /S /Q build
2628
rmdir /S /Q dist
27-
python setup.py bdist_wheel
29+
poetry build
30+
if %errorlevel% neq 0 exit /b %errorlevel%
2831

2932
:: Deploy locally for tests
3033
pip install pip install --no-deps --force-reinstall dist\*-py3-*.whl

conf/release.Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
2222
WORKDIR /opt/sonar-tools
2323

2424
COPY ./sonar sonar
25-
COPY ./requirements.txt .
2625
COPY ./cli cli
27-
COPY ./setup.py .
28-
COPY ./sonar-tools .
2926
COPY ./README.md .
3027
COPY ./LICENSE .
3128
COPY ./sonar/audit sonar/audit
@@ -36,6 +33,6 @@ RUN pip install --upgrade pip \
3633
USER ${USERNAME}
3734
WORKDIR /home/${USERNAME}
3835

39-
HEALTHCHECK --interval=180s --timeout=5s CMD [ "sonar-tools" ]
36+
HEALTHCHECK --interval=180s --timeout=5s CMD [ "sonar-tools-help" ]
4037

41-
CMD [ "sonar-tools" ]
38+
CMD [ "sonar-tools-help" ]

conf/ruff2sonar.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,22 @@ def main() -> None:
4343
while i < nblines:
4444
line = lines[i]
4545
i += 1
46-
# Search for pattern like "F401 [*] `sys` imported but unused"
47-
if not (m := re.match(r"^([A-Za-z0-9]+) (\[\*\]) (.+)$", line)):
48-
continue
49-
rule_id = m.group(1)
50-
message = m.group(3)
51-
line = lines[i]
52-
i += 1
53-
# Search for pattern like " --> cli/cust_measures.py:28:8"
54-
if not (m := re.match(r"^\s*--> ([^:]+):(\d+):(\d+)$", line)):
46+
# Search for pattern like "sonar/projects.py:196:13: B904 Within an `except` clause, raise exceptions"
47+
if not (m := re.match(r"^([^:]+):(\d+):(\d+): ([A-Z0-9]+)( \[\*\])? (.+)$", line)):
5548
continue
5649
file_path = m.group(1)
5750
line_no = int(m.group(2))
51+
start_col = int(m.group(3)) - 1
52+
end_col = start_col + 1
53+
rule_id = m.group(4)
54+
message = m.group(6)
55+
i += 1
5856

5957
# Search for " | ^^^" pattern"
60-
while i < nblines and not (m := re.match(r"^\s*\|\s(\s*)(\^+)", lines[i])):
58+
while i < nblines and not re.match(r"^$", lines[i]):
59+
if m := re.match(r"\s*\|\s(\s*)(\^+)", lines[i]):
60+
end_col = start_col + len(m.group(2))
6161
i += 1
62-
if not m:
63-
continue
64-
start_col = len(m.group(1))
65-
end_col = start_col + len(m.group(2))
6662

6763
sonar_issue = {
6864
"ruleId": f"{TOOLNAME}:{rule_id}",

conf/run_tests.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ do
4040
sonar start -i $target && sleep 30
4141
fi
4242
if [ -d "$ROOTDIR/$GEN_LOC/$target/" ]; then
43-
coverage run --branch --source="$ROOTDIR" -m pytest "$ROOTDIR/$GEN_LOC/$target/" --junit-xml="$buildDir/xunit-results-$target.xml"
44-
coverage xml -o "$buildDir/coverage-$target.xml"
45-
fi
46-
if [ "$target" != "latest" ] && [ "$target" != "common" ]; then
47-
sonar stop -i $target
43+
poetry run coverage run --branch --source="$ROOTDIR" -m pytest "$ROOTDIR/$GEN_LOC/$target/" --junit-xml="$buildDir/xunit-results-$target.xml"
44+
poetry run coverage xml -o "$buildDir/coverage-$target.xml"
4845
fi
4946
done

conf/scan.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ fi
7070

7171
version=$(grep PACKAGE_VERSION "$ROOTDIR/sonar/version.py" | cut -d "=" -f 2 | sed -e "s/[\'\" ]//g" -e "s/^ +//" -e "s/ +$//")
7272

73+
7374
cmd="sonar-scanner -Dsonar.projectVersion=$version \
7475
-Dsonar.python.flake8.reportPaths=$flake8Report \
7576
-Dsonar.python.pylint.reportPaths=$pylintReport \
76-
-Dsonar.login=$SONAR_TOKEN \
7777
-Dsonar.token=$SONAR_TOKEN \
7878
"${scanOpts[*]}""
7979

80+
if [ "$SONAR_HOST_URL" == "$SONAR_HOST_URL_9" ]; then
81+
cmd="$cmd -Dsonar.login=$SONAR_TOKEN"
82+
fi
83+
8084
if ls $buildDir/coverage*.xml >/dev/null 2>&1; then
8185
cmd="$cmd -Dsonar.python.coverage.reportPaths=$buildDir/coverage*.xml"
8286
else

conf/snapshot.Dockerfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,21 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
2222
WORKDIR /opt/sonar-tools
2323

2424
COPY ./sonar sonar
25-
COPY ./requirements.txt .
25+
COPY ./pyproject.toml .
2626
COPY ./cli cli
27-
COPY ./setup.py .
28-
COPY ./sonar-tools .
2927
COPY ./README.md .
3028
COPY ./LICENSE .
3129
COPY ./sonar/audit sonar/audit
3230

3331
RUN pip install --upgrade pip \
34-
&& pip install --no-cache-dir -r requirements.txt \
35-
&& pip install --no-cache-dir --upgrade pip setuptools wheel \
36-
&& python setup.py bdist_wheel \
32+
&& pip install --no-cache-dir poetry \
33+
&& poetry install \
34+
&& poetry build \
3735
&& pip install dist/sonar_tools-*-py3-*.whl --force-reinstall
3836

3937
USER ${USERNAME}
4038
WORKDIR /home/${USERNAME}
4139

42-
HEALTHCHECK --interval=180s --timeout=5s CMD [ "sonar-tools" ]
40+
HEALTHCHECK --interval=180s --timeout=5s CMD [ "sonar-tools-help" ]
4341

44-
CMD [ "sonar-tools" ]
42+
CMD [ "sonar-tools-help" ]

migration/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ while [ $# -ne 0 ]; do
4343
shift
4444
done
4545

46-
black --line-length=150 .
46+
ruff format
4747
rm -rf "$ROOTDIR/build/lib/migration" "$ROOTDIR/build/lib/cli" "$ROOTDIR/build/lib/sonar" "$ROOTDIR"/build/scripts*/sonar_migration "$ROOTDIR"/dist/sonar_migration*
4848
python3 "$ROOTDIR/setup_migration.py" bdist_wheel
4949

0 commit comments

Comments
 (0)