From 2ec06cb99636dd66e63e427c878fc5c4749e66e9 Mon Sep 17 00:00:00 2001 From: Youssef Boulaoaune <43298428+Boulaouaney@users.noreply.github.com> Date: Tue, 28 Oct 2025 15:39:49 +0900 Subject: [PATCH 1/7] Enhance linux/macOS installer with uv package manager support Added support for uv package manager installation and updated installation logic to use uv if available. Modified logging and error handling for better user guidance. --- utils/installers/install.sh | 190 ++++++++++++++++++++++++------------ 1 file changed, 128 insertions(+), 62 deletions(-) diff --git a/utils/installers/install.sh b/utils/installers/install.sh index fb7689373d..cc598b0ce9 100755 --- a/utils/installers/install.sh +++ b/utils/installers/install.sh @@ -25,25 +25,23 @@ fi set -e -# Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' -NC='\033[0m' # No Color +NC='\033[0m' -# Logging level: 0=quiet, 1=info (default), 2=verbose LOG_LEVEL=1 -# Configuration FORCE_REINSTALL="false" BIN_DIR="${HF_CLI_BIN_DIR:-$HOME/.local/bin}" UPDATED_RC_FILE="" REQUESTED_VERSION="${HF_CLI_VERSION:-}" SKIP_PATH_UPDATE="false" UPDATED_FISH_PATH="false" +USE_UV="${HF_CLI_USE_UV:-true}" +UV_INSTALLED="false" -# Logging functions log_debug() { if [ "$LOG_LEVEL" -lt 2 ]; then return 0 @@ -92,17 +90,18 @@ Usage: curl -LsSf https://hf.co/cli/install.sh | sh -s -- [OPTIONS] Options: --force Recreate the Hugging Face CLI virtual environment if it exists --no-modify-path Skip adding the hf wrapper directory to PATH - -v, --verbose Enable verbose output (includes full pip logs) + --no-uv Use pip instead of uv for package installation + -v, --verbose Enable verbose output --help, -h Show this message and exit Environment variables: HF_HOME Installation base directory; installer uses $HF_HOME/cli when set HF_CLI_BIN_DIR Directory for the hf wrapper (default: ~/.local/bin) HF_CLI_VERSION Install a specific huggingface_hub version (default: latest) + HF_CLI_USE_UV Use uv for package installation (default: true) EOF } -# Normalize user paths to absolute paths expand_path() { local input="$1" if [ -z "$input" ]; then @@ -133,6 +132,9 @@ while [ $# -gt 0 ]; do --no-modify-path) SKIP_PATH_UPDATE="true" ;; + --no-uv) + USE_UV="false" + ;; -v|--verbose) LOG_LEVEL=2 HF_CLI_VERBOSE_PIP=1 @@ -150,7 +152,6 @@ while [ $# -gt 0 ]; do shift done -# Persist fully resolved paths for downstream use and wrapper creation BIN_DIR=$(expand_path "$BIN_DIR") if [ -n "$HF_HOME" ]; then @@ -162,12 +163,10 @@ fi HF_CLI_DIR=$(expand_path "$HF_CLI_DIR") VENV_DIR="$HF_CLI_DIR/venv" -# Check if command exists command_exists() { command -v "$1" >/dev/null 2>&1 } -# Detect OS detect_os() { if [[ "$OSTYPE" == "linux-gnu"* ]]; then echo "linux" @@ -178,7 +177,6 @@ detect_os() { fi } -# Install Python if not available python_version_supported() { "$1" <<'PY' >/dev/null 2>&1 import sys @@ -212,7 +210,7 @@ ensure_python() { ;; linux) if command_exists apt-get || command_exists apt; then - log_info "On Debian/Ubuntu: sudo apt update && sudo apt install python3 python3-pip" + log_info "On Debian/Ubuntu: sudo apt update && sudo apt install python3 python3-pip python3-venv" elif command_exists dnf; then log_info "On Fedora/RHEL: sudo dnf install python3 python3-pip" elif command_exists yum; then @@ -231,14 +229,77 @@ ensure_python() { log_info "Using Python: $($PYTHON_CMD --version)" } -# Create directories +ensure_uv() { + if [ "$USE_UV" != "true" ]; then + log_info "Using pip for package installation" + return + fi + + if command_exists uv; then + UV_CMD="uv" + log_info "Using uv: $(uv --version 2>&1 || echo 'version unknown')" + return + fi + + log_info "Installing uv package manager..." + + local uv_installer=$(mktemp) + if command_exists curl; then + if ! curl -LsSf https://astral.sh/uv/install.sh -o "$uv_installer" 2>/dev/null; then + log_warning "Failed to download uv installer, falling back to pip" + USE_UV="false" + rm -f "$uv_installer" + return + fi + elif command_exists wget; then + if ! wget -qO "$uv_installer" https://astral.sh/uv/install.sh 2>/dev/null; then + log_warning "Failed to download uv installer, falling back to pip" + USE_UV="false" + rm -f "$uv_installer" + return + fi + else + log_warning "curl or wget not found, falling back to pip" + USE_UV="false" + return + fi + + chmod +x "$uv_installer" + + export INSTALLER_NO_MODIFY_PATH=1 + if ! sh "$uv_installer" >/dev/null 2>&1; then + log_warning "Failed to install uv, falling back to pip" + USE_UV="false" + rm -f "$uv_installer" + return + fi + rm -f "$uv_installer" + + local uv_locations=( + "$HOME/.cargo/bin/uv" + "$HOME/.local/bin/uv" + "/usr/local/bin/uv" + ) + + for location in "${uv_locations[@]}"; do + if [ -x "$location" ]; then + UV_CMD="$location" + UV_INSTALLED="true" + log_info "uv installed: $($UV_CMD --version)" + return + fi + done + + log_warning "uv installation completed but command not found, falling back to pip" + USE_UV="false" +} + create_directories() { log_info "Creating directories..." run_command "Failed to create install directory $HF_CLI_DIR" mkdir -p "$HF_CLI_DIR" run_command "Failed to create bin directory $BIN_DIR" mkdir -p "$BIN_DIR" } -# Create virtual environment create_venv() { log_info "Creating virtual environment..." if [ -d "$VENV_DIR" ]; then @@ -251,32 +312,39 @@ create_venv() { fi fi - # Fail early with guidance when python lacks the venv module - if ! "$PYTHON_CMD" -m venv --help >/dev/null 2>&1; then - log_error "Python's venv module is unavailable. Install python3-venv / ensurepip and retry." - case "$(detect_os)" in - linux) - log_info "Try: sudo apt install python3-venv # Debian/Ubuntu" - log_info " sudo dnf install python3-venv # Fedora" - ;; - macos) - log_info "Try reinstalling Python via Homebrew: brew install python" - ;; - esac - exit 1 - fi + if [ "$USE_UV" = "true" ]; then + local uv_args=() + if [ "$LOG_LEVEL" -ge 2 ]; then + uv_args+=(--verbose) + else + uv_args+=(--quiet) + fi - run_command "Failed to create virtual environment at $VENV_DIR" "$PYTHON_CMD" -m venv "$VENV_DIR" + run_command "Failed to create virtual environment at $VENV_DIR" "$UV_CMD" venv "${uv_args[@]}" --python "$PYTHON_CMD" "$VENV_DIR" + else + if ! "$PYTHON_CMD" -m venv --help >/dev/null 2>&1; then + log_error "Python's venv module is unavailable. Install python3-venv and retry." + case "$(detect_os)" in + linux) + log_info "Try: sudo apt install python3-venv # Debian/Ubuntu" + log_info " sudo dnf install python3-venv # Fedora" + ;; + macos) + log_info "Try reinstalling Python via Homebrew: brew install python" + ;; + esac + exit 1 + fi - # Mark this installation as installer-managed - touch "$VENV_DIR/.hf_installer_marker" + run_command "Failed to create virtual environment at $VENV_DIR" "$PYTHON_CMD" -m venv "$VENV_DIR" + + log_info "Upgrading pip..." + run_command "Failed to upgrade pip" "$VENV_DIR/bin/python" -m pip install --upgrade pip + fi - # Use the venv python for pip management - log_info "Upgrading pip..." - run_command "Failed to upgrade pip" "$VENV_DIR/bin/python" -m pip install --upgrade pip + touch "$VENV_DIR/.hf_installer_marker" } -# Install huggingface_hub with CLI extras install_hf_hub() { local package_spec="huggingface_hub" if [ -n "$REQUESTED_VERSION" ]; then @@ -286,32 +354,36 @@ install_hf_hub() { log_info "Installing The Hugging Face CLI (latest)..." fi - local extra_pip_args="${HF_CLI_PIP_ARGS:-${HF_PIP_ARGS:-}}" - local -a pip_flags - if [ "${HF_CLI_VERBOSE_PIP:-}" = "1" ]; then - pip_flags=() - else - pip_flags=(--quiet --progress-bar off --disable-pip-version-check) - fi + if [ "$USE_UV" = "true" ]; then + local -a uv_flags=() + if [ "${HF_CLI_VERBOSE_PIP:-}" != "1" ]; then + uv_flags+=(--quiet) + fi - if [ -n "$extra_pip_args" ]; then - log_info "Passing extra pip arguments: $extra_pip_args" - fi + run_command "Failed to install $package_spec" "$UV_CMD" pip install --python "$VENV_DIR/bin/python" "${uv_flags[@]}" "$package_spec" + else + local extra_pip_args="${HF_CLI_PIP_ARGS:-${HF_PIP_ARGS:-}}" + local -a pip_flags + if [ "${HF_CLI_VERBOSE_PIP:-}" = "1" ]; then + pip_flags=() + else + pip_flags=(--quiet --progress-bar off --disable-pip-version-check) + fi - if [ "${HF_CLI_VERBOSE_PIP:-}" != "1" ]; then - log_info "(pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs)" - fi + if [ -n "$extra_pip_args" ]; then + log_info "Passing extra pip arguments: $extra_pip_args" + fi - if [ -n "$extra_pip_args" ]; then - # shellcheck disable=SC2086 - run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} $extra_pip_args - else - # shellcheck disable=SC2086 - run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} + if [ -n "$extra_pip_args" ]; then + # shellcheck disable=SC2086 + run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} $extra_pip_args + else + # shellcheck disable=SC2086 + run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} + fi fi } -# Expose the hf CLI by linking or copying the console script from the virtualenv expose_cli_command() { log_info "Linking hf CLI into $BIN_DIR..." @@ -344,12 +416,10 @@ expose_cli_command() { log_info "Run without touching PATH: env PATH=\"$BIN_DIR:\$PATH\" hf --help" } -# Update PATH if needed update_path() { local shell_rc="" local -a shell_rc_candidates=() - # Broaden shell detection and guidance for PATH propagation case "$SHELL" in */bash) shell_rc_candidates=() @@ -432,12 +502,10 @@ update_path() { fi } -# Verify installation verify_installation() { log_info "Verifying installation..." if [ -x "$BIN_DIR/hf" ]; then - # Test the CLI if "$BIN_DIR/hf" version >/dev/null 2>&1; then log_success "Hugging Face CLI installed successfully!" log_info "CLI location: $BIN_DIR/hf" @@ -452,7 +520,6 @@ verify_installation() { fi } -# Uninstall function show_uninstall_info() { log_info "" log_info "To uninstall the Hugging Face CLI, run:" @@ -470,7 +537,6 @@ show_uninstall_info() { fi } -# Main installation process main() { log_info "Installing Hugging Face CLI..." log_info "OS: $(detect_os)" @@ -481,6 +547,7 @@ main() { log_info "Skip PATH update: $SKIP_PATH_UPDATE" ensure_python + ensure_uv create_directories create_venv install_hf_hub @@ -508,7 +575,6 @@ main() { log_info "" } -# Handle Ctrl+C trap 'log_error "Installation interrupted"; exit 130' INT main "$@" From 4e741d3265da19456cd711618a7448e699adfaa5 Mon Sep 17 00:00:00 2001 From: Youssef Boulaoaune <43298428+Boulaouaney@users.noreply.github.com> Date: Tue, 28 Oct 2025 15:54:18 +0900 Subject: [PATCH 2/7] Enhance Windows installer with uv package manager support --- utils/installers/install.ps1 | 191 ++++++++++++++++++++++++----------- 1 file changed, 134 insertions(+), 57 deletions(-) diff --git a/utils/installers/install.ps1 b/utils/installers/install.ps1 index 71b89bb62a..ea67b33559 100644 --- a/utils/installers/install.ps1 +++ b/utils/installers/install.ps1 @@ -13,11 +13,14 @@ Downloads and installs the `huggingface_hub` package into a dedicated virtual en Recreates the virtual environment even if it already exists. Off by default. .PARAMETER Verbose -Enables verbose output, including detailed pip logs. +Enables verbose output, including detailed logs. .PARAMETER NoModifyPath Skips PATH modifications; `hf` must be invoked via its full path unless you add it manually. +.PARAMETER NoUv +Use pip instead of uv for package installation. + .EXAMPLE powershell -c "irm https://hf.co/cli/install.ps1 | iex" #> @@ -28,25 +31,28 @@ Environment variables: HF_HOME Installation base directory; installer uses $env:HF_HOME\cli when set HF_CLI_BIN_DIR Directory for the hf wrapper (default: $env:USERPROFILE\.local\bin) HF_CLI_VERSION Install a specific huggingface_hub version (default: latest) + HF_CLI_USE_UV Use uv for package installation (default: true) #> param( [switch]$Force = $false, [switch]$Verbose, - [switch]$NoModifyPath + [switch]$NoModifyPath, + [switch]$NoUv ) $script:LogLevel = if ($Verbose) { 2 } else { 1 } $script:PathUpdated = $false +$script:UseUv = if ($NoUv) { $false } elseif ($env:HF_CLI_USE_UV -eq 'false') { $false } else { $true } +$script:UvInstalled = $false +$script:UvCmd = $null if ($Verbose) { $env:HF_CLI_VERBOSE_PIP = '1' } -# Set error action preference $ErrorActionPreference = "Stop" -# Colors for output $Colors = @{ Red = 'Red' Green = 'Green' @@ -83,7 +89,6 @@ function Write-Log { } } -# Normalize user-supplied paths function Resolve-CliPath { param([string]$Path) @@ -107,7 +112,6 @@ function Resolve-CliPath { return [System.IO.Path]::GetFullPath((Join-Path $base $expanded)) } -# Compose installer directories using environment variables only if ($env:HF_HOME) { $HF_CLI_DIR = Resolve-CliPath (Join-Path $env:HF_HOME "cli") } else { @@ -136,7 +140,7 @@ function Test-PythonVersion { $version = & $PythonCmd --version 2>&1 if ($version -match "Python 3\.(\d+)\.") { $minorVersion = [int]$matches[1] - return $minorVersion -ge 9 # Python 3.9+ + return $minorVersion -ge 9 } return $false } catch { return $false } @@ -145,7 +149,6 @@ function Test-PythonVersion { function Find-Python { Write-Log "Looking for Python 3.9+ installation..." - # Try common Python commands $pythonCommands = @("python", "python3", "py") foreach ($cmd in $pythonCommands) { @@ -158,7 +161,6 @@ function Find-Python { } } - # Try Python Launcher for Windows if (Test-Command "py") { try { $version = py -3 --version 2>&1 @@ -178,6 +180,68 @@ function Find-Python { throw "Python 3.9+ not found" } +function Install-Uv { + if (-not $script:UseUv) { + Write-Log "Using pip for package installation" + return + } + + if (Test-Command "uv") { + try { + $uvVersion = & uv --version 2>&1 + $script:UvCmd = "uv" + Write-Log "Using uv: $uvVersion" + return + } catch { } + } + + Write-Log "Installing uv package manager..." + + try { + $uvInstaller = Join-Path $env:TEMP "uv-installer.ps1" + + if (Test-Command "curl") { + & curl -LsSf https://astral.sh/uv/install.ps1 -o $uvInstaller 2>$null + } else { + Invoke-WebRequest -Uri "https://astral.sh/uv/install.ps1" -OutFile $uvInstaller -UseBasicParsing + } + + if (-not (Test-Path $uvInstaller)) { + Write-Log "Failed to download uv installer, falling back to pip" "WARNING" + $script:UseUv = $false + return + } + + $env:INSTALLER_NO_MODIFY_PATH = "1" + & powershell -ExecutionPolicy ByPass -File $uvInstaller *>$null + + Remove-Item -Path $uvInstaller -Force -ErrorAction SilentlyContinue + + $uvLocations = @( + (Join-Path $env:USERPROFILE ".cargo\bin\uv.exe"), + (Join-Path $env:USERPROFILE ".local\bin\uv.exe"), + "C:\Program Files\uv\uv.exe" + ) + + foreach ($location in $uvLocations) { + if (Test-Path $location) { + $script:UvCmd = $location + $script:UvInstalled = $true + $uvVersion = & $script:UvCmd --version 2>&1 + Write-Log "uv installed: $uvVersion" + return + } + } + + Write-Log "uv installation completed but command not found, falling back to pip" "WARNING" + $script:UseUv = $false + } + catch { + Write-Log "Failed to install uv, falling back to pip" "WARNING" + $script:UseUv = $false + } +} + function New-Directories { Write-Log "Creating directories..." if (-not (Test-Path $HF_CLI_DIR)) { New-Item -ItemType Directory -Path $HF_CLI_DIR -Force | Out-Null } @@ -200,38 +264,45 @@ function New-VirtualEnvironment { } } - # Fail fast when venv module is unavailable - try { + if ($script:UseUv) { + $uvArgs = @('venv', $VENV_DIR) + if ($script:LogLevel -lt 2) { + $uvArgs += '--quiet' + } + + & $script:UvCmd @uvArgs + if (-not $?) { throw "Failed to create virtual environment with uv" } + } + else { + try { + if ($PythonCmd -eq "py -3") { + & py -3 -c "import venv" | Out-Null + } else { + & $PythonCmd -c "import venv" | Out-Null + } + } catch { + Write-Log "Python installation is missing the venv module." "ERROR" + Write-Log "Install the optional venv feature or repair Python before retrying." "ERROR" + Write-Log "Microsoft Store Python: Repair via Apps settings" "INFO" + Write-Log "python.org installer: Choose 'Modify' and enable 'pip/venv'." "INFO" + throw "Python venv module unavailable" + } + if ($PythonCmd -eq "py -3") { - & py -3 -c "import venv" | Out-Null + & py -3 -m venv $VENV_DIR } else { - & $PythonCmd -c "import venv" | Out-Null + & $PythonCmd -m venv $VENV_DIR } - } catch { - Write-Log "Python installation is missing the venv module." "ERROR" - Write-Log "Install the optional venv feature or repair Python before retrying." "ERROR" - Write-Log "Microsoft Store Python: Repair via Apps settings" "INFO" - Write-Log "python.org installer: Choose 'Modify' and enable 'pip/venv'." "INFO" - throw "Python venv module unavailable" - } + if (-not $?) { throw "Failed to create virtual environment" } - # Create virtual environment - if ($PythonCmd -eq "py -3") { - & py -3 -m venv $VENV_DIR - } else { - & $PythonCmd -m venv $VENV_DIR + $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" + Write-Log "Upgrading pip..." + & $script:VenvPython -m pip install --upgrade pip + if (-not $?) { throw "Failed to upgrade pip" } } - if (-not $?) { throw "Failed to create virtual environment" } - # Mark this installation as installer-managed $markerFile = Join-Path $VENV_DIR ".hf_installer_marker" New-Item -Path $markerFile -ItemType File -Force | Out-Null - - # Use the venv's python -m pip for deterministic upgrades - $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" - Write-Log "Upgrading pip..." - & $script:VenvPython -m pip install --upgrade pip - if (-not $?) { throw "Failed to upgrade pip" } } function Install-HuggingFaceHub { @@ -243,23 +314,35 @@ function Install-HuggingFaceHub { } else { Write-Log "Installing The Hugging Face CLI (latest)..." } - if (-not $script:VenvPython) { $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" } - - # Allow optional pip arguments via HF_CLI_PIP_ARGS/HF_PIP_ARGS env vars - $extraArgsRaw = if ($env:HF_CLI_PIP_ARGS) { $env:HF_CLI_PIP_ARGS } else { $env:HF_PIP_ARGS } - $pipArgs = @('-m', 'pip', 'install', '--upgrade') - if ($env:HF_CLI_VERBOSE_PIP -ne '1') { - $pipArgs += @('--quiet', '--progress-bar', 'off', '--disable-pip-version-check') - Write-Log "(pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs)" - } - $pipArgs += $packageSpec - if ($extraArgsRaw) { - Write-Log "Passing extra pip arguments: $extraArgsRaw" - $pipArgs += $extraArgsRaw -split '\s+' + + if ($script:UseUv) { + if (-not $script:VenvPython) { $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" } + + $uvArgs = @('pip', 'install', '--python', $script:VenvPython, $packageSpec) + if ($env:HF_CLI_VERBOSE_PIP -ne '1') { + $uvArgs += '--quiet' + } + + & $script:UvCmd @uvArgs + if (-not $?) { throw "Failed to install huggingface_hub with uv" } } + else { + if (-not $script:VenvPython) { $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" } + + $extraArgsRaw = if ($env:HF_CLI_PIP_ARGS) { $env:HF_CLI_PIP_ARGS } else { $env:HF_PIP_ARGS } + $pipArgs = @('-m', 'pip', 'install', '--upgrade') + if ($env:HF_CLI_VERBOSE_PIP -ne '1') { + $pipArgs += @('--quiet', '--progress-bar', 'off', '--disable-pip-version-check') + } + $pipArgs += $packageSpec + if ($extraArgsRaw) { + Write-Log "Passing extra pip arguments: $extraArgsRaw" + $pipArgs += $extraArgsRaw -split '\s+' + } - & $script:VenvPython @pipArgs - if (-not $?) { throw "Failed to install huggingface_hub" } + & $script:VenvPython @pipArgs + if (-not $?) { throw "Failed to install huggingface_hub" } + } } function Publish-HfCommand { @@ -285,7 +368,6 @@ function Publish-HfCommand { function Update-Path { Write-Log "Checking PATH configuration..." - # Get current user PATH $currentPath = [Environment]::GetEnvironmentVariable("PATH", "User") if ($currentPath -notlike "*$BIN_DIR*") { @@ -295,12 +377,10 @@ function Update-Path { $newPath = "$BIN_DIR;" + $currentPath [Environment]::SetEnvironmentVariable("PATH", $newPath, "User") - # Update PATH for current session $env:PATH = "$BIN_DIR;$env:PATH" Write-Log "Added $BIN_DIR to PATH. Changes will take effect in new terminals." "SUCCESS" Write-Log "Current PowerShell session already includes hf after this update." "INFO" - Write-Log "Undo later via Settings ▸ Environment Variables, or: [Environment]::SetEnvironmentVariable(`"PATH`", ($([Environment]::GetEnvironmentVariable('PATH','User')) -replace [regex]::Escape(`"$BIN_DIR;`"), ''), 'User')" "INFO" $script:PathUpdated = $true } catch { @@ -321,7 +401,6 @@ function Test-Installation { if (Test-Path $hfExecutable) { try { - # Test the CLI $output = & $hfExecutable version 2>&1 if ($?) { Write-Log "CLI location: $hfExecutable" @@ -347,8 +426,8 @@ function Show-UninstallInfo { Write-Log "" Write-Log "To uninstall the Hugging Face CLI:" Write-Log " Remove-Item -Path '$HF_CLI_DIR' -Recurse -Force" - Write-Log " Remove-Item -Path '$BIN_DIR\\hf.exe'" - Write-Log " Remove-Item -Path '$BIN_DIR\\hf-script.py' (if present)" + Write-Log " Remove-Item -Path '$BIN_DIR\hf.exe'" + Write-Log " Remove-Item -Path '$BIN_DIR\hf-script.py' (if present)" Write-Log "" if ($script:PathUpdated) { Write-Log "Remove '$BIN_DIR' from your user PATH via Settings ▸ Environment Variables," "INFO" @@ -375,13 +454,13 @@ function Show-Usage { Write-Log (' & "{0}" --help' -f $hfExecutable) } -# Main installation process function Main { try { Write-Log "Installing Hugging Face CLI for Windows..." Write-Log "PowerShell version: $($PSVersionTable.PSVersion)" $pythonCmd = Find-Python + Install-Uv New-Directories New-VirtualEnvironment -PythonCmd $pythonCmd Install-HuggingFaceHub @@ -411,11 +490,9 @@ function Main { } } -# Handle Ctrl+C $null = Register-ObjectEvent -InputObject ([Console]) -EventName CancelKeyPress -Action { Write-Log "Installation interrupted" "ERROR" exit 130 } -# Run main function Main From 826655204bbc040e11da8a9533d560da265e47a0 Mon Sep 17 00:00:00 2001 From: Youssef Boulaouane Date: Sat, 8 Nov 2025 04:05:38 +0900 Subject: [PATCH 3/7] Address PR feedback Removed newly added paramters Put back comments Use uv only if installed Do not create venv with uv --- utils/installers/install.ps1 | 160 ++++++++++----------------------- utils/installers/install.sh | 167 ++++++++++++----------------------- 2 files changed, 105 insertions(+), 222 deletions(-) diff --git a/utils/installers/install.ps1 b/utils/installers/install.ps1 index ea67b33559..c087fee751 100644 --- a/utils/installers/install.ps1 +++ b/utils/installers/install.ps1 @@ -13,14 +13,11 @@ Downloads and installs the `huggingface_hub` package into a dedicated virtual en Recreates the virtual environment even if it already exists. Off by default. .PARAMETER Verbose -Enables verbose output, including detailed logs. +Enables verbose output, including detailed pip logs. .PARAMETER NoModifyPath Skips PATH modifications; `hf` must be invoked via its full path unless you add it manually. -.PARAMETER NoUv -Use pip instead of uv for package installation. - .EXAMPLE powershell -c "irm https://hf.co/cli/install.ps1 | iex" #> @@ -31,28 +28,25 @@ Environment variables: HF_HOME Installation base directory; installer uses $env:HF_HOME\cli when set HF_CLI_BIN_DIR Directory for the hf wrapper (default: $env:USERPROFILE\.local\bin) HF_CLI_VERSION Install a specific huggingface_hub version (default: latest) - HF_CLI_USE_UV Use uv for package installation (default: true) #> param( [switch]$Force = $false, [switch]$Verbose, - [switch]$NoModifyPath, - [switch]$NoUv + [switch]$NoModifyPath ) $script:LogLevel = if ($Verbose) { 2 } else { 1 } $script:PathUpdated = $false -$script:UseUv = if ($NoUv) { $false } elseif ($env:HF_CLI_USE_UV -eq 'false') { $false } else { $true } -$script:UvInstalled = $false -$script:UvCmd = $null if ($Verbose) { $env:HF_CLI_VERBOSE_PIP = '1' } +# Set error action preference $ErrorActionPreference = "Stop" +# Colors for output $Colors = @{ Red = 'Red' Green = 'Green' @@ -89,6 +83,7 @@ function Write-Log { } } +# Normalize user-supplied paths function Resolve-CliPath { param([string]$Path) @@ -112,6 +107,7 @@ function Resolve-CliPath { return [System.IO.Path]::GetFullPath((Join-Path $base $expanded)) } +# Compose installer directories using environment variables only if ($env:HF_HOME) { $HF_CLI_DIR = Resolve-CliPath (Join-Path $env:HF_HOME "cli") } else { @@ -140,7 +136,7 @@ function Test-PythonVersion { $version = & $PythonCmd --version 2>&1 if ($version -match "Python 3\.(\d+)\.") { $minorVersion = [int]$matches[1] - return $minorVersion -ge 9 + return $minorVersion -ge 9 # Python 3.9+ } return $false } catch { return $false } @@ -149,6 +145,7 @@ function Test-PythonVersion { function Find-Python { Write-Log "Looking for Python 3.9+ installation..." + # Try common Python commands $pythonCommands = @("python", "python3", "py") foreach ($cmd in $pythonCommands) { @@ -161,6 +158,7 @@ function Find-Python { } } + # Try Python Launcher for Windows if (Test-Command "py") { try { $version = py -3 --version 2>&1 @@ -180,68 +178,6 @@ function Find-Python { throw "Python 3.9+ not found" } -function Install-Uv { - if (-not $script:UseUv) { - Write-Log "Using pip for package installation" - return - } - - if (Test-Command "uv") { - try { - $uvVersion = & uv --version 2>&1 - $script:UvCmd = "uv" - Write-Log "Using uv: $uvVersion" - return - } catch { } - } - - Write-Log "Installing uv package manager..." - - try { - $uvInstaller = Join-Path $env:TEMP "uv-installer.ps1" - - if (Test-Command "curl") { - & curl -LsSf https://astral.sh/uv/install.ps1 -o $uvInstaller 2>$null - } else { - Invoke-WebRequest -Uri "https://astral.sh/uv/install.ps1" -OutFile $uvInstaller -UseBasicParsing - } - - if (-not (Test-Path $uvInstaller)) { - Write-Log "Failed to download uv installer, falling back to pip" "WARNING" - $script:UseUv = $false - return - } - - $env:INSTALLER_NO_MODIFY_PATH = "1" - & powershell -ExecutionPolicy ByPass -File $uvInstaller *>$null - - Remove-Item -Path $uvInstaller -Force -ErrorAction SilentlyContinue - - $uvLocations = @( - (Join-Path $env:USERPROFILE ".cargo\bin\uv.exe"), - (Join-Path $env:USERPROFILE ".local\bin\uv.exe"), - "C:\Program Files\uv\uv.exe" - ) - - foreach ($location in $uvLocations) { - if (Test-Path $location) { - $script:UvCmd = $location - $script:UvInstalled = $true - $uvVersion = & $script:UvCmd --version 2>&1 - Write-Log "uv installed: $uvVersion" - return - } - } - - Write-Log "uv installation completed but command not found, falling back to pip" "WARNING" - $script:UseUv = $false - } - catch { - Write-Log "Failed to install uv, falling back to pip" "WARNING" - $script:UseUv = $false - } -} - function New-Directories { Write-Log "Creating directories..." if (-not (Test-Path $HF_CLI_DIR)) { New-Item -ItemType Directory -Path $HF_CLI_DIR -Force | Out-Null } @@ -264,45 +200,38 @@ function New-VirtualEnvironment { } } - if ($script:UseUv) { - $uvArgs = @('venv', $VENV_DIR) - if ($script:LogLevel -lt 2) { - $uvArgs += '--quiet' - } - - & $script:UvCmd @uvArgs - if (-not $?) { throw "Failed to create virtual environment with uv" } - } - else { - try { - if ($PythonCmd -eq "py -3") { - & py -3 -c "import venv" | Out-Null - } else { - & $PythonCmd -c "import venv" | Out-Null - } - } catch { - Write-Log "Python installation is missing the venv module." "ERROR" - Write-Log "Install the optional venv feature or repair Python before retrying." "ERROR" - Write-Log "Microsoft Store Python: Repair via Apps settings" "INFO" - Write-Log "python.org installer: Choose 'Modify' and enable 'pip/venv'." "INFO" - throw "Python venv module unavailable" - } - + # Fail fast when venv module is unavailable + try { if ($PythonCmd -eq "py -3") { - & py -3 -m venv $VENV_DIR + & py -3 -c "import venv" | Out-Null } else { - & $PythonCmd -m venv $VENV_DIR + & $PythonCmd -c "import venv" | Out-Null } - if (-not $?) { throw "Failed to create virtual environment" } + } catch { + Write-Log "Python installation is missing the venv module." "ERROR" + Write-Log "Install the optional venv feature or repair Python before retrying." "ERROR" + Write-Log "Microsoft Store Python: Repair via Apps settings" "INFO" + Write-Log "python.org installer: Choose 'Modify' and enable 'pip/venv'." "INFO" + throw "Python venv module unavailable" + } - $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" - Write-Log "Upgrading pip..." - & $script:VenvPython -m pip install --upgrade pip - if (-not $?) { throw "Failed to upgrade pip" } + # Create virtual environment + if ($PythonCmd -eq "py -3") { + & py -3 -m venv $VENV_DIR + } else { + & $PythonCmd -m venv $VENV_DIR } + if (-not $?) { throw "Failed to create virtual environment" } + # Mark this installation as installer-managed $markerFile = Join-Path $VENV_DIR ".hf_installer_marker" New-Item -Path $markerFile -ItemType File -Force | Out-Null + + # Use the venv's python -m pip for deterministic upgrades + $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" + Write-Log "Upgrading pip..." + & $script:VenvPython -m pip install --upgrade pip + if (-not $?) { throw "Failed to upgrade pip" } } function Install-HuggingFaceHub { @@ -314,25 +243,26 @@ function Install-HuggingFaceHub { } else { Write-Log "Installing The Hugging Face CLI (latest)..." } + if (-not $script:VenvPython) { $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" } - if ($script:UseUv) { - if (-not $script:VenvPython) { $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" } - + # Check if uv is available and use it for faster installation + if (Test-Command "uv") { + Write-Log "Using uv for faster installation" $uvArgs = @('pip', 'install', '--python', $script:VenvPython, $packageSpec) if ($env:HF_CLI_VERBOSE_PIP -ne '1') { $uvArgs += '--quiet' } - & $script:UvCmd @uvArgs + & uv @uvArgs if (-not $?) { throw "Failed to install huggingface_hub with uv" } } else { - if (-not $script:VenvPython) { $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" } - + # Allow optional pip arguments via HF_CLI_PIP_ARGS/HF_PIP_ARGS env vars $extraArgsRaw = if ($env:HF_CLI_PIP_ARGS) { $env:HF_CLI_PIP_ARGS } else { $env:HF_PIP_ARGS } $pipArgs = @('-m', 'pip', 'install', '--upgrade') if ($env:HF_CLI_VERBOSE_PIP -ne '1') { $pipArgs += @('--quiet', '--progress-bar', 'off', '--disable-pip-version-check') + Write-Log "(pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs)" } $pipArgs += $packageSpec if ($extraArgsRaw) { @@ -368,6 +298,7 @@ function Publish-HfCommand { function Update-Path { Write-Log "Checking PATH configuration..." + # Get current user PATH $currentPath = [Environment]::GetEnvironmentVariable("PATH", "User") if ($currentPath -notlike "*$BIN_DIR*") { @@ -377,10 +308,12 @@ function Update-Path { $newPath = "$BIN_DIR;" + $currentPath [Environment]::SetEnvironmentVariable("PATH", $newPath, "User") + # Update PATH for current session $env:PATH = "$BIN_DIR;$env:PATH" Write-Log "Added $BIN_DIR to PATH. Changes will take effect in new terminals." "SUCCESS" Write-Log "Current PowerShell session already includes hf after this update." "INFO" + Write-Log "Undo later via Settings ▸ Environment Variables, or: [Environment]::SetEnvironmentVariable(`"PATH`", ($([Environment]::GetEnvironmentVariable('PATH','User')) -replace [regex]::Escape(`"$BIN_DIR;`"), ''), 'User')" "INFO" $script:PathUpdated = $true } catch { @@ -401,6 +334,7 @@ function Test-Installation { if (Test-Path $hfExecutable) { try { + # Test the CLI $output = & $hfExecutable version 2>&1 if ($?) { Write-Log "CLI location: $hfExecutable" @@ -454,13 +388,13 @@ function Show-Usage { Write-Log (' & "{0}" --help' -f $hfExecutable) } +# Main installation process function Main { try { Write-Log "Installing Hugging Face CLI for Windows..." Write-Log "PowerShell version: $($PSVersionTable.PSVersion)" $pythonCmd = Find-Python - Install-Uv New-Directories New-VirtualEnvironment -PythonCmd $pythonCmd Install-HuggingFaceHub @@ -490,9 +424,11 @@ function Main { } } +# Handle Ctrl+C $null = Register-ObjectEvent -InputObject ([Console]) -EventName CancelKeyPress -Action { Write-Log "Installation interrupted" "ERROR" exit 130 } -Main +# Run main function +Main \ No newline at end of file diff --git a/utils/installers/install.sh b/utils/installers/install.sh index cc598b0ce9..ffe39c737f 100755 --- a/utils/installers/install.sh +++ b/utils/installers/install.sh @@ -25,23 +25,25 @@ fi set -e +# Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' -NC='\033[0m' +NC='\033[0m' # No Color +# Logging level: 0=quiet, 1=info (default), 2=verbose LOG_LEVEL=1 +# Configuration FORCE_REINSTALL="false" BIN_DIR="${HF_CLI_BIN_DIR:-$HOME/.local/bin}" UPDATED_RC_FILE="" REQUESTED_VERSION="${HF_CLI_VERSION:-}" SKIP_PATH_UPDATE="false" UPDATED_FISH_PATH="false" -USE_UV="${HF_CLI_USE_UV:-true}" -UV_INSTALLED="false" +# Logging functions log_debug() { if [ "$LOG_LEVEL" -lt 2 ]; then return 0 @@ -90,18 +92,17 @@ Usage: curl -LsSf https://hf.co/cli/install.sh | sh -s -- [OPTIONS] Options: --force Recreate the Hugging Face CLI virtual environment if it exists --no-modify-path Skip adding the hf wrapper directory to PATH - --no-uv Use pip instead of uv for package installation - -v, --verbose Enable verbose output + -v, --verbose Enable verbose output (includes full pip logs) --help, -h Show this message and exit Environment variables: HF_HOME Installation base directory; installer uses $HF_HOME/cli when set HF_CLI_BIN_DIR Directory for the hf wrapper (default: ~/.local/bin) HF_CLI_VERSION Install a specific huggingface_hub version (default: latest) - HF_CLI_USE_UV Use uv for package installation (default: true) EOF } +# Normalize user paths to absolute paths expand_path() { local input="$1" if [ -z "$input" ]; then @@ -132,9 +133,6 @@ while [ $# -gt 0 ]; do --no-modify-path) SKIP_PATH_UPDATE="true" ;; - --no-uv) - USE_UV="false" - ;; -v|--verbose) LOG_LEVEL=2 HF_CLI_VERBOSE_PIP=1 @@ -152,6 +150,7 @@ while [ $# -gt 0 ]; do shift done +# Persist fully resolved paths for downstream use and wrapper creation BIN_DIR=$(expand_path "$BIN_DIR") if [ -n "$HF_HOME" ]; then @@ -163,10 +162,12 @@ fi HF_CLI_DIR=$(expand_path "$HF_CLI_DIR") VENV_DIR="$HF_CLI_DIR/venv" +# Check if command exists command_exists() { command -v "$1" >/dev/null 2>&1 } +# Detect OS detect_os() { if [[ "$OSTYPE" == "linux-gnu"* ]]; then echo "linux" @@ -177,6 +178,7 @@ detect_os() { fi } +# Install Python if not available python_version_supported() { "$1" <<'PY' >/dev/null 2>&1 import sys @@ -210,7 +212,7 @@ ensure_python() { ;; linux) if command_exists apt-get || command_exists apt; then - log_info "On Debian/Ubuntu: sudo apt update && sudo apt install python3 python3-pip python3-venv" + log_info "On Debian/Ubuntu: sudo apt update && sudo apt install python3 python3-pip" elif command_exists dnf; then log_info "On Fedora/RHEL: sudo dnf install python3 python3-pip" elif command_exists yum; then @@ -229,77 +231,14 @@ ensure_python() { log_info "Using Python: $($PYTHON_CMD --version)" } -ensure_uv() { - if [ "$USE_UV" != "true" ]; then - log_info "Using pip for package installation" - return - fi - - if command_exists uv; then - UV_CMD="uv" - log_info "Using uv: $(uv --version 2>&1 || echo 'version unknown')" - return - fi - - log_info "Installing uv package manager..." - - local uv_installer=$(mktemp) - if command_exists curl; then - if ! curl -LsSf https://astral.sh/uv/install.sh -o "$uv_installer" 2>/dev/null; then - log_warning "Failed to download uv installer, falling back to pip" - USE_UV="false" - rm -f "$uv_installer" - return - fi - elif command_exists wget; then - if ! wget -qO "$uv_installer" https://astral.sh/uv/install.sh 2>/dev/null; then - log_warning "Failed to download uv installer, falling back to pip" - USE_UV="false" - rm -f "$uv_installer" - return - fi - else - log_warning "curl or wget not found, falling back to pip" - USE_UV="false" - return - fi - - chmod +x "$uv_installer" - - export INSTALLER_NO_MODIFY_PATH=1 - if ! sh "$uv_installer" >/dev/null 2>&1; then - log_warning "Failed to install uv, falling back to pip" - USE_UV="false" - rm -f "$uv_installer" - return - fi - rm -f "$uv_installer" - - local uv_locations=( - "$HOME/.cargo/bin/uv" - "$HOME/.local/bin/uv" - "/usr/local/bin/uv" - ) - - for location in "${uv_locations[@]}"; do - if [ -x "$location" ]; then - UV_CMD="$location" - UV_INSTALLED="true" - log_info "uv installed: $($UV_CMD --version)" - return - fi - done - - log_warning "uv installation completed but command not found, falling back to pip" - USE_UV="false" -} - +# Create directories create_directories() { log_info "Creating directories..." run_command "Failed to create install directory $HF_CLI_DIR" mkdir -p "$HF_CLI_DIR" run_command "Failed to create bin directory $BIN_DIR" mkdir -p "$BIN_DIR" } +# Create virtual environment create_venv() { log_info "Creating virtual environment..." if [ -d "$VENV_DIR" ]; then @@ -312,39 +251,32 @@ create_venv() { fi fi - if [ "$USE_UV" = "true" ]; then - local uv_args=() - if [ "$LOG_LEVEL" -ge 2 ]; then - uv_args+=(--verbose) - else - uv_args+=(--quiet) - fi - - run_command "Failed to create virtual environment at $VENV_DIR" "$UV_CMD" venv "${uv_args[@]}" --python "$PYTHON_CMD" "$VENV_DIR" - else - if ! "$PYTHON_CMD" -m venv --help >/dev/null 2>&1; then - log_error "Python's venv module is unavailable. Install python3-venv and retry." - case "$(detect_os)" in - linux) - log_info "Try: sudo apt install python3-venv # Debian/Ubuntu" - log_info " sudo dnf install python3-venv # Fedora" - ;; - macos) - log_info "Try reinstalling Python via Homebrew: brew install python" - ;; - esac - exit 1 - fi - - run_command "Failed to create virtual environment at $VENV_DIR" "$PYTHON_CMD" -m venv "$VENV_DIR" - - log_info "Upgrading pip..." - run_command "Failed to upgrade pip" "$VENV_DIR/bin/python" -m pip install --upgrade pip + # Fail early with guidance when python lacks the venv module + if ! "$PYTHON_CMD" -m venv --help >/dev/null 2>&1; then + log_error "Python's venv module is unavailable. Install python3-venv / ensurepip and retry." + case "$(detect_os)" in + linux) + log_info "Try: sudo apt install python3-venv # Debian/Ubuntu" + log_info " sudo dnf install python3-venv # Fedora" + ;; + macos) + log_info "Try reinstalling Python via Homebrew: brew install python" + ;; + esac + exit 1 fi + run_command "Failed to create virtual environment at $VENV_DIR" "$PYTHON_CMD" -m venv "$VENV_DIR" + + # Mark this installation as installer-managed touch "$VENV_DIR/.hf_installer_marker" + + # Use the venv python for pip management + log_info "Upgrading pip..." + run_command "Failed to upgrade pip" "$VENV_DIR/bin/python" -m pip install --upgrade pip } +# Install huggingface_hub with CLI extras install_hf_hub() { local package_spec="huggingface_hub" if [ -n "$REQUESTED_VERSION" ]; then @@ -354,13 +286,17 @@ install_hf_hub() { log_info "Installing The Hugging Face CLI (latest)..." fi - if [ "$USE_UV" = "true" ]; then - local -a uv_flags=() - if [ "${HF_CLI_VERBOSE_PIP:-}" != "1" ]; then - uv_flags+=(--quiet) + # Check if uv is available and use it for faster installation + if command_exists uv; then + log_info "Using uv for faster installation" + local -a uv_flags + if [ "${HF_CLI_VERBOSE_PIP:-}" = "1" ]; then + uv_flags=() + else + uv_flags=(--quiet) fi - run_command "Failed to install $package_spec" "$UV_CMD" pip install --python "$VENV_DIR/bin/python" "${uv_flags[@]}" "$package_spec" + run_command "Failed to install $package_spec" uv pip install --python "$VENV_DIR/bin/python" ${uv_flags[*]} "$package_spec" else local extra_pip_args="${HF_CLI_PIP_ARGS:-${HF_PIP_ARGS:-}}" local -a pip_flags @@ -374,6 +310,10 @@ install_hf_hub() { log_info "Passing extra pip arguments: $extra_pip_args" fi + if [ "${HF_CLI_VERBOSE_PIP:-}" != "1" ]; then + log_info "(pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs)" + fi + if [ -n "$extra_pip_args" ]; then # shellcheck disable=SC2086 run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} $extra_pip_args @@ -384,6 +324,7 @@ install_hf_hub() { fi } +# Expose the hf CLI by linking or copying the console script from the virtualenv expose_cli_command() { log_info "Linking hf CLI into $BIN_DIR..." @@ -416,10 +357,12 @@ expose_cli_command() { log_info "Run without touching PATH: env PATH=\"$BIN_DIR:\$PATH\" hf --help" } +# Update PATH if needed update_path() { local shell_rc="" local -a shell_rc_candidates=() + # Broaden shell detection and guidance for PATH propagation case "$SHELL" in */bash) shell_rc_candidates=() @@ -502,10 +445,12 @@ update_path() { fi } +# Verify installation verify_installation() { log_info "Verifying installation..." if [ -x "$BIN_DIR/hf" ]; then + # Test the CLI if "$BIN_DIR/hf" version >/dev/null 2>&1; then log_success "Hugging Face CLI installed successfully!" log_info "CLI location: $BIN_DIR/hf" @@ -520,6 +465,7 @@ verify_installation() { fi } +# Uninstall function show_uninstall_info() { log_info "" log_info "To uninstall the Hugging Face CLI, run:" @@ -537,6 +483,7 @@ show_uninstall_info() { fi } +# Main installation process main() { log_info "Installing Hugging Face CLI..." log_info "OS: $(detect_os)" @@ -547,7 +494,6 @@ main() { log_info "Skip PATH update: $SKIP_PATH_UPDATE" ensure_python - ensure_uv create_directories create_venv install_hf_hub @@ -575,6 +521,7 @@ main() { log_info "" } +# Handle Ctrl+C trap 'log_error "Installation interrupted"; exit 130' INT -main "$@" +main "$@" \ No newline at end of file From 573de80cddece1043d6e6e6f018b0ae928d4c889 Mon Sep 17 00:00:00 2001 From: Lucain Date: Thu, 13 Nov 2025 16:20:37 +0100 Subject: [PATCH 4/7] Update utils/installers/install.sh --- utils/installers/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/installers/install.sh b/utils/installers/install.sh index 2ed62b5bfd..ad9c0ac348 100755 --- a/utils/installers/install.sh +++ b/utils/installers/install.sh @@ -525,4 +525,4 @@ main() { # Handle Ctrl+C trap 'log_error "Installation interrupted"; exit 130' INT -main "$@" \ No newline at end of file +main "$@" From c229d368b65213090a30adbd03eb08cf62fe5f2b Mon Sep 17 00:00:00 2001 From: Lucain Date: Thu, 13 Nov 2025 16:20:46 +0100 Subject: [PATCH 5/7] Update utils/installers/install.ps1 --- utils/installers/install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/installers/install.ps1 b/utils/installers/install.ps1 index c087fee751..3a8f6835d3 100644 --- a/utils/installers/install.ps1 +++ b/utils/installers/install.ps1 @@ -431,4 +431,4 @@ $null = Register-ObjectEvent -InputObject ([Console]) -EventName CancelKeyPress } # Run main function -Main \ No newline at end of file +Main From cc68a4091ec4a37418d919462ede3c62f6dd21d6 Mon Sep 17 00:00:00 2001 From: Youssef Boulaoaune <43298428+Boulaouaney@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:37:41 +0900 Subject: [PATCH 6/7] Fix indentation for pip output suppression log --- utils/installers/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/installers/install.sh b/utils/installers/install.sh index ad9c0ac348..e37d30ad34 100755 --- a/utils/installers/install.sh +++ b/utils/installers/install.sh @@ -311,9 +311,9 @@ install_hf_hub() { log_info "Passing extra pip arguments: $extra_pip_args" fi - if [ "${HF_CLI_VERBOSE_PIP:-}" != "1" ]; then - log_info "pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs" - fi + if [ "${HF_CLI_VERBOSE_PIP:-}" != "1" ]; then + log_info "pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs" + fi if [ -n "$extra_pip_args" ]; then # shellcheck disable=SC2086 From f6d9d9653d36f9e92f302ed5c189992343daf8de Mon Sep 17 00:00:00 2001 From: Youssef Boulaoaune <43298428+Boulaouaney@users.noreply.github.com> Date: Wed, 19 Nov 2025 11:23:22 +0900 Subject: [PATCH 7/7] Refactor install scripts to unify uv/pip logic and fix argument passing --- utils/installers/install.ps1 | 26 +++++++++++++++++---- utils/installers/install.sh | 44 +++++++++++++++++------------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/utils/installers/install.ps1 b/utils/installers/install.ps1 index 3a8f6835d3..5ca2e6b8b6 100644 --- a/utils/installers/install.ps1 +++ b/utils/installers/install.ps1 @@ -245,28 +245,44 @@ function Install-HuggingFaceHub { } if (-not $script:VenvPython) { $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" } + $extraArgsRaw = if ($env:HF_CLI_PIP_ARGS) { $env:HF_CLI_PIP_ARGS } else { $env:HF_PIP_ARGS } + + if ($extraArgsRaw) { + Write-Log "Passing extra arguments: $extraArgsRaw" + } + + if ($env:HF_CLI_VERBOSE_PIP -ne '1') { + Write-Log "Installation output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs" + } + # Check if uv is available and use it for faster installation if (Test-Command "uv") { Write-Log "Using uv for faster installation" - $uvArgs = @('pip', 'install', '--python', $script:VenvPython, $packageSpec) + $uvArgs = @('pip', 'install', '--python', $script:VenvPython, '--upgrade') + if ($env:HF_CLI_VERBOSE_PIP -ne '1') { $uvArgs += '--quiet' } + + $uvArgs += $packageSpec + + if ($extraArgsRaw) { + $uvArgs += $extraArgsRaw -split '\s+' + } & uv @uvArgs if (-not $?) { throw "Failed to install huggingface_hub with uv" } } else { - # Allow optional pip arguments via HF_CLI_PIP_ARGS/HF_PIP_ARGS env vars - $extraArgsRaw = if ($env:HF_CLI_PIP_ARGS) { $env:HF_CLI_PIP_ARGS } else { $env:HF_PIP_ARGS } $pipArgs = @('-m', 'pip', 'install', '--upgrade') + if ($env:HF_CLI_VERBOSE_PIP -ne '1') { $pipArgs += @('--quiet', '--progress-bar', 'off', '--disable-pip-version-check') - Write-Log "(pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs)" } + $pipArgs += $packageSpec + if ($extraArgsRaw) { - Write-Log "Passing extra pip arguments: $extraArgsRaw" $pipArgs += $extraArgsRaw -split '\s+' } diff --git a/utils/installers/install.sh b/utils/installers/install.sh index e37d30ad34..5d04bc656d 100755 --- a/utils/installers/install.sh +++ b/utils/installers/install.sh @@ -287,41 +287,39 @@ install_hf_hub() { log_info "Installing The Hugging Face CLI (latest)..." fi + local extra_pip_args="${HF_CLI_PIP_ARGS:-${HF_PIP_ARGS:-}}" + local verbose="${HF_CLI_VERBOSE_PIP:-}" + + if [ -n "$extra_pip_args" ]; then + log_info "Passing extra arguments: $extra_pip_args" + fi + + if [ "$verbose" != "1" ]; then + log_info "Installation output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs" + fi + # Check if uv is available and use it for faster installation if command_exists uv; then log_info "Using uv for faster installation" local -a uv_flags - if [ "${HF_CLI_VERBOSE_PIP:-}" = "1" ]; then - uv_flags=() - else + if [ "$verbose" != "1" ]; then uv_flags=(--quiet) + else + uv_flags=() fi - run_command "Failed to install $package_spec" uv pip install --python "$VENV_DIR/bin/python" ${uv_flags[*]} "$package_spec" + # shellcheck disable=SC2086 + run_command "Failed to install $package_spec" uv pip install --python "$VENV_DIR/bin/python" --upgrade ${uv_flags[*]} "$package_spec" $extra_pip_args else - local extra_pip_args="${HF_CLI_PIP_ARGS:-${HF_PIP_ARGS:-}}" local -a pip_flags - if [ "${HF_CLI_VERBOSE_PIP:-}" = "1" ]; then - pip_flags=() - else + if [ "$verbose" != "1" ]; then pip_flags=(--quiet --progress-bar off --disable-pip-version-check) - fi - - if [ -n "$extra_pip_args" ]; then - log_info "Passing extra pip arguments: $extra_pip_args" - fi - - if [ "${HF_CLI_VERBOSE_PIP:-}" != "1" ]; then - log_info "pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs" - fi - - if [ -n "$extra_pip_args" ]; then - # shellcheck disable=SC2086 - run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} $extra_pip_args else - # shellcheck disable=SC2086 - run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} + pip_flags=() fi + + # shellcheck disable=SC2086 + run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} $extra_pip_args fi }