Install stub packages using pip if some missing stubs were detected.
(
formatter: util.FancyFormatter,
options: Options,
*,
after_run: bool = False,
non_interactive: bool = False,
)
| 1742 | |
| 1743 | |
| 1744 | def install_types( |
| 1745 | formatter: util.FancyFormatter, |
| 1746 | options: Options, |
| 1747 | *, |
| 1748 | after_run: bool = False, |
| 1749 | non_interactive: bool = False, |
| 1750 | ) -> bool: |
| 1751 | """Install stub packages using pip if some missing stubs were detected.""" |
| 1752 | packages = read_types_packages_to_install(options.cache_dir, after_run) |
| 1753 | if not packages: |
| 1754 | # If there are no missing stubs, generate no output. |
| 1755 | return False |
| 1756 | if after_run and not non_interactive: |
| 1757 | print() |
| 1758 | print("Installing missing stub packages:") |
| 1759 | assert options.python_executable, "Python executable required to install types" |
| 1760 | cmd = [options.python_executable, "-m", "pip", "install"] + packages |
| 1761 | print(formatter.style(" ".join(cmd), "none", bold=True)) |
| 1762 | print() |
| 1763 | if not non_interactive: |
| 1764 | x = input("Install? [yN] ") |
| 1765 | if not x.strip() or not x.lower().startswith("y"): |
| 1766 | print(formatter.style("mypy: Skipping installation", "red", bold=True)) |
| 1767 | sys.exit(2) |
| 1768 | print() |
| 1769 | subprocess.run(cmd) |
| 1770 | return True |
no test coverage detected
searching dependent graphs…