Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/huggingface_hub/cli/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def update() -> None:
out.text(f"hf is up to date ({__version__})")
return

# Windows refuses to replace the `hf.exe` launcher of a running process: pip would fail with a
# "file in use" error (WinError 32) *after* having uninstalled the current version, leaving a dead
# `hf.exe` and no `huggingface_hub` module behind. Print the command instead of running it, the same
# way pip refuses to upgrade itself on Windows.
if sys.platform == "win32" and installation_method() == "pip":
command = subprocess.list2cmdline([sys.executable, "-m", "pip", "install", "-U", "huggingface_hub"])
out.error(
"On Windows, a pip-installed `hf` cannot update itself: pip is not allowed to replace `hf.exe` while it "
f"is running. Run this command instead:\n {command}"
)
raise click.exceptions.Exit(code=1)

# The standalone installer installs the `hf-cli` skill by default. If it's not installed at this
# point, the user opted out (or removed it): tell the installer to leave it alone instead of
# silently undoing that choice.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5009,6 +5009,8 @@ def _mocked_update(self) -> Generator[Mock, None, None]:
with (
patch("huggingface_hub.cli.system._fetch_latest_pypi_version", return_value="99.0.0"),
patch("huggingface_hub.cli.system.subprocess.call", return_value=0),
# `hf update` refuses to self-update a pip install on Windows: pretend we're not on Windows.
patch("huggingface_hub.cli.system.sys.platform", "linux"),
patch("huggingface_hub.cli.system.run_update", return_value=0) as mock_run_update,
):
yield mock_run_update
Expand Down
Loading