Skip to content

Commit

Permalink
Refactor naming on interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: patrickpa <patrick@ivex.ai>
  • Loading branch information
patrickpa committed Jun 6, 2024
1 parent 59a16a6 commit 931f03c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 60 deletions.
2 changes: 1 addition & 1 deletion qc_baselib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@


from .configuration import Configuration as Configuration
from .results import Result as Result
from .result import Result as Result
from .models import IssueSeverity as IssueSeverity
46 changes: 25 additions & 21 deletions qc_baselib/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def write_to_file(self, xml_output_file_path: str) -> None:
config_xml_file.write(xml_text)

def _get_checker_bundle(
self, application: str
self, checker_bundle_name: str
) -> Union[config.CheckerBundleType, None]:
if len(self._configuration.checker_bundles) == 0:
return None
Expand All @@ -82,7 +82,7 @@ def _get_checker_bundle(
(
bundle
for bundle in self._configuration.checker_bundles
if bundle.application == application
if bundle.application == checker_bundle_name
),
None,
)
Expand All @@ -104,9 +104,9 @@ def get_config_param(self, param_name: str) -> Union[str, int, float, None]:
return param.value

def get_checker_bundle_param(
self, application: str, param_name: str
self, checker_bundle_name: str, param_name: str
) -> Union[str, int, float, None]:
bundle = self._get_checker_bundle(application=application)
bundle = self._get_checker_bundle(application=checker_bundle_name)

if bundle is None or len(bundle.params) == 0:
return None
Expand All @@ -122,9 +122,9 @@ def get_checker_bundle_param(
return param.value

def get_checker_param(
self, application: str, checker_id: str, param_name: str
self, checker_bundle_name: str, checker_id: str, param_name: str
) -> Union[str, int, float, None]:
bundle = self._get_checker_bundle(application=application)
bundle = self._get_checker_bundle(application=checker_bundle_name)

if bundle is None:
return None
Expand All @@ -146,7 +146,7 @@ def get_checker_param(
return param.value

def get_report_module_param(
self, application: str, param_name: str
self, checker_bundle_name: str, param_name: str
) -> Union[str, int, float, None]:
if len(self._configuration.reports) == 0:
return None
Expand All @@ -155,7 +155,7 @@ def get_report_module_param(
(
report
for report in self._configuration.reports
if report.application == application
if report.application == checker_bundle_name
),
None,
)
Expand All @@ -173,9 +173,9 @@ def get_report_module_param(

return param.value

def register_checker_bundle(self, application: str) -> None:
def register_checker_bundle(self, checker_bundle_name: str) -> None:
checker_bundle = config.CheckerBundleType.model_construct(
**{"application": application}
**{"application": checker_bundle_name}
)

if self._configuration is None:
Expand All @@ -186,13 +186,17 @@ def register_checker_bundle(self, application: str) -> None:
else:
self._configuration.checker_bundles.append(checker_bundle)

def register_checker_to_bundle(
def register_checker(
self,
application: str,
checker_bundle_name: str,
checker_id: str,
min_level: IssueSeverity,
max_level: IssueSeverity,
) -> None:
"""
Checker with checker_id will be registered to the checker bundle
identified by the checker_bundle_name.
"""
check = config.CheckerType(
checker_id=checker_id, min_level=min_level, max_level=max_level
)
Expand All @@ -202,11 +206,11 @@ def register_checker_to_bundle(
"Adding check to empty configuration. Initialize the config registering first a checker bundle."
)
else:
bundle = self._get_checker_bundle(application=application)
bundle = self._get_checker_bundle(application=checker_bundle_name)

if bundle is None:
raise RuntimeError(
f"Adding check to non-existent '{application}' checker bundle. Register first the checker bundle."
f"Adding check to non-existent '{checker_bundle_name}' checker bundle. Register first the checker bundle."
)
bundle.checkers.append(check)

Expand All @@ -219,7 +223,7 @@ def set_config_param(self, name: str, value: Union[int, float, str]) -> None:
self._configuration.params.append(param)

def set_checker_bundle_param(
self, application: str, name: str, value: Union[int, float, str]
self, checker_bundle_name: str, name: str, value: Union[int, float, str]
) -> None:
param = common.ParamType(name=name, value=value)

Expand All @@ -232,20 +236,20 @@ def set_checker_bundle_param(
(
bundle
for bundle in self._configuration.checker_bundles
if bundle.application == application
if bundle.application == checker_bundle_name
),
None,
)

if bundle is None:
raise RuntimeError(
f"Adding param to non-existent '{application}' checker bundle. Register first the checker bundle."
f"Adding param to non-existent '{checker_bundle_name}' checker bundle. Register first the checker bundle."
)
bundle.params.append(param)

def set_checker_param(
self,
application: str,
checker_bundle_name: str,
checker_id: str,
name: str,
value: Union[str, int, float],
Expand All @@ -261,14 +265,14 @@ def set_checker_param(
(
bundle
for bundle in self._configuration.checker_bundles
if bundle.application == application
if bundle.application == checker_bundle_name
),
None,
)

if bundle is None:
raise RuntimeError(
f"Adding param to non-existent '{application}' checker bundle. Register first the checker bundle."
f"Adding param to non-existent '{checker_bundle_name}' checker bundle. Register first the checker bundle."
)

check = next(
Expand All @@ -277,6 +281,6 @@ def set_checker_param(
)
if check is None:
raise RuntimeError(
f"Adding param to non-existent '{application}' checker bundle. Register first the checker bundle."
f"Adding param to non-existent '{checker_bundle_name}' checker bundle. Register first the checker bundle."
)
check.params.append(param)
Loading

0 comments on commit 931f03c

Please sign in to comment.