Skip to content

Fix ~ user home not expanded in local_dir and cache_dir on file download#4293

Merged
Wauplin merged 1 commit into
mainfrom
fix-4292-cache-dir-not-resolved
May 29, 2026
Merged

Fix ~ user home not expanded in local_dir and cache_dir on file download#4293
Wauplin merged 1 commit into
mainfrom
fix-4292-cache-dir-not-resolved

Conversation

@Wauplin

@Wauplin Wauplin commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Fix #4292 cc @monkmonk99

When passing local_dir or cache_dir with a ~, the user home was not expanded, leading to errors down the line when downloading files. This PR fixes it by resolving cache_dir = str(Path(cache_dir).expanduser().resolve()) before any path manipulation.

I did not add a test as I wasn't sure how to properly do that (home user depends on the machine). I think it's fine like this.

Before / after

(main) ✗ hf download tiiuae/falcon-7b-instruct config.json --cache-dir "~/.local/huggingface/hub/"
Traceback (most recent call last):
(...)
  File "/home/wauplin/projects/huggingface_hub/src/huggingface_hub/file_download.py", line 677, in _create_symlink
    os.symlink(src_rel_or_abs, abs_dst)
FileNotFoundError: [Errno 2] No such file or directory: '../../blobs/84d8843072cbc300692c6bccff5b9c08c430498e' -> '/home/wauplin/.local/huggingface/hub/models--tiiuae--falcon-7b-instruct/snapshots/8782b5c5d8c9290412416618f36a133653e85285/config.json'

(main) ✗ git switch fix-4292-cache-dir-not-resolved                                               
Switched to branch 'fix-4292-cache-dir-not-resolved'
Your branch is up to date with 'origin/fix-4292-cache-dir-not-resolved'.

(fix-4292-cache-dir-not-resolved) ✗ hf download tiiuae/falcon-7b-instruct config.json --cache-dir "~/.local/huggingface/hub/"
config.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████| 1.05k/1.05k [00:00<00:00, 3.16MB/s]
✓ Downloaded
  path: /home/wauplin/.local/huggingface/hub/models--tiiuae--falcon-7b-instruct/snapshots/8782b5c5d8c9290412416618f36a133653e85285/config.json

@Wauplin Wauplin requested a review from hanouticelina May 29, 2026 07:39
@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@hanouticelina hanouticelina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@Wauplin Wauplin merged commit b686a47 into main May 29, 2026
24 of 26 checks passed
@Wauplin Wauplin deleted the fix-4292-cache-dir-not-resolved branch May 29, 2026 08:27
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.18.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When providing cache_dir to hf_hub_download, "~" in path is not expanded to users home directory.

2 participants