diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e6e2ba2..191baa82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/adlfs/spec.py b/adlfs/spec.py index 90916e3c..8b4b9fb7 100644 --- a/adlfs/spec.py +++ b/adlfs/spec.py @@ -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]]: diff --git a/adlfs/tests/test_spec.py b/adlfs/tests/test_spec.py index 91f5d0df..09e92ce5 100644 --- a/adlfs/tests/test_spec.py +++ b/adlfs/tests/test_spec.py @@ -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)