mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-04 20:45:49 +08:00
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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user