From da50b5c4112bc44dce08685f9e30708b8cb88489 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 16 Mar 2025 20:40:38 +0100 Subject: [PATCH] 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()`. --- tests/stubtest_third_party.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index a83d4fbc5..379ba718d 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -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)