Move error handling to main function (#13630)

* This makes is easier to call `run_stubtest()` manually, for
   example when testing the script - no need to construct
   an `ArgumentParser` instance.
* This concentrates argument error handling in the
  `main()` function and prevents an unexpected process exit
  when calling `run_stubtest()`.
This commit is contained in:
Sebastian Rittau
2025-03-16 20:40:38 +01:00
committed by GitHub
parent acac58ad4a
commit da50b5c411
+9 -18
View File
@@ -31,20 +31,12 @@ from ts_utils.utils import (
def run_stubtest(
dist: Path,
*,
parser: argparse.ArgumentParser,
verbose: bool = False,
specified_platforms_only: bool = False,
keep_tmp_dir: bool = False,
dist: Path, *, verbose: bool = False, specified_platforms_only: bool = False, keep_tmp_dir: bool = False
) -> bool:
"""Run stubtest for a single distribution."""
dist_name = dist.name
try:
metadata = read_metadata(dist_name)
except NoSuchStubError as e:
parser.error(str(e))
metadata = read_metadata(dist_name)
print(f"{dist_name}... ", end="", flush=True)
t = time()
@@ -410,14 +402,13 @@ def main() -> NoReturn:
for i, dist in enumerate(dists):
if i % args.num_shards != args.shard_index:
continue
if not run_stubtest(
dist,
parser=parser,
verbose=args.verbose,
specified_platforms_only=args.specified_platforms_only,
keep_tmp_dir=args.keep_tmp_dir,
):
result = 1
try:
if not run_stubtest(
dist, verbose=args.verbose, specified_platforms_only=args.specified_platforms_only, keep_tmp_dir=args.keep_tmp_dir
):
result = 1
except NoSuchStubError as e:
parser.error(str(e))
sys.exit(result)