Skip to content

Commit 8749d2b

Browse files
committed
remove_aiopath
1 parent 2521c46 commit 8749d2b

File tree

3 files changed

+35
-38
lines changed

3 files changed

+35
-38
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "dean_utils"
7-
version="0.0.67"
7+
version="0.0.68"
88
authors=[
99
{ name="Dean MacGregor", email="powertrading121@gmail.com"}
1010
]

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ azure-storage-queue
77
python-multipart
88
azure-communication-email
99
httpx
10-
aiopath

src/dean_utils/utils/az_utils.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import contextlib
45
import json
56
import os
67
from datetime import datetime, timedelta, timezone
@@ -18,7 +19,6 @@
1819

1920
import azure.storage.blob as asb
2021
import fsspec
21-
from aiopath import AsyncPath
2222
from azure.core.exceptions import HttpResponseError
2323
from azure.storage.blob import BlobBlock
2424
from azure.storage.blob.aio import BlobClient
@@ -597,7 +597,7 @@ async def stream_dl(
597597

598598
async def stream_up(
599599
self,
600-
local_path: str | Path | AsyncPath,
600+
local_path: str | Path,
601601
remote_path: str,
602602
size: int = 16384,
603603
/,
@@ -619,41 +619,39 @@ async def stream_up(
619619
recurs:
620620
To try again recursively
621621
"""
622-
if isinstance(local_path, (str, Path)):
623-
local_path = AsyncPath(local_path)
624-
async with (
625-
BlobClient.from_connection_string(
622+
if isinstance(local_path, str):
623+
local_path = Path(local_path)
624+
with local_path.open("rb") as src:
625+
async with BlobClient.from_connection_string(
626626
self.connection_string, *(remote_path.split("/", maxsplit=1))
627-
) as target,
628-
local_path.open("rb") as src,
629-
):
630-
block_list = []
631-
while True:
632-
chunk = await src.read(size)
633-
chunk = cast("IO", chunk)
634-
if not chunk:
635-
break
636-
block_id = uuid4().hex
637-
try:
638-
await target.stage_block(block_id=block_id, data=chunk)
639-
except HttpResponseError as err:
640-
if "The specified blob or block content is invalid." not in str(
641-
err
642-
):
643-
raise
644-
await asyncio.sleep(1)
645-
await target.commit_block_list([])
646-
await target.delete_blob()
647-
if recurs is False:
648-
await self.stream_up(
649-
local_path,
650-
remote_path,
651-
recurs=True,
652-
)
653-
else:
654-
raise
655-
block_list.append(BlobBlock(block_id=block_id))
656-
await target.commit_block_list(block_list)
627+
) as target:
628+
block_list = []
629+
while True:
630+
chunk = src.read(size)
631+
chunk = cast("IO", chunk)
632+
if not chunk:
633+
break
634+
block_id = uuid4().hex
635+
try:
636+
await target.stage_block(block_id=block_id, data=chunk)
637+
except HttpResponseError as err:
638+
if "The specified blob or block content is invalid." not in str(
639+
err
640+
):
641+
raise
642+
await asyncio.sleep(1)
643+
await target.commit_block_list([])
644+
await target.delete_blob()
645+
if recurs is False:
646+
await self.stream_up(
647+
local_path,
648+
remote_path,
649+
recurs=True,
650+
)
651+
else:
652+
raise
653+
block_list.append(BlobBlock(block_id=block_id))
654+
await target.commit_block_list(block_list)
657655

658656
async def walk(self, path: str, maxdepth=None, **kwargs):
659657
"""

0 commit comments

Comments
 (0)