Return (is_available, command_prefix).
()
| 369 | |
| 370 | |
| 371 | def check_iwyu_available() -> tuple[bool, str]: |
| 372 | """Return (is_available, command_prefix).""" |
| 373 | # System IWYU |
| 374 | try: |
| 375 | result = subprocess.run( |
| 376 | ["include-what-you-use", "--version"], |
| 377 | capture_output=True, |
| 378 | text=True, |
| 379 | timeout=10, |
| 380 | ) |
| 381 | if result.returncode == 0: |
| 382 | return (True, "") |
| 383 | except ( |
| 384 | subprocess.CalledProcessError, |
| 385 | FileNotFoundError, |
| 386 | subprocess.TimeoutExpired, |
| 387 | ): |
| 388 | pass |
| 389 | |
| 390 | # clang-tool-chain-iwyu via uv |
| 391 | try: |
| 392 | result = subprocess.run( |
| 393 | [ |
| 394 | "uv", |
| 395 | "run", |
| 396 | "python", |
| 397 | "-c", |
| 398 | "from clang_tool_chain.wrapper import iwyu_main", |
| 399 | ], |
| 400 | capture_output=True, |
| 401 | text=True, |
| 402 | timeout=10, |
| 403 | ) |
| 404 | if result.returncode == 0: |
| 405 | return (True, "uv run ") |
| 406 | except ( |
| 407 | subprocess.CalledProcessError, |
| 408 | FileNotFoundError, |
| 409 | subprocess.TimeoutExpired, |
| 410 | ): |
| 411 | pass |
| 412 | |
| 413 | return (False, "") |
| 414 | |
| 415 | |
| 416 | # --------------------------------------------------------------------------- |