Skip to content

Commit d145c5c

Browse files
authored
Misc minor improvements and fixes
* Fix bug * Fix bug * Fix TD * Fix bug due to refactoring * Disable rule R0913 covered by ruff * Fix type hint * Tune ruff analysis to not report type hints in python 3.10+ format * Fix * Quality pass * Fix issue changelog count * Remove unused import * Add release date test * Formatting * fix exit code of sonar-tools-help * Fix minimum version * Fix migration build with toml file * Add migration in package * Fix pack (migration vs cli) * Adjust issue counts after intro of ruff * Fix sync export test * Fix tests * Fix tests * Fix test now that no warning on sonar-tools
1 parent c8adc75 commit d145c5c

19 files changed

+267
-70
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ deletes tokens created since more than a certain number of days
3939
- [Release notes](https://github.com/okorach/sonar-tools/releases)
4040

4141
# Requirements and Installation
42-
- `sonar-tools` requires python 3.8 or higher
42+
- `sonar-tools` requires python 3.9 or higher
4343
- Installation is based on [pip](https://pypi.org/project/pip/).
4444
- Online installation.
4545
- Run: `python3 -m pip install sonar-tools` (or `python3 -m pip upgrade sonar-tools`)

cli/sonar_tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
"""Main entry point for sonar-tools"""
2323

24-
from sonar import version
24+
from sonar import version, utilities, errcodes
2525

2626

2727
def main() -> None:
@@ -48,6 +48,7 @@ def main() -> None:
4848
See tools built-in -h help and https://github.com/okorach/sonar-tools for more documentation
4949
"""
5050
)
51+
utilities.final_exit(errcodes.OK)
5152

5253

5354
if __name__ == "__main__":

conf/prep_all_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_TEST:?}" "${SONAR_T
4545
create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_LATEST:?}" "${SONAR_TOKEN_LATEST_ADMIN_USER}" "${SONAR_TOKEN_LATEST_ADMIN_ANALYSIS}"
4646
create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_CB:?}" "${SONAR_TOKEN_CB_ADMIN_USER}" "${SONAR_TOKEN_CB_ADMIN_ANALYSIS}"
4747
create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_9:?}" "${SONAR_TOKEN_9_ADMIN_USER}" "${SONAR_TOKEN_9_ADMIN_ANALYSIS}"
48-
create_fresh_project "${SYNC_PROJECT_KEY}" "https://sonarcloud.io" "${SONAR_TOKEN_SONARCLOUD" "${SONAR_TOKEN_SONARCLOUD"
48+
create_fresh_project "${SYNC_PROJECT_KEY}" "https://sonarcloud.io" "${SONAR_TOKEN_SONARCLOUD}" "${SONAR_TOKEN_SONARCLOUD}"
4949
create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_CB:?}" "${SONAR_TOKEN_CB_ADMIN_USER}" "${SONAR_TOKEN_CB_ADMIN_ANALYSIS}"
5050

5151
for pr in 5 7; do

conf/pylintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ disable=raw-checker-failed,
9191
R0205,
9292
W0107,
9393
R1721,
94-
R1711
94+
R1711,
95+
R0913
96+
9597

9698

9799
# Enable the message, report, category or checker with the given id(s). You can

migration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Command line tool to collect SonarQube data to prepare eventual migration to Son
1818

1919

2020
# Requirements and Installation
21-
- `sonar-migration` requires python 3.8 or higher
21+
- `sonar-migration` requires python 3.9 or higher
2222
- Installation is based on [pip](https://pypi.org/project/pip/).
2323
- Online installation.
2424
- Run: `python3 -m pip install sonar-migration` (or `python3 -m pip upgrade sonar-migration`)

migration/deploy.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CONFDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2525

2626
build_image=1
2727
release=0
28+
release_docker=0
2829

2930
while [[ $# -ne 0 ]]; do
3031
case "${1}" in
@@ -43,9 +44,12 @@ while [[ $# -ne 0 ]]; do
4344
shift
4445
done
4546

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*
48-
python3 "${ROOTDIR}/setup_migration.py" bdist_wheel
48+
mv "${ROOTDIR}/pyproject.toml" "${ROOTDIR}/pyproject.toml.sonar-tools"
49+
cp "${ROOTDIR}/migration/pyproject.toml" "${ROOTDIR}"
50+
poetry build
51+
mv "${ROOTDIR}/pyproject.toml.sonar-tools" "${ROOTDIR}/pyproject.toml"
52+
4953

5054
# Deploy locally for tests
5155
pip install --upgrade --force-reinstall "${ROOTDIR}"/dist/sonar_migration-*-py3-*.whl
@@ -63,7 +67,7 @@ if [[ "${release}" = "1" ]]; then
6367
fi
6468
fi
6569

66-
if [[ "${release}_docker" = "1" ]]; then
70+
if [[ "${release_docker}" = "1" ]]; then
6771
docker buildx build --push --platform linux/amd64,linux/arm64 -t olivierkorach/sonar-migration:0.4 -t olivierkorach/sonar-migration:latest -f migration/release.Dockerfile "${ROOTDIR}"
6872
cd "${CONFDIR}" && docker pushrm olivierkorach/sonar-migration
6973
fi

migration/pyproject.toml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
[project]
2+
name = "sonar-migration"
3+
version = "0.6"
4+
description = "A tool for SonarQube Server to Cloud migration assistance"
5+
authors = [
6+
{name = "Olivier Korach", email = "[email protected]"},
7+
]
8+
maintainers = [
9+
{name = "Olivier Korach", email = "[email protected]"},
10+
]
11+
12+
license = "LGPL-3.0-only"
13+
14+
license-files = ["LICEN[CS]E*"]
15+
16+
keywords = ["sonarqube", "sonar", "migration", "administration", "automation"]
17+
18+
readme = "README.md"
19+
requires-python = ">= 3.9"
20+
dependencies = [
21+
"argparse",
22+
"datetime",
23+
"python-dateutil (>=2.9.0)",
24+
"requests (>=2.32)",
25+
"jprops (>=2.0.2)",
26+
"levenshtein (>=0.27.1)",
27+
"PyYAML (>=6.0.2)",
28+
]
29+
30+
classifiers = [
31+
"Development Status :: 5 - Production/Stable",
32+
# Indicate who your project is intended for
33+
"Intended Audience :: Developers",
34+
"Topic :: Code Quality :: Utility Tools",
35+
# Specify the Python versions you support here.
36+
"Programming Language :: Python :: 3",
37+
"Programming Language :: Python :: 3.8",
38+
"Programming Language :: Python :: 3.9",
39+
"Programming Language :: Python :: 3.10",
40+
"Programming Language :: Python :: 3.11",
41+
"Programming Language :: Python :: 3.12",
42+
"Programming Language :: Python :: 3.13",
43+
]
44+
45+
[project.urls]
46+
Homepage = "https://pypi.org/sonar-migration"
47+
Documentation = "https://github.com/okorach/migration/README.md"
48+
Repository = "https://github.com/okorach/sonar-tools.git"
49+
Issues = "https://github.com/okorach/sonar-tools/issues"
50+
Changelog = "https://github.com/okorach/sonar-tools/blob/master/doc/what-is-new.md"
51+
52+
[project.scripts]
53+
sonar-migration = "migration.migration:main"
54+
55+
[build-system]
56+
build-backend = "poetry.core.masonry.api"
57+
requires = [
58+
"poetry-core>=2.0.0,<3.0.0",
59+
"wheel",
60+
"sphinx>=7.4.7",
61+
"sphinx_rtd_theme>=3.0.2",
62+
"sphinx-autodoc-typehints>=2.2.3",
63+
"twine",
64+
"get_pypi_latest_version",
65+
]
66+
67+
[tool.poetry]
68+
packages = [{include = "sonar"}, {include = "migration"}]
69+
70+
[dependency-groups]
71+
test = [
72+
"pytest (>=8.1.1)",
73+
"coverage (>=7.4.4)",
74+
]
75+
lint = [
76+
"ruff (>=0.5.2)",
77+
"pylint (>=3.1.0)",
78+
"flake8 (>=7.0.0)",
79+
]
80+
docs = [
81+
"sphinx (>=7.3.7)",
82+
"sphinx-autodoc-typehints (>=2.1.0)",
83+
"sphinx-rtd-theme (>=2.0.0)",
84+
]
85+
dev = [
86+
{ include-group = "test" },
87+
{ include-group = "lint" },
88+
{ include-group = "docs" },
89+
]
90+
91+
[tool.ruff]
92+
93+
# Set the maximum line length to 150.
94+
line-length = 150
95+
target-version = "py39"
96+
indent-width = 4
97+
98+
[tool.ruff.format]
99+
# Like Black, use double quotes for strings.
100+
quote-style = "double"
101+
# Like Black, indent with spaces, rather than tabs.
102+
indent-style = "space"
103+
# Like Black, respect magic trailing commas.
104+
skip-magic-trailing-comma = false
105+
# Like Black, automatically detect the appropriate line ending.
106+
line-ending = "auto"
107+
# Enable auto-formatting of code examples in docstrings. Markdown,
108+
# reStructuredText code/literal blocks and doctests are all supported.
109+
#
110+
# This is currently disabled by default, but it is planned for this
111+
# to be opt-out in the future.
112+
docstring-code-format = true
113+
114+
# Set the line length limit used when formatting code snippets in
115+
# docstrings.
116+
#
117+
# This only has an effect when the `docstring-code-format` setting is
118+
# enabled.
119+
docstring-code-line-length = "dynamic"
120+
121+
122+
[tool.ruff.lint]
123+
# Add the `line-too-long` rule to the enforced rule set. By default, Ruff omits rules that
124+
# overlap with the use of a formatter, like Black, but we can override this behavior by
125+
# explicitly adding the rule.
126+
# extend-select = ["E501"]
127+
# select = [
128+
# # pycodestyle
129+
# "E",
130+
# # Pyflakes
131+
# "F",
132+
# # pyupgrade
133+
# # "UP",
134+
# # flake8-bugbear
135+
# "B",
136+
# # flake8-simplify
137+
# "SIM",
138+
# # isort
139+
# "I",
140+
#]
141+
select = [ "ALL" ]
142+
extend-ignore = [
143+
"D403",
144+
"D415",
145+
"D400",
146+
"FBT002",
147+
"FBT001",
148+
"PTH123", # `open()` should be replaced by `Path.open()`
149+
"ISC001",
150+
"COM812", # Missing trailing comma in a dictionary or set literal
151+
"D211",
152+
"D213",
153+
"D203",
154+
"D401",
155+
"ERA001",
156+
"S101",
157+
"I001",
158+
"TRY003",
159+
"EM102",
160+
]
161+
162+
exclude = [
163+
".eggs",
164+
".git",
165+
".mypy_cache",
166+
".pyenv",
167+
".pytest_cache",
168+
".ruff_cache",
169+
".svn",
170+
".tox",
171+
".venv",
172+
".vscode",
173+
"__pypackages__",
174+
"_build",
175+
"build",
176+
"dist",
177+
"node_modules",
178+
"site-packages"
179+
]
180+
181+
[tool.ruff.lint.pyupgrade]
182+
# Preserve types, even if a file imports `from __future__ import annotations`.
183+
keep-runtime-typing = true

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ requires = [
8080
]
8181

8282
[tool.poetry]
83-
packages = [{include = "sonar"}, {include = "cli"}]
83+
packages = [{include = "sonar"}, {include = "migration"}, {include = "cli"}]
8484

8585
[dependency-groups]
8686
test = [
@@ -193,3 +193,6 @@ exclude = [
193193
"site-packages"
194194
]
195195

196+
[tool.ruff.lint.pyupgrade]
197+
# Preserve types, even if a file imports `from __future__ import annotations`.
198+
keep-runtime-typing = true

sonar/components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def set_visibility(self, visibility: str) -> None:
250250
def get_analyses(self, filter_in: Optional[list[str]] = None, filter_out: Optional[list[str]] = None) -> types.ApiPayload:
251251
"""Returns a component analyses"""
252252
params = utilities.dict_remap(self.api_params(c.READ), {"component": "project"})
253-
data = self.endpoint.get_paginated("project_analyses/search", return_field="analyses", params=params)["analyses"]
253+
data = self.endpoint.get_paginated("project_analyses/search", return_field="analyses", **params)["analyses"]
254254
if filter_in and len(filter_in) > 0:
255255
data = [d for d in data if any(e["category"] in filter_in for e in d["events"])]
256256
if filter_out and len(filter_out) > 0:

sonar/groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def members(self, use_cache: bool = True) -> list[users.User]:
203203
data = json.loads(self.get(MEMBERSHIP_API, params={"groupId": self.id}).text)
204204
self.__members = [users.User.get_object_by_id(self.endpoint, d["userId"]) for d in data["groupMemberships"]]
205205
else:
206-
data = self.endpoint.get_paginated("api/user_groups/users", return_field="users", params={"name": self.name})
206+
data = self.endpoint.get_paginated("api/user_groups/users", return_field="users", name=self.name)
207207
self.__members = [users.User.get_object(self.endpoint, d["login"]) for d in data["users"]]
208208
return self.__members
209209

0 commit comments

Comments
 (0)