44
55Example usage:
66
7- spin run python tools/pyright_cov .py --verifytypes numpy --ignoreexternal \
8- --fail-under 80 --exclude-like '*.tests.*'
7+ spin run python tools/pyright_completeness .py --verifytypes numpy --ignoreexternal \
8+ --fail-under 80 --exclude-like '*.tests.*' '*.conftest.*'
99
1010We use `--ignoreexternal` to avoid "partially unknown" reports coming from the stdlib
1111`numbers` module, see https://github.com/microsoft/pyright/discussions/9911.
12-
13- It might be possible to replace this with `basedpyright`
14- https://github.com/DetachHead/basedpyright/issues/125 in the future.
1512"""
1613from __future__ import annotations
1714
@@ -34,6 +31,7 @@ def main(argv: Sequence[str] | None = None) -> int:
3431 parser .add_argument (
3532 "--exclude-like" ,
3633 required = False ,
34+ nargs = '*' ,
3735 type = str ,
3836 help = "Exclude symbols whose names matches this glob pattern" ,
3937 )
@@ -47,7 +45,7 @@ def main(argv: Sequence[str] | None = None) -> int:
4745def run_pyright_with_coverage (
4846 pyright_args : list [str ],
4947 cov_fail_under : float ,
50- exclude_like : str | None ,
48+ exclude_like : Sequence [ str ] ,
5149) -> int :
5250 result = subprocess .run (
5351 ["pyright" , * pyright_args ], capture_output = True , text = True
@@ -60,10 +58,10 @@ def run_pyright_with_coverage(
6058 sys .stderr .write (result .stderr )
6159 return 1
6260
63- if exclude_like is not None :
61+ if exclude_like :
6462 symbols = data ["typeCompleteness" ]["symbols" ]
6563 matched_symbols = [
66- x for x in symbols if not fnmatch .fnmatch (x ["name" ], exclude_like )
64+ x for x in symbols if not any ( fnmatch .fnmatch (x ["name" ], pattern ) for pattern in exclude_like )
6765 and x ['isExported' ]
6866 ]
6967 cov_percent = (
@@ -73,16 +71,15 @@ def run_pyright_with_coverage(
7371 cov_percent = data ["typeCompleteness" ]["completenessScore" ] * 100
7472
7573 sys .stderr .write (result .stderr )
76- sys .stdout .write (result .stdout )
7774 if cov_percent < cov_fail_under :
7875 sys .stdout .write (
7976 f"Coverage { cov_percent :.1f} % is below minimum required "
80- f"{ cov_fail_under :.1f} %"
77+ f"{ cov_fail_under :.1f} %\n "
8178 )
8279 return 1
8380 sys .stdout .write (
8481 f"Coverage { cov_percent :.1f} % is at or above minimum required "
85- f"{ cov_fail_under :.1f} %"
82+ f"{ cov_fail_under :.1f} %\n "
8683 )
8784 return 0
8885
0 commit comments