From 645f588bc2be549024d501f22e3fb394d9143a3f Mon Sep 17 00:00:00 2001 From: Quentin Lhoest Date: Thu, 4 Jan 2024 20:01:31 +0100 Subject: [PATCH 1/2] fix rm on branch --- src/huggingface_hub/hf_file_system.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/huggingface_hub/hf_file_system.py b/src/huggingface_hub/hf_file_system.py index 424923db25..bfdbb9bd59 100644 --- a/src/huggingface_hub/hf_file_system.py +++ b/src/huggingface_hub/hf_file_system.py @@ -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 "" From 35ba0318cfa63b2646f7a6fd26f0afa4cd76f8e1 Mon Sep 17 00:00:00 2001 From: Quentin Lhoest Date: Tue, 9 Jan 2024 17:04:22 +0100 Subject: [PATCH 2/2] add test --- tests/test_hf_file_system.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_hf_file_system.py b/tests/test_hf_file_system.py index 40ffc4adc0..00e389a24b 100644 --- a/tests/test_hf_file_system.py +++ b/tests/test_hf_file_system.py @@ -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: