From c31f2683cc84b29b0044ec258b0055f6e5be4944 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 10 Oct 2019 15:56:57 +0200 Subject: [PATCH] cmake scripts: make pro_conversion_rate.py mypy clean Change-Id: Id5b210361b6df61bb54324507fcff259cc4091e4 Reviewed-by: Alexandru Croitor Reviewed-by: Tobias Hunger --- util/cmake/pro_conversion_rate.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/util/cmake/pro_conversion_rate.py b/util/cmake/pro_conversion_rate.py index 1224f999a82..3c0c7e30704 100755 --- a/util/cmake/pro_conversion_rate.py +++ b/util/cmake/pro_conversion_rate.py @@ -43,6 +43,7 @@ from argparse import ArgumentParser import os import typing +from typing import Dict, Union from timeit import default_timer @@ -94,7 +95,7 @@ class Blacklist: return False def is_blacklisted_part_aho(self, dir_path: str) -> bool: - return self.tree.search(dir_path) is not None + return self.tree.search(dir_path) is not None # type: ignore def recursive_scan(path: str, extension: str, result_paths: typing.List[str], blacklist: Blacklist): @@ -124,7 +125,7 @@ def compute_stats( existing_pros: int, missing_pros: int, ) -> dict: - stats = {} + stats: Dict[str, Dict[str, Union[str, int, float]]] = {} stats["total projects"] = {"label": "Total pro files found", "value": total_pros} stats["existing projects"] = { "label": "Existing CMakeLists.txt files found", @@ -142,17 +143,21 @@ def compute_stats( for p in pros_with_missing_project: rel_path = os.path.relpath(p, src_path) if rel_path.startswith("examples"): + assert isinstance(stats["missing examples"]["value"], int) stats["missing examples"]["value"] += 1 elif rel_path.startswith("tests"): + assert isinstance(stats["missing tests"]["value"], int) stats["missing tests"]["value"] += 1 elif rel_path.startswith(os.path.join("src", "plugins")): + assert isinstance(stats["missing plugins"]["value"], int) stats["missing plugins"]["value"] += 1 elif rel_path.startswith("src"): + assert isinstance(stats["missing src"]["value"], int) stats["missing src"]["value"] += 1 for stat in stats: - if stats[stat]["value"] > 0: - stats[stat]["percentage"] = round(stats[stat]["value"] * 100 / total_pros, 2) + if int(stats[stat]["value"]) > 0: + stats[stat]["percentage"] = round(float(stats[stat]["value"]) * 100 / total_pros, 2) return stats