()
| 1993 | |
| 1994 | |
| 1995 | def install_python_stack() -> int: |
| 1996 | global USE_UV, _STEP, _TOTAL |
| 1997 | _STEP = 0 |
| 1998 | |
| 1999 | # install.sh (which already installed unsloth) sets SKIP_STUDIO_BASE=1 to |
| 2000 | # avoid reinstalling base packages. "unsloth studio update" does NOT set it, |
| 2001 | # so base packages (unsloth + unsloth-zoo) are reinstalled to pick up new |
| 2002 | # versions. |
| 2003 | skip_base = os.environ.get("SKIP_STUDIO_BASE", "0") == "1" |
| 2004 | # --package installs a different package name (for testing). |
| 2005 | package_name = os.environ.get("STUDIO_PACKAGE_NAME", "unsloth") |
| 2006 | # --local overlays a local repo checkout after updating deps. |
| 2007 | local_repo = os.environ.get("STUDIO_LOCAL_REPO", "") |
| 2008 | base_total = 11 if IS_WINDOWS else 12 # +1 for the anyio repair check (step 8b) |
| 2009 | if IS_MACOS: |
| 2010 | base_total -= 1 # triton step is skipped on macOS |
| 2011 | if not IS_MACOS and not NO_TORCH: |
| 2012 | base_total += 1 # ROCm torch check (line 1526) -- all non-macOS platforms |
| 2013 | if not IS_WINDOWS: |
| 2014 | base_total += 2 # flash-attn (line 1620) + ROCm torch final (line 1705) -- Linux only |
| 2015 | _TOTAL = (base_total - 1) if skip_base else base_total |
| 2016 | |
| 2017 | # 1. Try uv for faster installs (before pip upgrade -- uv venvs don't |
| 2018 | # include pip by default). |
| 2019 | USE_UV = _bootstrap_uv() |
| 2020 | |
| 2021 | # 2. Ensure pip is available (uv venvs from install.sh omit pip). |
| 2022 | _progress("pip bootstrap") |
| 2023 | if USE_UV: |
| 2024 | run( |
| 2025 | "Bootstrapping pip via uv", |
| 2026 | [ |
| 2027 | "uv", |
| 2028 | "pip", |
| 2029 | "install", |
| 2030 | "--python", |
| 2031 | sys.executable, |
| 2032 | "pip", |
| 2033 | ], |
| 2034 | ) |
| 2035 | else: |
| 2036 | # pip may not exist yet (uv-created venvs omit it). Try ensurepip, |
| 2037 | # then upgrade. Direct upgrade only when pip is already present. |
| 2038 | _has_pip = ( |
| 2039 | subprocess.run( |
| 2040 | [sys.executable, "-m", "pip", "--version"], |
| 2041 | stdout = subprocess.DEVNULL, |
| 2042 | stderr = subprocess.DEVNULL, |
| 2043 | **_windows_hidden_subprocess_kwargs(), |
| 2044 | ).returncode |
| 2045 | == 0 |
| 2046 | ) |
| 2047 | |
| 2048 | if not _has_pip: |
| 2049 | run( |
| 2050 | "Bootstrapping pip via ensurepip", |
| 2051 | [sys.executable, "-m", "ensurepip", "--upgrade"], |
| 2052 | ) |
no test coverage detected
searching dependent graphs…