Skip to content

[Download] Warn when allow/ignore patterns match no files in snapshot_download - #5067

Merged
Wauplin merged 3 commits into
huggingface:mainfrom
Ad1th:fix/warn-no-files-match-patterns
Oct 2, 2026
Merged

Wauplin merged 3 commits into
huggingface:mainfrom
Ad1th:fix/warn-no-files-match-patterns

Conversation

@Ad1th

@Ad1th Ad1th commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5064

What

snapshot_download (and therefore hf download) reported a normal successful download when allow_patterns / ignore_patterns (--include / --exclude) matched zero files. A mistyped glob such as --include "*.safetensor" looked identical to a successful download.

This adds a logger.warning when patterns were provided, the repo has files, and none of them matched:

$ hf download sentence-transformers/all-MiniLM-L6-v2 --include "*.safetensor"
No files matched allow_patterns=['*.safetensor'] (repo has 30 files).
✓ Downloaded
  path: ...

No behavior change otherwise: no new exception, exit code unchanged, nothing is warned when the patterns match at least one file, when no patterns are given, or when the repo is empty.

Tests

Added test_warn_when_patterns_match_no_files (parametrized: warns for no-match allow_patterns as list/str, ignore_patterns=["*"], and allow+ignore cancelling out; stays quiet when files match or no patterns are given) and test_no_warning_when_repo_is_empty. The four warning cases fail before the change and pass after.

  • tests/test_snapshot_download.py, tests/test_cli.py: pass locally
  • ruff check / ruff format --check, check_static_imports, check_all_variable, generate_async_inference_client, generate_cli_reference: pass
  • ty check src reports 2 errors in cli/_output.py (invalid-type-form); they are identical on main without this change.

Note

Low Risk
Adds a log warning only on a zero-match pattern edge case; download success semantics and exit behavior are unchanged.

Overview
snapshot_download (and hf download via --include / --exclude) now emits a logger.warning when the repo tree has files but allow_patterns / ignore_patterns filter everything out—so a typo like *.safetensor no longer looks like a normal “fetch 0 files” success.

The warning lists whichever pattern kwargs were set (e.g. allow_patterns='*.safetensor'). It is skipped when no patterns are passed, when at least one file matches, or when the repo tree is empty. No new errors, exit codes, or download behavior otherwise.

Reviewed by Cursor Bugbot for commit 7fda4f3. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread tests/test_snapshot_download.py Resolved

@Wauplin Wauplin 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.

Made some changes but overall looks good

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.57%. Comparing base (1daa48b) to head (7fda4f3).
⚠️ Report is 759 commits behind head on main.

Files with missing lines Patch % Lines
src/huggingface_hub/_snapshot_download.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5067      +/-   ##
==========================================
+ Coverage   75.00%   77.57%   +2.56%     
==========================================
  Files         145      177      +32     
  Lines       13978    24787   +10809     
==========================================
+ Hits        10484    19228    +8744     
- Misses       3494     5559    +2065     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bot-ci-comment

bot-ci-comment Bot commented Oct 2, 2026

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.

@Wauplin
Wauplin merged commit 0ce4427 into huggingface:main Oct 2, 2026
23 of 27 checks passed
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v2.2.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.

hf download / snapshot_download report success when allow/ignore patterns match zero files

2 participants