Skip to content
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

[HfFileSystem] Fix rm on branch #1957

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/huggingface_hub/hf_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@ def rm(
**kwargs,
) -> None:
resolved_path = self.resolve_path(path, revision=revision)
root_path = REPO_TYPES_URL_PREFIXES.get(resolved_path.repo_type, "") + resolved_path.repo_id
paths = self.expand_path(path, recursive=recursive, maxdepth=maxdepth, revision=revision)
paths_in_repo = [path[len(root_path) + 1 :] for path in paths if not self.isdir(path)]
paths_in_repo = [self.resolve_path(path).path_in_repo for path in paths if not self.isdir(path)]
operations = [CommitOperationDelete(path_in_repo=path_in_repo) for path_in_repo in paths_in_repo]
commit_message = f"Delete {path} "
commit_message += "recursively " if recursive else ""
Expand Down
4 changes: 4 additions & 0 deletions tests/test_hf_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,14 @@ def test_file_type(self):
def test_remove_file(self):
self.hffs.rm_file(self.hf_path + "/data/text_data.txt")
self.assertEqual(self.hffs.glob(self.hf_path + "/data/*"), [self.hf_path + "/data/binary_data.bin"])
self.hffs.rm_file(self.hf_path + "@refs/pr/1" + "/data/binary_data_for_pr.bin")
self.assertEqual(self.hffs.glob(self.hf_path + "@refs/pr/1" + "/data/*"), [])

def test_remove_directory(self):
self.hffs.rm(self.hf_path + "/data", recursive=True)
self.assertNotIn(self.hf_path + "/data", self.hffs.ls(self.hf_path))
self.hffs.rm(self.hf_path + "@refs/pr/1" + "/data", recursive=True)
self.assertNotIn(self.hf_path + "@refs/pr/1" + "/data", self.hffs.ls(self.hf_path))

def test_read_file(self):
with self.hffs.open(self.hf_path + "/data/text_data.txt", "r") as f:
Expand Down
Loading