Skip to content

Commit a9bd7ed

Browse files
BoulaouaneyWauplin
andauthored
Add uv support to installation scripts for faster package installation (#3486)
* 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. * Enhance Windows installer with uv package manager support * Address PR feedback Removed newly added paramters Put back comments Use uv only if installed Do not create venv with uv * Update utils/installers/install.sh * Update utils/installers/install.ps1 * Fix indentation for pip output suppression log * Refactor install scripts to unify uv/pip logic and fix argument passing --------- Co-authored-by: Lucain <lucainp@gmail.com> Co-authored-by: Lucain <lucain@huggingface.co>
1 parent ec95611 commit a9bd7ed

File tree

2 files changed

+64
-24
lines changed

2 files changed

+64
-24
lines changed

utils/installers/install.ps1

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,50 @@ function Install-HuggingFaceHub {
245245
}
246246
if (-not $script:VenvPython) { $script:VenvPython = Join-Path $SCRIPTS_DIR "python.exe" }
247247

248-
# Allow optional pip arguments via HF_CLI_PIP_ARGS/HF_PIP_ARGS env vars
249248
$extraArgsRaw = if ($env:HF_CLI_PIP_ARGS) { $env:HF_CLI_PIP_ARGS } else { $env:HF_PIP_ARGS }
250-
$pipArgs = @('-m', 'pip', 'install', '--upgrade')
249+
250+
if ($extraArgsRaw) {
251+
Write-Log "Passing extra arguments: $extraArgsRaw"
252+
}
253+
251254
if ($env:HF_CLI_VERBOSE_PIP -ne '1') {
252-
$pipArgs += @('--quiet', '--progress-bar', 'off', '--disable-pip-version-check')
253-
Write-Log "(pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs)"
255+
Write-Log "Installation output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs"
254256
}
255-
$pipArgs += $packageSpec
256-
if ($extraArgsRaw) {
257-
Write-Log "Passing extra pip arguments: $extraArgsRaw"
258-
$pipArgs += $extraArgsRaw -split '\s+'
257+
258+
# Check if uv is available and use it for faster installation
259+
if (Test-Command "uv") {
260+
Write-Log "Using uv for faster installation"
261+
$uvArgs = @('pip', 'install', '--python', $script:VenvPython, '--upgrade')
262+
263+
if ($env:HF_CLI_VERBOSE_PIP -ne '1') {
264+
$uvArgs += '--quiet'
265+
}
266+
267+
$uvArgs += $packageSpec
268+
269+
if ($extraArgsRaw) {
270+
$uvArgs += $extraArgsRaw -split '\s+'
271+
}
272+
273+
& uv @uvArgs
274+
if (-not $?) { throw "Failed to install huggingface_hub with uv" }
259275
}
276+
else {
277+
$pipArgs = @('-m', 'pip', 'install', '--upgrade')
278+
279+
if ($env:HF_CLI_VERBOSE_PIP -ne '1') {
280+
$pipArgs += @('--quiet', '--progress-bar', 'off', '--disable-pip-version-check')
281+
}
282+
283+
$pipArgs += $packageSpec
284+
285+
if ($extraArgsRaw) {
286+
$pipArgs += $extraArgsRaw -split '\s+'
287+
}
260288

261-
& $script:VenvPython @pipArgs
262-
if (-not $?) { throw "Failed to install huggingface_hub" }
289+
& $script:VenvPython @pipArgs
290+
if (-not $?) { throw "Failed to install huggingface_hub" }
291+
}
263292
}
264293

265294
function Publish-HfCommand {
@@ -347,8 +376,8 @@ function Show-UninstallInfo {
347376
Write-Log ""
348377
Write-Log "To uninstall the Hugging Face CLI:"
349378
Write-Log " Remove-Item -Path '$HF_CLI_DIR' -Recurse -Force"
350-
Write-Log " Remove-Item -Path '$BIN_DIR\\hf.exe'"
351-
Write-Log " Remove-Item -Path '$BIN_DIR\\hf-script.py' (if present)"
379+
Write-Log " Remove-Item -Path '$BIN_DIR\hf.exe'"
380+
Write-Log " Remove-Item -Path '$BIN_DIR\hf-script.py' (if present)"
352381
Write-Log ""
353382
if ($script:PathUpdated) {
354383
Write-Log "Remove '$BIN_DIR' from your user PATH via Settings ▸ Environment Variables," "INFO"

utils/installers/install.sh

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,27 +288,38 @@ install_hf_hub() {
288288
fi
289289

290290
local extra_pip_args="${HF_CLI_PIP_ARGS:-${HF_PIP_ARGS:-}}"
291-
local -a pip_flags
292-
if [ "${HF_CLI_VERBOSE_PIP:-}" = "1" ]; then
293-
pip_flags=()
294-
else
295-
pip_flags=(--quiet --progress-bar off --disable-pip-version-check)
296-
fi
291+
local verbose="${HF_CLI_VERBOSE_PIP:-}"
297292

298293
if [ -n "$extra_pip_args" ]; then
299-
log_info "Passing extra pip arguments: $extra_pip_args"
294+
log_info "Passing extra arguments: $extra_pip_args"
300295
fi
301296

302-
if [ "${HF_CLI_VERBOSE_PIP:-}" != "1" ]; then
303-
log_info "pip output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs"
297+
if [ "$verbose" != "1" ]; then
298+
log_info "Installation output suppressed; set HF_CLI_VERBOSE_PIP=1 for full logs"
304299
fi
305300

306-
if [ -n "$extra_pip_args" ]; then
301+
# Check if uv is available and use it for faster installation
302+
if command_exists uv; then
303+
log_info "Using uv for faster installation"
304+
local -a uv_flags
305+
if [ "$verbose" != "1" ]; then
306+
uv_flags=(--quiet)
307+
else
308+
uv_flags=()
309+
fi
310+
307311
# shellcheck disable=SC2086
308-
run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} $extra_pip_args
312+
run_command "Failed to install $package_spec" uv pip install --python "$VENV_DIR/bin/python" --upgrade ${uv_flags[*]} "$package_spec" $extra_pip_args
309313
else
314+
local -a pip_flags
315+
if [ "$verbose" != "1" ]; then
316+
pip_flags=(--quiet --progress-bar off --disable-pip-version-check)
317+
else
318+
pip_flags=()
319+
fi
320+
310321
# shellcheck disable=SC2086
311-
run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]}
322+
run_command "Failed to install $package_spec" "$VENV_DIR/bin/python" -m pip install --upgrade "$package_spec" ${pip_flags[*]} $extra_pip_args
312323
fi
313324
}
314325

0 commit comments

Comments
 (0)