SCANPY-80 Read ".coveragerc" configuration to exclude files from coverage#234
SCANPY-80 Read ".coveragerc" configuration to exclude files from coverage#234maksim-grebeniuk-sonarsource merged 6 commits intomasterfrom
Conversation
9d0b0bc to
4a8fec7
Compare
thomas-serre-sonarsource
left a comment
There was a problem hiding this comment.
The logic looks good to me.
I suggested a few changes with some of them which are a matter of taste.
| class CoverageRCConfigurationLoader: | ||
|
|
||
| @staticmethod | ||
| def load(base_dir: pathlib.Path) -> dict[str, str]: |
There was a problem hiding this comment.
minor let's rename this function as it's not loading the all coverage file but only the exclusions properties
| def load(base_dir: pathlib.Path) -> dict[str, str]: | |
| def load_exclusion_properties(base_dir: pathlib.Path) -> dict[str, str]: |
| exclusion_properties = CoverageRCConfigurationLoader.__read_coverage_exclusions_properties( | ||
| config_file_path, coverage_properties | ||
| ) | ||
| result_dict.update(exclusion_properties) | ||
| return result_dict |
There was a problem hiding this comment.
minor I would simplify
| exclusion_properties = CoverageRCConfigurationLoader.__read_coverage_exclusions_properties( | |
| config_file_path, coverage_properties | |
| ) | |
| result_dict.update(exclusion_properties) | |
| return result_dict | |
| exclusion_properties = CoverageRCConfigurationLoader.__read_coverage_exclusions_properties( | |
| config_file_path, coverage_properties | |
| ) | |
| return exclusion_properties |
| def __read_config(config_file_path: pathlib.Path) -> dict[str, Any]: | ||
| config_dict: dict[str, Any] = {} | ||
| if not config_file_path.exists(): | ||
| logging.debug(f"Configuration file not found: {config_file_path}") |
There was a problem hiding this comment.
minor for coherence with other logs
| logging.debug(f"Configuration file not found: {config_file_path}") | |
| logging.debug(f"Coverage file not found: {config_file_path}") |
|
|
||
| # Iterate over sections and options |
There was a problem hiding this comment.
nit
| # Iterate over sections and options |
| return config_dict | ||
|
|
||
| @staticmethod | ||
| def __read_coverage_exclusions_properties( |
There was a problem hiding this comment.
minor as this function is not reading from the file but only extracting patterns
| def __read_coverage_exclusions_properties( | |
| def __extract_coverage_exclusion_patterns( |
| @staticmethod | ||
| def __read_coverage_exclusions_properties( | ||
| config_file_path: pathlib.Path, coverage_properties: dict[str, Any] | ||
| ) -> dict[str, Any]: | ||
| result_dict: dict[str, Any] = {} | ||
| if "run" not in coverage_properties: | ||
| logging.debug(f"The run key was not found in {config_file_path}") | ||
| return result_dict | ||
|
|
||
| if "omit" not in coverage_properties["run"]: | ||
| logging.debug(f"The run.omit key was not found in {config_file_path}") | ||
| return result_dict |
There was a problem hiding this comment.
| @staticmethod | |
| def __read_coverage_exclusions_properties( | |
| config_file_path: pathlib.Path, coverage_properties: dict[str, Any] | |
| ) -> dict[str, Any]: | |
| result_dict: dict[str, Any] = {} | |
| if "run" not in coverage_properties: | |
| logging.debug(f"The run key was not found in {config_file_path}") | |
| return result_dict | |
| if "omit" not in coverage_properties["run"]: | |
| logging.debug(f"The run.omit key was not found in {config_file_path}") | |
| return result_dict | |
| @staticmethod | |
| def __extract_coverage_exclusion_patterns(coverage_properties: dict[str, Any]) -> dict[str, Any]: | |
| result_dict: dict[str, Any] = {} | |
| if "run" not in coverage_properties or "omit" not in coverage_properties["run"]: | |
| logging.debug(f"Coverage file has no exclusion properties") | |
| return result_dict |
| result_dict["sonar.coverage.exclusions"] = translated_exclusions | ||
| return result_dict |
There was a problem hiding this comment.
I don't find it relevant in a loader file to build the options that should be passed to the scanner. I think this function should only return the exclusion patterns, so only a string, and the dict should be built outside. Moreover, the dict will always have only one key which seems overkill :) I'd suggest to build the dictionnary in the load function
| result_dict["sonar.coverage.exclusions"] = translated_exclusions | |
| return result_dict | |
| return translated_exclusions |
|
thomas-serre-sonarsource
left a comment
There was a problem hiding this comment.
LGTM, thanks for the modifications !




SCANPY-80
Part of