Like pip_install but returns False on failure instead of exiting. For optional installs that have a follow-up fallback.
(
label: str,
*args: str,
constrain: bool = True,
force_pip: bool = False,
)
| 1865 | |
| 1866 | |
| 1867 | def pip_install_try( |
| 1868 | label: str, |
| 1869 | *args: str, |
| 1870 | constrain: bool = True, |
| 1871 | force_pip: bool = False, |
| 1872 | ) -> bool: |
| 1873 | """Like pip_install but returns False on failure instead of exiting. |
| 1874 | For optional installs that have a follow-up fallback. |
| 1875 | """ |
| 1876 | constraint_args_pip: list[str] = [] |
| 1877 | constraint_args_uv: list[str] = [] |
| 1878 | if constrain and CONSTRAINTS.is_file(): |
| 1879 | constraint_args_pip = ["-c", str(CONSTRAINTS)] |
| 1880 | constraint_args_uv = ["-c", _uv_safe_path(CONSTRAINTS)] |
| 1881 | |
| 1882 | if USE_UV and not force_pip: |
| 1883 | cmd = _build_uv_cmd(args) + constraint_args_uv |
| 1884 | else: |
| 1885 | cmd = _build_pip_cmd(args) + constraint_args_pip |
| 1886 | |
| 1887 | if VERBOSE: |
| 1888 | _step(_LABEL, f"{label}...", _dim) |
| 1889 | result = subprocess.run( |
| 1890 | cmd, |
| 1891 | stdout = subprocess.PIPE, |
| 1892 | stderr = subprocess.STDOUT, |
| 1893 | ) |
| 1894 | if result.returncode == 0: |
| 1895 | return True |
| 1896 | if VERBOSE and result.stdout: |
| 1897 | print(result.stdout.decode(errors = "replace")) |
| 1898 | return False |
| 1899 | |
| 1900 | |
| 1901 | def pip_install( |
no test coverage detected
searching dependent graphs…