Skip to content

Set rm_files to be a synchronous method #503

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Unreleased
- The block size is now used for partitioned uploads. Previously, 1 GiB was used for each uploaded block irrespective of the block size
- Updated default block size to be 50 MiB. Set `blocksize` for `AzureBlobFileSystem` or `block_size` when opening `AzureBlobFile` to revert back to 5 MiB default.
- `AzureBlobFile` now inherits the block size from `AzureBlobFileSystem` when fs.open() is called and a block_size is not passed in.
- Added `AzureBlobFileSystem.rm_file()`


2024.12.0
Expand Down
23 changes: 23 additions & 0 deletions adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,29 @@ async def _rm_files(

sync_wrapper(_rm_files)

async def _rm_file(self, path: str, **kwargs):
"""Delete a file.
Parameters
----------
path: str
File to delete.
"""
container_name, p, _ = self.split_path(path)
try:
async with self.service_client.get_container_client(
container=container_name
) as cc:
await cc.delete_blob(p)
except ResourceNotFoundError:
pass
except FileNotFoundError:
pass
except Exception as e:
raise RuntimeError("Failed to remove %s for %s", path, e) from e

rm_file = sync_wrapper(_rm_file)

async def _separate_directory_markers_for_non_empty_directories(
self, file_paths: typing.Iterable[str]
) -> typing.Tuple[typing.List[str], typing.List[str]]:
Expand Down
12 changes: 12 additions & 0 deletions adlfs/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2140,3 +2140,15 @@ def test_blobfile_default_blocksize(storage):
"data/root/a/file.txt",
)
assert f.blocksize == 50 * 2**20


def test_rm_file(storage):
fs = AzureBlobFileSystem(
account_name=storage.account_name,
connection_string=CONN_STR,
)
path = "data/top_file.txt"

fs.rm_file(path)
with pytest.raises(FileNotFoundError):
fs.ls(path)