Repository navigation
Accept two-letter byte units (KB/MB/GB/TB) in parse_size - #4468
hanouticelina merged 2 commits into
Conversation
The `hf cache ls --filter` help and docs advertise size thresholds like `size>1GB` and `size>10MB`, and the CLI's own --help example uses `size>1GB`. But parse_size only accepted single-letter units, so those documented filters raised `ValueError: Unknown unit 'gb'` while `size>30g` worked. The sibling parse_size_to_int() already supports KB/MB/GB/TB. Add the two-letter aliases so the advertised filters work, and cover them in the parsing tests (3KB/10MB/1GB/2TB were previously untested or wrongly marked invalid).
hanouticelina
left a comment
There was a problem hiding this comment.
thanks for noticing and fixing! the other parser that we have in the already supports KB/MB/GB/TB, so yes let's align this one as well
|
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4468 +/- ##
==========================================
+ Coverage 75.00% 75.73% +0.72%
==========================================
Files 145 175 +30
Lines 13978 22539 +8561
==========================================
+ Hits 10484 17069 +6585
- Misses 3494 5470 +1976 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for the quick merge, @hanouticelina! Glad it lined up with parse_size_to_int. Happy to help align anything else if more of these turn up. |
|
This PR has been shipped as part of the v1.22.0 release. |
The hf cache ls --filter help text and docs advertise size thresholds like size>1GB and size>10MB. The CLI's own --help example (and package_reference/cli.md) uses size>1GB, and manage-cache.md says these "work out of the box". But parse_size only accepted single-letter units, so the documented filters raised an error while the single-letter form worked:
This adds the two-letter aliases (kb/mb/gb/tb/pb) to BYTE_UNITS and covers them in the parsing tests. 3KB was previously listed as an invalid case; it's now valid, alongside new 10MB/1GB/2TB cases. Duration parsing is untouched.
Happy to flip this the other way (fix the docs to use single-letter units) if you'd prefer to keep parse_size single-letter only.
Note
Low Risk
Small parsing-map and test updates with no auth, security, or data-path changes.
Overview
parse_sizenow accepts two-letter byte units (kb,mb,gb,tb,pb) in addition to the existing single-letter aliases, so documentedhf cache ls --filterthresholds likesize>1GBandsize>10MBparse correctly instead of raising “Unknown unit”.Tests add valid cases for
3KB,10MB,1GB, and2TB, and drop3KBfrom the invalid-size list. Duration parsing is unchanged.Reviewed by Cursor Bugbot for commit 0914e52. Bugbot is set up for automated code reviews on this repo. Configure here.