-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix HfFileSystem.exists()
for deleted repos and update documentation
#2643
Conversation
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hanouticelina!
Left a few nits. Could you also add a test to check the initial snippet now works as expected?
from huggingface_hub import HfApi, HfFileSystem
import time
api = HfApi()
hfs = HfFileSystem()
hub_model_id = "MoritzLaurer/test-repo"
api.create_repo(hub_model_id, repo_type='model')
time.sleep(5)
api.delete_repo(repo_id=hub_model_id, repo_type="model")
time.sleep(5)
assert not hfs.exists(hub_model_id, refresh=True)
# Add docstrings to the methods of HfFileSystem from fsspec.AbstractFileSystem | ||
for name, function in inspect.getmembers(HfFileSystem, predicate=inspect.isfunction): | ||
parent = getattr(fsspec.AbstractFileSystem, name, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think a similar logic makes sense for all "hidden" methods not defined in huggingface_hub but in fsspec instead: read_text, read-bytes, write_text, write_bytes, tail, touch, etc. The initial goal was to make them appear in the documentation (see #2100) even though the implementation did not do that.
This can be done in a later PR (not urgent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good! Thanks for adding the test :)
Fixes #2552.
This PR fixes a bug where
HfFileSystem.exists()
returnsTrue
even after the repository has been deleted. The issue arises because the cache is not properly invalidated when the repository is deleted, causingHfFileSystem
to rely on stale cache data. The fix updates theHfFileSystem.invalidate_cache()
method to clear the repository 'existence' cache when the provided path matches the repository root.This PR also includes an update to
HfFileSystem
documentation.Main changes
HfFileSystem.invalidate_cache()
to clear repository cache.HfFileSystem
documentation to suggest usingHFApi
methods when possible.HfFileSystem
's methods.HfApi
class docstring visible in package reference by moving it from__init__
to class level.