20
20
from __future__ import annotations
21
21
import os
22
22
import sys
23
- from typing import Union
23
+ from typing import Union , AnyStr
24
24
import toml
25
25
26
26
@@ -47,16 +47,12 @@ def setup(self) -> None:
47
47
def _read_toml_args (self ) -> list [str ]:
48
48
scan_arguments : list [str ] = []
49
49
try :
50
- if os .path .isfile ("pyproject.toml" ):
51
- with open ("pyproject.toml" , "r" ) as file :
52
- # TODO: actually search for pyproject.toml
53
- toml_data = file .read ()
54
- parsed_data = toml .loads (toml_data )
55
- print (parsed_data )
56
- if "sonar" in parsed_data :
57
- sonar_properties = parsed_data ["sonar" ]
58
- for key , value in sonar_properties .items ():
59
- self ._add_parameter_to_scanner_args (scan_arguments , key , value )
50
+ parsed_data = self ._read_toml_file ()
51
+ if ("tool" not in parsed_data ) or ("sonar" not in parsed_data ["tool" ]):
52
+ return scan_arguments
53
+ sonar_properties = parsed_data ["tool" ]["sonar" ]
54
+ for key , value in sonar_properties .items ():
55
+ self ._add_parameter_to_scanner_args (scan_arguments , key , value )
60
56
except BaseException as e :
61
57
print (e )
62
58
return scan_arguments
@@ -67,3 +63,11 @@ def _add_parameter_to_scanner_args(self, scan_arguments: list[str], key: str, va
67
63
if isinstance (value , dict ):
68
64
for k , v in value .items ():
69
65
self ._add_parameter_to_scanner_args (scan_arguments , f"{ key } .{ k } " , v )
66
+
67
+ def _read_toml_file (self ) -> dict :
68
+ if not os .path .isfile ("pyproject.toml" ):
69
+ return {}
70
+ with open ("pyproject.toml" , "r" ) as file :
71
+ # TODO: actually search for pyproject.toml
72
+ toml_data = file .read ()
73
+ return toml .loads (toml_data )
0 commit comments