Skip to content

Commit 21edca8

Browse files
hanouticelinaWauplinCopilot
authored
Add cross-platform CLI Installers (#3378)
* [1.0] Httpx migration (#3328) * first httpx integration * more migration * some fixes * download workflow should work * Fix repocard and error utils tests * fix hf-file-system * gix http utils tests * more fixes * fix some inference tests * fix test_file_download tests * async inference client * async code should be good * Define RemoteEntryFileNotFound explicitly (+some fixes) * fix async code quality * torch ok * fix hf_file_system * fix errors tests * mock * fix test_cli mock * fix commit scheduler * add fileno test * no more requests anywhere * fix test_file_download * tmp requests * Update src/huggingface_hub/utils/_http.py Co-authored-by: célina <[email protected]> * Update src/huggingface_hub/utils/_http.py Co-authored-by: célina <[email protected]> * Update src/huggingface_hub/hf_file_system.py Co-authored-by: célina <[email protected]> * not async * fix tests --------- Co-authored-by: célina <[email protected]> * Bump minimal version to Python3.9 (#3343) * Bump minimal version to Python3.9 * use built-in generics * code quality * new batch * yet another btach * fix dataclass_with_extra * fix * keep Type for strict dataclasses * fix test * Remove `HfFolder` and `InferenceAPI` classes (#3344) * Remove HfFolder * Remove InferenceAPI * more recent gradio * bump pytest * fix python 3.9? * install gradio only on python 3.10+ * fix tests * fix tests * fix * [v1.0] Remove more deprecated stuff (#3345) * remove constants.-hf_cache_home * remove smoothly_deprecate_use_auth_token * remove get_token_permission * remove update_repo_visibility * remove is_write_action arg * remove write_permission arg from login methods * new parameter skip_if_logged_in in login methods * Remove resume_download / force_filename parameters * Remove deprecated local_dir_use_symlinks parameter * Remove deprecated language, library, task, tags from list_models * Return commit URL in upload_file/upload_folder (previously url to file/folder on the Hub) * fix upload_file/upload_folder tests * smoothly_deprecate_legacy_arguments everywhere * code quality * fix tests * fix xet tests * [v1.0] Remove `Repository` class (#3346) * Remove Repository class + adapt docs * remove fr git_vs_http * bump to 1.0.0.dev0 * Remove _deprecate_positional_args on login methods (#3349) * [v1.0] Remove imports kept only for backward compatibility (#3350) * Remove imports kept only for backward compatibility * fix tests * [v1.0] Remove keras2 utilities (#3352) * Remove keras2 utilities * remove keras from init * [v1.0] Remove anything tensorflow-related + deps (#3354) * Remove anything tensorflow-related + deps * init * fix tests * fix conflicts in tests * Release: v1.0.0.rc0 * [v1.0] Update "HTTP backend" docs + `git_vs_http` guide (#3357) * HTTP configuration docs * http configuration docs * refactored git_vs_http * fix import * fix docs? * Update docs/source/en/package_reference/utilities.md Co-authored-by: célina <[email protected]> --------- Co-authored-by: célina <[email protected]> * Refactor CLI implementation using Typer (#3372) * Refactor CLI implementation using Typer (#3365) * migrate CLI to typer * (#3364) disable rich in all cases * update tests * make typer-slim a required dep * use Annotated * fix linting issues * fix tests * refactoring * update docs * use built in types * fix mypy * call whoami directly * lint * Apply suggestions from code review Co-authored-by: Lucain <[email protected]> * import Annotated from typing * Use Enums * set verbosity globally * refactor scan cache and update version docstring * centralize where Typer is defined * no need for ... * rename enum * no need for extra param name * docstring * revert * centralize arguments and options definition * add library version when initializing HfApi * add auto-completion * sort commands alphabetically * suggestions * centralize jobs params and HfApi initialization * fix --------- Co-authored-by: Lucain <[email protected]> * update docs --------- Co-authored-by: Lucain <[email protected]> * add installers * fix windows * fix log * fix workflow? * fix workflow again * add debugging steps * fix * remove bin dir and install dir params * update workflow * remove version param * document usage * [1.0] Httpx migration (#3328) * first httpx integration * more migration * some fixes * download workflow should work * Fix repocard and error utils tests * fix hf-file-system * gix http utils tests * more fixes * fix some inference tests * fix test_file_download tests * async inference client * async code should be good * Define RemoteEntryFileNotFound explicitly (+some fixes) * fix async code quality * torch ok * fix hf_file_system * fix errors tests * mock * fix test_cli mock * fix commit scheduler * add fileno test * no more requests anywhere * fix test_file_download * tmp requests * Update src/huggingface_hub/utils/_http.py Co-authored-by: célina <[email protected]> * Update src/huggingface_hub/utils/_http.py Co-authored-by: célina <[email protected]> * Update src/huggingface_hub/hf_file_system.py Co-authored-by: célina <[email protected]> * not async * fix tests --------- Co-authored-by: célina <[email protected]> * Bump minimal version to Python3.9 (#3343) * Bump minimal version to Python3.9 * use built-in generics * code quality * new batch * yet another btach * fix dataclass_with_extra * fix * keep Type for strict dataclasses * fix test * Remove `HfFolder` and `InferenceAPI` classes (#3344) * Remove HfFolder * Remove InferenceAPI * more recent gradio * bump pytest * fix python 3.9? * install gradio only on python 3.10+ * fix tests * fix tests * fix * [v1.0] Remove more deprecated stuff (#3345) * remove constants.-hf_cache_home * remove smoothly_deprecate_use_auth_token * remove get_token_permission * remove update_repo_visibility * remove is_write_action arg * remove write_permission arg from login methods * new parameter skip_if_logged_in in login methods * Remove resume_download / force_filename parameters * Remove deprecated local_dir_use_symlinks parameter * Remove deprecated language, library, task, tags from list_models * Return commit URL in upload_file/upload_folder (previously url to file/folder on the Hub) * fix upload_file/upload_folder tests * smoothly_deprecate_legacy_arguments everywhere * code quality * fix tests * fix xet tests * [v1.0] Remove `Repository` class (#3346) * Remove Repository class + adapt docs * remove fr git_vs_http * bump to 1.0.0.dev0 * Remove _deprecate_positional_args on login methods (#3349) * [v1.0] Remove imports kept only for backward compatibility (#3350) * Remove imports kept only for backward compatibility * fix tests * [v1.0] Remove keras2 utilities (#3352) * Remove keras2 utilities * remove keras from init * [v1.0] Remove anything tensorflow-related + deps (#3354) * Remove anything tensorflow-related + deps * init * fix tests * fix conflicts in tests * Release: v1.0.0.rc0 * [v1.0] Update "HTTP backend" docs + `git_vs_http` guide (#3357) * HTTP configuration docs * http configuration docs * refactored git_vs_http * fix import * fix docs? * Update docs/source/en/package_reference/utilities.md Co-authored-by: célina <[email protected]> --------- Co-authored-by: célina <[email protected]> * Refactor CLI implementation using Typer (#3372) * Refactor CLI implementation using Typer (#3365) * migrate CLI to typer * (#3364) disable rich in all cases * update tests * make typer-slim a required dep * use Annotated * fix linting issues * fix tests * refactoring * update docs * use built in types * fix mypy * call whoami directly * lint * Apply suggestions from code review Co-authored-by: Lucain <[email protected]> * import Annotated from typing * Use Enums * set verbosity globally * refactor scan cache and update version docstring * centralize where Typer is defined * no need for ... * rename enum * no need for extra param name * docstring * revert * centralize arguments and options definition * add library version when initializing HfApi * add auto-completion * sort commands alphabetically * suggestions * centralize jobs params and HfApi initialization * fix --------- Co-authored-by: Lucain <[email protected]> * update docs --------- Co-authored-by: Lucain <[email protected]> * Make HfHubHTTPError inherit from OSError (#3387) * Release: v1.0.0.rc1 * print relevant message based on the linux distro * better warning message * log info instead of warning * copilot suggestions * Update utils/installers/install.sh Co-authored-by: Copilot <[email protected]> * update docs --------- Co-authored-by: Lucain <[email protected]> Co-authored-by: Lucain Pouget <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent ee6c65a commit 21edca8

File tree

5 files changed

+1046
-0
lines changed

5 files changed

+1046
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Check CLI installers
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "utils/installers/**"
9+
- ".github/workflows/check-installers.yml"
10+
pull_request:
11+
paths:
12+
- "utils/installers/**"
13+
- ".github/workflows/check-installers.yml"
14+
workflow_dispatch: {}
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
linux-installer:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Run installer
27+
shell: bash
28+
run: |
29+
set -euo pipefail
30+
31+
HF_TEST_ROOT=$(mktemp -d)
32+
INSTALL_DIR="$HF_TEST_ROOT/install"
33+
BIN_DIR="$HF_TEST_ROOT/bin"
34+
35+
HF_HOME="$INSTALL_DIR" HF_CLI_BIN_DIR="$BIN_DIR" utils/installers/install.sh --no-modify-path
36+
37+
export PATH="$BIN_DIR:$PATH"
38+
39+
HF_VERSION_PATH="$HF_TEST_ROOT/hf-version.txt"
40+
hf version | tee "$HF_VERSION_PATH"
41+
if ! grep -Eq 'huggingface_hub version: [0-9]+(\.[0-9]+){1,2}' "$HF_VERSION_PATH"; then
42+
echo "hf version output missing huggingface_hub version" >&2
43+
cat "$HF_VERSION_PATH" >&2
44+
exit 1
45+
fi
46+
47+
NO_COLOR=1 hf --help
48+
49+
rm -rf "$HF_TEST_ROOT"
50+
51+
windows-installer:
52+
runs-on: windows-latest
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v4
56+
57+
- name: Run installer
58+
shell: pwsh
59+
run: |
60+
$hfTestRoot = Join-Path $env:TEMP ([System.Guid]::NewGuid().ToString())
61+
$installDir = Join-Path $hfTestRoot 'install'
62+
$binDir = Join-Path $hfTestRoot 'bin'
63+
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
64+
New-Item -ItemType Directory -Path $binDir -Force | Out-Null
65+
66+
$env:HF_HOME = $installDir
67+
$env:HF_CLI_BIN_DIR = $binDir
68+
& "$PWD/utils/installers/install.ps1" -NoModifyPath
69+
70+
$env:PATH = "$binDir;$env:PATH"
71+
72+
$hfVersionPath = Join-Path $hfTestRoot 'hf-version.txt'
73+
& hf.exe version | Tee-Object -FilePath $hfVersionPath
74+
if ($LASTEXITCODE -ne 0) {
75+
throw 'hf version failed'
76+
}
77+
if (-not (Select-String -Path $hfVersionPath -Pattern 'huggingface_hub version: [0-9]+(\.[0-9]+){1,2}')) {
78+
throw 'hf version output missing huggingface_hub version'
79+
}
80+
81+
$env:NO_COLOR = '1'
82+
& hf.exe --help
83+
if ($LASTEXITCODE -ne 0) {
84+
throw 'hf --help failed'
85+
}
86+
Remove-Item Env:NO_COLOR
87+
88+
Remove-Item -Path $hfTestRoot -Recurse -Force

docs/source/en/guides/cli.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ First of all, let's install the CLI:
1717
> [!TIP]
1818
> In the snippet above, we also installed the `[cli]` extra dependencies to make the user experience better, especially when using the `cache delete` command.
1919
20+
Alternatively, you can install the `hf` CLI with a single command:
21+
22+
On macOS and Linux:
23+
24+
```bash
25+
>>> curl -LsSf https://hf.co/install.sh | sh
26+
```
27+
28+
On Windows:
29+
30+
```powershell
31+
>>> powershell -c "irm https://hf.co/install.ps1 | iex"
32+
```
33+
2034
Once installed, you can check that the CLI is correctly setup:
2135

2236
```

docs/source/en/installation.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ Python will now look inside the folder you cloned to in addition to the normal l
103103
For example, if your Python packages are typically installed in `./.venv/lib/python3.13/site-packages/`,
104104
Python will also search the folder you cloned `./huggingface_hub/`.
105105

106+
## Install the Hugging Face CLI
107+
108+
Use our one-liner installers to set up the `hf` CLI without touching your Python environment:
109+
110+
On macOS and Linux:
111+
112+
```bash
113+
curl -LsSf https://hf.co/install.sh | sh
114+
```
115+
116+
On Windows:
117+
118+
```powershell
119+
powershell -c "irm https://hf.co/install.ps1 | iex"
120+
```
121+
106122
## Install with conda
107123

108124
If you are more familiar with it, you can install `huggingface_hub` using the [conda-forge channel](https://anaconda.org/conda-forge/huggingface_hub):

0 commit comments

Comments
 (0)