Build and run a pip install command (uses uv when available, falls back to pip).
(
label: str,
*args: str,
req: Path | None = None,
constrain: bool = True,
)
| 1899 | |
| 1900 | |
| 1901 | def pip_install( |
| 1902 | label: str, |
| 1903 | *args: str, |
| 1904 | req: Path | None = None, |
| 1905 | constrain: bool = True, |
| 1906 | ) -> None: |
| 1907 | """Build and run a pip install command (uses uv when available, falls back to pip).""" |
| 1908 | constraint_args_pip: list[str] = [] |
| 1909 | constraint_args_uv: list[str] = [] |
| 1910 | if constrain and CONSTRAINTS.is_file(): |
| 1911 | constraint_args_pip = ["-c", str(CONSTRAINTS)] |
| 1912 | constraint_args_uv = ["-c", _uv_safe_path(CONSTRAINTS)] |
| 1913 | |
| 1914 | actual_req = req |
| 1915 | temp_reqs: list[Path] = [] |
| 1916 | if req is not None and IS_WINDOWS and WINDOWS_SKIP_PACKAGES: |
| 1917 | actual_req = _filter_requirements(req, WINDOWS_SKIP_PACKAGES) |
| 1918 | temp_reqs.append(actual_req) |
| 1919 | if actual_req is not None and NO_TORCH and NO_TORCH_SKIP_PACKAGES: |
| 1920 | actual_req = _filter_requirements(actual_req, NO_TORCH_SKIP_PACKAGES) |
| 1921 | temp_reqs.append(actual_req) |
| 1922 | if actual_req is not None and PLATFORM_LACKS_TORCHCODEC_WHEEL: |
| 1923 | # Linux aarch64 / Windows ARM64 / Intel Mac have no torchcodec |
| 1924 | # wheel. `unsloth studio update --local` does not pass |
| 1925 | # --no-torch, so the NO_TORCH filter above does not fire; do |
| 1926 | # the targeted skip independently so the audio extras step |
| 1927 | # does not take down the whole update. |
| 1928 | actual_req = _filter_requirements(actual_req, {"torchcodec"}) |
| 1929 | temp_reqs.append(actual_req) |
| 1930 | req_args_pip: list[str] = [] |
| 1931 | req_args_uv: list[str] = [] |
| 1932 | if actual_req is not None: |
| 1933 | req_args_pip = ["-r", str(actual_req)] |
| 1934 | req_args_uv = ["-r", _uv_safe_path(actual_req)] |
| 1935 | |
| 1936 | try: |
| 1937 | if USE_UV: |
| 1938 | uv_cmd = _build_uv_cmd(args) + constraint_args_uv + req_args_uv |
| 1939 | if VERBOSE: |
| 1940 | print(f" {label}...") |
| 1941 | result = subprocess.run( |
| 1942 | uv_cmd, |
| 1943 | stdout = subprocess.PIPE, |
| 1944 | stderr = subprocess.STDOUT, |
| 1945 | **_windows_hidden_subprocess_kwargs(), |
| 1946 | ) |
| 1947 | if result.returncode == 0: |
| 1948 | return |
| 1949 | print(_red(f" uv failed, falling back to pip...")) |
| 1950 | if result.stdout: |
| 1951 | print(result.stdout.decode(errors = "replace")) |
| 1952 | |
| 1953 | pip_cmd = _build_pip_cmd(args) + constraint_args_pip + req_args_pip |
| 1954 | run(f"{label} (pip)" if USE_UV else label, pip_cmd) |
| 1955 | finally: |
| 1956 | for temp_req in temp_reqs: |
| 1957 | temp_req.unlink(missing_ok = True) |
| 1958 |
no test coverage detected
searching dependent graphs…