Skip to content

Commit b57b7c4

Browse files
committed
exclude *.tests.* for numpy package
1 parent 95d3e40 commit b57b7c4

File tree

2 files changed

+29
-374
lines changed

2 files changed

+29
-374
lines changed

coverage_sources/get_pyright_stats.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import os
55
import subprocess
66
from typing import Any, Dict, Union
7+
from fnmatch import fnmatch
8+
9+
EXCLUDE_LIKE: Dict[str, str] = {
10+
'numpy': '*.tests.*',
11+
}
712

813

914
def create_output_directory(output_dir: str) -> None:
@@ -66,13 +71,23 @@ def run_pyright(venv_name: str, package: str, output_file: str) -> None:
6671
print(f"Output: {e.output}")
6772

6873

69-
def parse_output_json(output_file: str) -> Dict[str, Union[int, float]]:
74+
def parse_output_json(output_file: str, exclude_like: str | None = None) -> Dict[str, Union[int, float]]:
7075
try:
7176
with open(output_file, "r") as f:
7277
output_data = json.load(f)
7378
pyright_data: Dict[str, Union[int, float]] = {}
79+
7480
symbol_count = output_data["typeCompleteness"]["exportedSymbolCounts"]
75-
coverage: float = output_data["typeCompleteness"]["completenessScore"] * 100.0
81+
if exclude_like is None:
82+
coverage: float = output_data["typeCompleteness"]["completenessScore"] * 100.0
83+
else:
84+
matched_symbols = [
85+
x for x in output_data["typeCompleteness"]["symbols"] if not fnmatch(x["name"], exclude_like)
86+
and x['isExported']
87+
]
88+
coverage = (
89+
sum(x["isTypeKnown"] for x in matched_symbols) / len(matched_symbols) * 100
90+
)
7691

7792
pyright_data = symbol_count
7893
pyright_data["coverage"] = coverage
@@ -133,7 +148,7 @@ def main(packages: list[dict[str, Any]]) -> Dict[str, Any]:
133148

134149
output_file = f"{output_dir}/{package}_output.json"
135150
run_pyright(venv_name, package, output_file)
136-
pyright_data = parse_output_json(output_file)
151+
pyright_data = parse_output_json(output_file, EXCLUDE_LIKE.get(package, None))
137152

138153
stats[package] = pyright_data
139154

0 commit comments

Comments
 (0)