Run a list of commands, displaying them within the given section.
(section_header: str, commands: list[str])
| 77 | |
| 78 | |
| 79 | def run_commands(section_header: str, commands: list[str]) -> list[str]: |
| 80 | """Run a list of commands, displaying them within the given section.""" |
| 81 | |
| 82 | pool = ThreadPool(processes=max(1, multiprocessing.cpu_count() - 1)) |
| 83 | lock = Lock() |
| 84 | failed_commands = [] |
| 85 | |
| 86 | def process_command(arg: tuple[int, str]) -> None: |
| 87 | i, command = arg |
| 88 | |
| 89 | # Display the status. |
| 90 | click.secho( |
| 91 | f"\nRunning {section_header} {i + 1}/{len(commands)} : {_command_to_string(command)}", |
| 92 | bold=True, |
| 93 | ) |
| 94 | |
| 95 | # Run the command. |
| 96 | result = subprocess.call( |
| 97 | command.split(" "), stdout=subprocess.DEVNULL, stderr=None |
| 98 | ) |
| 99 | if result != 0: |
| 100 | with lock: |
| 101 | failed_commands.append(command) |
| 102 | |
| 103 | pool.map(process_command, enumerate(commands)) |
| 104 | return failed_commands |
| 105 | |
| 106 | |
| 107 | def main() -> None: |