Skip to content

[CLI] Migrate hf cache to out singleton#4070

Merged
hanouticelina merged 21 commits intomainfrom
cli-migrate-commands-part3
Apr 10, 2026
Merged

[CLI] Migrate hf cache to out singleton#4070
hanouticelina merged 21 commits intomainfrom
cli-migrate-commands-part3

Conversation

@hanouticelina
Copy link
Copy Markdown
Contributor

@hanouticelina hanouticelina commented Apr 8, 2026

Part of #3979

This PR migrates all cache subcommands (ls, rm, prune, verify) to the out singleton.

it introduces some notable breaking changes, in addition to those that affects all migrated commands (e.g. -q/--quiet replaced by --format quiet, errors and warnings goes to stderr instead of stdout):

hf cache ls --format json:

  • id field added (e.g. model/unsloth/Qwen3.5-35B-A3B-GGUF)
  • size_on_disk (int, bytes) replaced by size (formatted string, e.g. "1.2 GB")
  • last_accessed and last_modified changed from float timestamps to formatted strings (e.g. "3 days ago")

Note

Medium Risk
This changes hf cache CLI flags and output formats (including --quiet removal and different JSON/table fields), which can break user scripts and tests that parse stdout/stderr.

Overview
Migrates all hf cache subcommands (ls, rm, prune, verify) to the out output singleton and standardizes output handling via --format [agent|auto|human|json|quiet].

This replaces the legacy --quiet flag with --format quiet, updates ls rendering to go through out.table (including revised JSON/table fields such as adding id and emitting human-formatted size/time strings), and routes warnings/errors/success messages through out (changing stdout/stderr behavior).

Docs and CLI tests are updated to reflect the new --format option and the adjusted output assertions.

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

@bot-ci-comment
Copy link
Copy Markdown

bot-ci-comment Bot commented Apr 8, 2026

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 marked this pull request as ready for review April 9, 2026 14:57
@hanouticelina hanouticelina requested a review from Wauplin April 9, 2026 14:57
@hanouticelina
Copy link
Copy Markdown
Contributor Author

@cursoragent review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 9, 2026

The PR already exists and I don't need to update its title or body — my commit is already pushed. Here's my review summary:


I reviewed the PR and found two functional issues that I fixed:

1. out.result() calls had no data kwargs — In rm, prune, and verify, out.result(message) was called without structured data kwargs. Looking at Output.result() in _output.py, when data is empty: json mode emits an empty string, quiet mode emits nothing, and agent mode falls back to the message string. I added meaningful kwargs (repos_deleted, revisions_deleted, freed, repo_id, checked, etc.) so all output modes produce useful output.

2. verify error details used out.text() which is a no-op in json/quiet modes — Mismatch details, missing file lists, and extra file lists were printed via out.text(), which silently drops content in json and quiet modes. Changed these to out.error() so verification failure details are always visible (on stderr). Updated corresponding test assertions to check result.output (stdout+stderr combined) instead of result.stdout.

All 221 CLI tests pass, make style and make quality are clean.

Open in Web Open in Cursor 

hanouticelina and others added 8 commits April 9, 2026 16:59
…failures

- out.result() in rm, prune, verify now passes structured data kwargs
  so json/quiet modes emit useful output instead of empty strings
- verify mismatch/missing/extra details now use out.error() instead of
  out.text() so they are visible in all output modes (text is a no-op
  in json/quiet)
- update test assertions to use result.output (stdout+stderr) for error
  messages that now go to stderr via out.error()

Co-authored-by: célina <[email protected]>
@hanouticelina
Copy link
Copy Markdown
Contributor Author

@cursoragent revert 2f95baa

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 9, 2026

Reverted commit 2f95baa and pushed the revert to the branch.

Open in Web Open in Cursor 

@hanouticelina hanouticelina marked this pull request as draft April 9, 2026 15:32
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 09df44d. Configure here.

Comment thread src/huggingface_hub/cli/cache.py Outdated
@hanouticelina
Copy link
Copy Markdown
Contributor Author

@Wauplin one thing i noticed is that in json or agent, library level logger.info() messages can leak into stdout.

x hf cache rm model/m42-health/Llama3-Med42-70B --json --yes
Delete repo: /Users/hcelina/.cache/huggingface/hub/models--m42-health--Llama3-Med42-70B
Cache deletion done. Saved 8.8K.
{"repos_deleted": 1, "revisions_deleted": 1, "freed": "8.8K"} # in json mode we only want the dict

I don't think we should disable info logging in _output.py since set_mode() is called at import time. instead, we disable it in the _set_output_mode callback when mode is not human. what do you think?

@hanouticelina hanouticelina marked this pull request as ready for review April 10, 2026 08:13
Copy link
Copy Markdown
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Tested locally and approved! Minor comment + out.confirm can be handled separately

one thing i noticed is that in json or agent, library level logger.info() messages can leak into stdout.
I don't think we should disable info logging in _output.py since set_mode() is called at import time. instead, we disable it in the _set_output_mode callback when mode is not human. what do you think?

Yes indeed I see the problem. What do you think of redirecting logger.info() to stderr instead of stdout when in agent/json mode? so that the agent still have the info but we do not pollute the stdout. (and yes agree in doing it at runtime in _set_output_mode).

Otherwise I'm ok to disable logs entirely, I'm just unsure what we will be missing.

)
return

if not yes and not typer.confirm("Proceed with deletion?", default=False):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

note: change typer.confirm with out.confirm (once implemented) so that in agent mode with gracefully raise error (mentioned in #3979)

Image

)
return

if not yes and not typer.confirm("Proceed?"):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

Comment thread src/huggingface_hub/cli/cache.py Outdated
@hanouticelina
Copy link
Copy Markdown
Contributor Author

@Wauplin actually I'm dumb (and tricked by Opus 🙃), logger.info() messages already go to stderr (Python's StreamHandler defaults to stderr), stdout is clean, so all good!

> hf cache rm model/bartowski/Qwen2.5-Coder-14B-GGUF --yes --format json 2>/dev/null
{"repos_deleted": 1, "revisions_deleted": 1, "freed": "15.7G"}

@hanouticelina hanouticelina merged commit 52503dd into main Apr 10, 2026
17 of 20 checks passed
@hanouticelina hanouticelina deleted the cli-migrate-commands-part3 branch April 10, 2026 12:54
@huggingface-hub-bot
Copy link
Copy Markdown
Contributor

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

3 participants