File tree Expand file tree Collapse file tree 13 files changed +1938
-117
lines changed Expand file tree Collapse file tree 13 files changed +1938
-117
lines changed Original file line number Diff line number Diff line change 2323
2424from sonar import version
2525
26- print (f'''
26+
27+ def main () -> None :
28+ """Main entry point for sonar-tools"""
29+ print (
30+ f"""
2731sonar-tools version { version .PACKAGE_VERSION }
2832(c) Olivier Korach 2019-2025
2933Collections of utilities for SonarQube Server and Cloud:
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
4448See 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 ()
Original file line number Diff line number Diff line change @@ -38,10 +38,11 @@ while [ $# -ne 0 ]; do
3838done
3939
4040echo " ======= FORMATTING CODE ========="
41- black --line-length=150 .
41+ ruff format
4242echo " ======= BUILDING PACKAGE ========="
4343rm -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
4647if [ " $build_docs " == " 1" ]; then
4748 echo " ======= BUILDING DOCS ========="
Original file line number Diff line number Diff line change 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+
2527rmdir /S /Q build
2628rmdir /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
3033pip install pip install --no-deps --force-reinstall dist\*-py3-*.whl
Original file line number Diff line number Diff line change @@ -22,10 +22,7 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
2222WORKDIR /opt/sonar-tools
2323
2424COPY ./sonar sonar
25- COPY ./requirements.txt .
2625COPY ./cli cli
27- COPY ./setup.py .
28- COPY ./sonar-tools .
2926COPY ./README.md .
3027COPY ./LICENSE .
3128COPY ./sonar/audit sonar/audit
@@ -36,6 +33,6 @@ RUN pip install --upgrade pip \
3633USER ${USERNAME}
3734WORKDIR /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 " ]
Original file line number Diff line number Diff 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 } " ,
Original file line number Diff line number Diff line change 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
4946done
Original file line number Diff line number Diff line change 7070
7171version=$( grep PACKAGE_VERSION " $ROOTDIR /sonar/version.py" | cut -d " =" -f 2 | sed -e " s/[\'\" ]//g" -e " s/^ +//" -e " s/ +$//" )
7272
73+
7374cmd=" 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+
8084if ls $buildDir /coverage* .xml > /dev/null 2>&1 ; then
8185 cmd=" $cmd -Dsonar.python.coverage.reportPaths=$buildDir /coverage*.xml"
8286else
Original file line number Diff line number Diff line change @@ -22,23 +22,21 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
2222WORKDIR /opt/sonar-tools
2323
2424COPY ./sonar sonar
25- COPY ./requirements.txt .
25+ COPY ./pyproject.toml .
2626COPY ./cli cli
27- COPY ./setup.py .
28- COPY ./sonar-tools .
2927COPY ./README.md .
3028COPY ./LICENSE .
3129COPY ./sonar/audit sonar/audit
3230
3331RUN 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
3937USER ${USERNAME}
4038WORKDIR /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 " ]
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ while [ $# -ne 0 ]; do
4343 shift
4444done
4545
46- black --line-length=150 .
46+ ruff format
4747rm -rf " $ROOTDIR /build/lib/migration" " $ROOTDIR /build/lib/cli" " $ROOTDIR /build/lib/sonar" " $ROOTDIR " /build/scripts* /sonar_migration " $ROOTDIR " /dist/sonar_migration*
4848python3 " $ROOTDIR /setup_migration.py" bdist_wheel
4949
You can’t perform that action at this time.
0 commit comments