(examples: Sequence[ExampleScript], args: argparse.Namespace)
| 610 | |
| 611 | |
| 612 | def run_examples(examples: Sequence[ExampleScript], args: argparse.Namespace) -> int: |
| 613 | overrides: set[str] = set() |
| 614 | if args.include_interactive or env_flag("EXAMPLES_INCLUDE_INTERACTIVE"): |
| 615 | overrides.add("interactive") |
| 616 | if args.include_server or env_flag("EXAMPLES_INCLUDE_SERVER"): |
| 617 | overrides.add("server") |
| 618 | if args.include_audio or env_flag("EXAMPLES_INCLUDE_AUDIO"): |
| 619 | overrides.add("audio") |
| 620 | if args.include_external or env_flag("EXAMPLES_INCLUDE_EXTERNAL"): |
| 621 | overrides.add("external") |
| 622 | |
| 623 | logs_dir = Path(args.logs_dir).resolve() |
| 624 | artifacts_dir = Path(args.artifacts_dir).resolve() |
| 625 | main_log_path = Path(args.main_log).resolve() |
| 626 | auto_mode = args.auto_mode or os.environ.get("EXAMPLES_INTERACTIVE_MODE", "").lower() == "auto" |
| 627 | auto_skip_set = load_auto_skip() |
| 628 | |
| 629 | if auto_mode and "interactive" not in overrides: |
| 630 | overrides.add("interactive") |
| 631 | |
| 632 | ensure_dirs(logs_dir, is_file=False) |
| 633 | ensure_dirs(artifacts_dir, is_file=False) |
| 634 | ensure_dirs(main_log_path, is_file=True) |
| 635 | rerun_entries: list[str] = [] |
| 636 | |
| 637 | if not examples: |
| 638 | print("No example entry points found that match the filters.") |
| 639 | return 0 |
| 640 | |
| 641 | print(f"Interactive mode: {'auto' if auto_mode else 'prompt'}") |
| 642 | print(f"Found {len(examples)} example entry points under examples/.") |
| 643 | |
| 644 | executed = 0 |
| 645 | skipped = 0 |
| 646 | failed = 0 |
| 647 | results: list[ExampleResult] = [] |
| 648 | |
| 649 | jobs = max(1, args.jobs) |
| 650 | |
| 651 | output_lock = threading.Lock() |
| 652 | main_log_lock = threading.Lock() |
| 653 | buffer_output = not args.no_buffer_output and os.environ.get( |
| 654 | "EXAMPLES_BUFFER_OUTPUT", "1" |
| 655 | ).lower() not in {"0", "false", "no", "off"} |
| 656 | command_path = build_command_path() |
| 657 | path_augmented = command_path != os.environ.get("PATH", "") |
| 658 | |
| 659 | if path_augmented: |
| 660 | print("Augmented subprocess PATH using interactive shell/common tool directories.") |
| 661 | |
| 662 | def safe_write_main(line: str) -> None: |
| 663 | with main_log_lock: |
| 664 | write_main_log_line(main_log, line) |
| 665 | |
| 666 | def run_single(example: ExampleScript) -> ExampleResult: |
| 667 | relpath = example.relpath |
| 668 | log_filename = f"{relpath.replace('/', '__')}.log" |
| 669 | log_path = logs_dir / log_filename |
no test coverage detected