Skip to content

Commit bdf7577

Browse files
committed
Kill TD
1 parent caedd25 commit bdf7577

File tree

9 files changed

+31
-27
lines changed

9 files changed

+31
-27
lines changed

cli/measures_export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __get_measures_history(obj: object, wanted_metrics: types.KeyList, convert_o
5151
ratings = convert_options.get("ratings", "letters")
5252
percents = convert_options.get("percents", "float")
5353
for m in data:
54-
m[2] = measures.format(obj.endpoint, m[1], m[2], ratings, percents)
54+
m[2] = measures.format_measure(obj.endpoint, m[1], m[2], ratings, percents)
5555
return obj.component_data() | {"history": data}
5656

5757

sonar/branches.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ def audit(self, audit_settings: types.ConfigSettings) -> list[Problem]:
401401
try:
402402
if audit_settings.get(c.AUDIT_MODE_PARAM, "") == "housekeeper":
403403
return self.__audit_last_analysis(audit_settings)
404-
else:
405-
return self.__audit_last_analysis(audit_settings) + self.__audit_never_analyzed() + self._audit_component(audit_settings)
404+
return self.__audit_last_analysis(audit_settings) + self.__audit_never_analyzed() + self._audit_component(audit_settings)
406405
except Exception as e:
407406
log.error("%s while auditing %s, audit skipped", util.error_msg(e), str(self))
408407
return []

sonar/findings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121

2222
from __future__ import annotations
2323
import concurrent.futures
24-
from datetime import datetime
25-
from typing import Optional
24+
from typing import Optional, TYPE_CHECKING
25+
26+
if TYPE_CHECKING:
27+
from datetime import datetime
28+
from sonar.util import types
29+
2630
import re
2731
import Levenshtein
2832

2933
import sonar.logging as log
3034
import sonar.sqobject as sq
3135
import sonar.platform as pf
32-
from sonar.util import types
3336
from sonar.util import constants as c, issue_defs as idefs
3437
from sonar import exceptions
3538

sonar/measures.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from __future__ import annotations
2424

2525
import json
26-
from typing import Any, Optional
26+
from typing import Any, Optional, Union
2727
from sonar import metrics, exceptions, platform
2828
from sonar.util.types import ApiPayload, ApiParams, KeyList
2929
from sonar.util import cache, constants as c
@@ -121,8 +121,8 @@ def is_a_percent(self) -> bool:
121121
def is_an_effort(self) -> bool:
122122
return metrics.is_an_effort(self.endpoint, self.key)
123123

124-
def format(self, ratings: str = "letters", percents: str = "float") -> any:
125-
return format(self.endpoint, self.key, self.value, ratings=ratings, percents=percents)
124+
def format_measure(self, ratings: str = "letters", percents: str = "float") -> any:
125+
return format_measure(self.endpoint, self.key, self.value, ratings=ratings, percents=percents)
126126

127127

128128
def get(concerned_object: object, metrics_list: KeyList, **kwargs) -> dict[str, Measure]:
@@ -171,7 +171,7 @@ def get_history(concerned_object: object, metrics_list: KeyList, **kwargs) -> li
171171
return res_list
172172

173173

174-
def get_rating_letter(rating: Any) -> str:
174+
def get_rating_letter(rating: Union[int, float, str]) -> str:
175175
"""
176176
:param any rating: The rating as repturned by the API (a str or float)
177177
:return: The rating converted from number to letter, if number between 1 and 5, else the unchanged rating
@@ -197,7 +197,7 @@ def get_rating_number(rating_letter: str) -> int:
197197
return rating_letter
198198

199199

200-
def format(endpoint: platform.Platform, metric_key: str, value: Any, ratings: str = "letters", percents: str = "float") -> Any:
200+
def format_measure(endpoint: platform.Platform, metric_key: str, value: Any, ratings: str = "letters", percents: str = "float") -> Any:
201201
"""Formats a measure"""
202202
try:
203203
metric = metrics.Metric.get_object(endpoint, metric_key)

sonar/portfolios.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,23 @@
2626
from __future__ import annotations
2727

2828
import re
29-
from typing import Optional, Union, Any
29+
from typing import Optional, Union, Any, TYPE_CHECKING
3030
import json
3131
from http import HTTPStatus
3232
from threading import Lock
3333

34+
if TYPE_CHECKING:
35+
from sonar.util import types
36+
from sonar.branches import Branch
37+
3438
import sonar.logging as log
3539
import sonar.platform as pf
36-
from sonar.util import types, cache
40+
from sonar.util import cache
3741
import sonar.util.constants as c
3842

3943
from sonar import aggregations, exceptions, applications, app_branches
4044
from sonar.projects import Project
41-
from sonar.branches import Branch
45+
4246

4347
import sonar.permissions.permissions as perms
4448
import sonar.permissions.portfolio_permissions as pperms
@@ -538,7 +542,7 @@ def add_application_branch(self, app_key: str, branch: str = c.DEFAULT_BRANCH) -
538542
self._applications[app_key].append(branch)
539543
return True
540544

541-
def add_subportfolio(self, key: str, name: str = None, by_ref: bool = False) -> Portfolio:
545+
def add_subportfolio(self, key: str, name: Optional[str] = None, by_ref: bool = False) -> Portfolio:
542546
"""Adds a subportfolio to a portfolio, defined by key, name and by reference option"""
543547

544548
log.info("Adding sub-portfolios to %s", str(self))

sonar/settings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def get_all(endpoint: pf.Platform, project: Optional[object] = None) -> dict[str
440440
return get_bulk(endpoint, component=project, include_not_set=True)
441441

442442

443-
def new_code_to_string(data: Any) -> Union[int, str, None]:
443+
def new_code_to_string(data: Union[int, str, dict[str, str]]) -> Union[int, str, None]:
444444
"""Converts a new code period from anything to int str"""
445445
if isinstance(data, (int, str)):
446446
return data
@@ -539,10 +539,9 @@ def encode(setting: Setting, setting_value: Any) -> dict[str, Any]:
539539
"""Encodes the params to pass to api/settings/set according to setting value type"""
540540
if isinstance(setting_value, list):
541541
return {"values": setting_value} if isinstance(setting_value[0], str) else {"fieldValues": [json.dumps(v) for v in setting_value]}
542-
elif isinstance(setting_value, bool):
542+
if isinstance(setting_value, bool):
543543
return {"value": str(setting_value).lower()}
544-
else:
545-
return {"values" if setting.multi_valued else "value": setting_value}
544+
return {"values" if setting.multi_valued else "value": setting_value}
546545

547546

548547
def reset_setting(endpoint: pf.Platform, setting_key: str, project: Optional[object] = None) -> bool:

sonar/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
"""Abstraction of the SonarQube background task concept"""
2222

23-
from typing import Optional
23+
from typing import Optional, Any
2424
from datetime import datetime
2525
import time
2626
import json
@@ -441,7 +441,7 @@ def audit(self, audit_settings: types.ConfigSettings) -> list[Problem]:
441441
return problems
442442

443443

444-
def search(endpoint: pf.Platform, only_current: bool = False, component_key: Optional[str] = None, **kwargs) -> list[Task]:
444+
def search(endpoint: pf.Platform, only_current: bool = False, component_key: Optional[str] = None, **kwargs: Any) -> list[Task]:
445445
"""Searches background tasks
446446
447447
:param Platform endpoint: Reference to the SonarQube platform

sonar/util/component_helper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import re
2222
from typing import Optional
2323

24-
from sonar.util import constants as c
2524
from sonar import platform, components, projects, applications, portfolios
2625

2726

sonar/webhooks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"""Abstraction of the SonarQube webhook concept"""
2222

2323
from __future__ import annotations
24-
from typing import Optional
24+
from typing import Optional, ClassVar
2525

2626
import json
2727

@@ -41,10 +41,10 @@ class WebHook(sq.SqObject):
4141
Abstraction of the SonarQube "webhook" concept
4242
"""
4343

44-
CACHE = cache.Cache()
45-
API = {c.CREATE: "webhooks/create", c.READ: "webhooks/list", c.UPDATE: "webhooks/update", c.LIST: "webhooks/list", c.DELETE: "webhooks/delete"}
46-
SEARCH_KEY_FIELD = "key"
47-
SEARCH_RETURN_FIELD = "webhooks"
44+
CACHE: ClassVar[cache.Cache] = cache.Cache()
45+
API: ClassVar[dict[str, str]] = {c.CREATE: "webhooks/create", c.READ: "webhooks/list", c.UPDATE: "webhooks/update", c.LIST: "webhooks/list", c.DELETE: "webhooks/delete"}
46+
SEARCH_KEY_FIELD: ClassVar[str] = "key"
47+
SEARCH_RETURN_FIELD: ClassVar[str] = "webhooks"
4848

4949
def __init__(self, endpoint: pf.Platform, name: str, url: str, secret: Optional[str] = None, project: Optional[str] = None) -> None:
5050
"""Constructor"""

0 commit comments

Comments
 (0)