panpath 0.4.6__tar.gz → 0.4.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {panpath-0.4.6 → panpath-0.4.7}/PKG-INFO +2 -2
- {panpath-0.4.6 → panpath-0.4.7}/panpath/__init__.py +1 -1
- {panpath-0.4.6 → panpath-0.4.7}/panpath/azure_async_client.py +7 -0
- {panpath-0.4.6 → panpath-0.4.7}/panpath/azure_client.py +9 -1
- {panpath-0.4.6 → panpath-0.4.7}/panpath/base.py +56 -47
- {panpath-0.4.6 → panpath-0.4.7}/panpath/clients.py +26 -0
- {panpath-0.4.6 → panpath-0.4.7}/panpath/cloud.py +11 -11
- {panpath-0.4.6 → panpath-0.4.7}/panpath/gs_async_client.py +16 -11
- {panpath-0.4.6 → panpath-0.4.7}/panpath/gs_client.py +12 -7
- {panpath-0.4.6 → panpath-0.4.7}/panpath/local_path.py +4 -4
- {panpath-0.4.6 → panpath-0.4.7}/panpath/s3_async_client.py +2 -1
- {panpath-0.4.6 → panpath-0.4.7}/panpath/s3_client.py +2 -1
- {panpath-0.4.6 → panpath-0.4.7}/pyproject.toml +2 -2
- {panpath-0.4.6 → panpath-0.4.7}/LICENSE +0 -0
- {panpath-0.4.6 → panpath-0.4.7}/README.md +0 -0
- {panpath-0.4.6 → panpath-0.4.7}/panpath/azure_path.py +0 -0
- {panpath-0.4.6 → panpath-0.4.7}/panpath/exceptions.py +0 -0
- {panpath-0.4.6 → panpath-0.4.7}/panpath/gs_path.py +0 -0
- {panpath-0.4.6 → panpath-0.4.7}/panpath/py.typed +0 -0
- {panpath-0.4.6 → panpath-0.4.7}/panpath/registry.py +0 -0
- {panpath-0.4.6 → panpath-0.4.7}/panpath/s3_path.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: panpath
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.7
|
|
4
4
|
Summary: Universal sync/async local/cloud path library with pathlib-compatible interface
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -32,7 +32,7 @@ Requires-Dist: aioboto3 (>=11.0.0) ; extra == "async-s3" or extra == "all-async"
|
|
|
32
32
|
Requires-Dist: aiofiles (>=23.0.0) ; extra == "async-s3" or extra == "async-gs" or extra == "async-azure" or extra == "all-async" or extra == "all"
|
|
33
33
|
Requires-Dist: azure-storage-blob (>=12.0.0) ; extra == "azure" or extra == "async-azure" or extra == "all-sync" or extra == "all-async" or extra == "all"
|
|
34
34
|
Requires-Dist: boto3 (>=1.20.0) ; extra == "s3" or extra == "all-sync" or extra == "all"
|
|
35
|
-
Requires-Dist: gcloud-aio-storage (>=
|
|
35
|
+
Requires-Dist: gcloud-aio-storage (>=9.5) ; extra == "async-gs" or extra == "all-async" or extra == "all"
|
|
36
36
|
Requires-Dist: google-cloud-storage (>=2.0.0) ; extra == "gs" or extra == "all-sync" or extra == "all"
|
|
37
37
|
Requires-Dist: typing-extensions (>=4.0.0)
|
|
38
38
|
Project-URL: Documentation, https://github.com/pwwang/panpath#readme
|
|
@@ -301,6 +301,13 @@ class AsyncAzureBlobClient(AsyncClient):
|
|
|
301
301
|
|
|
302
302
|
Note: For better streaming support, use a_open() instead.
|
|
303
303
|
This method returns a file-like object that supports the standard file API.
|
|
304
|
+
|
|
305
|
+
Args:
|
|
306
|
+
path: Azure path
|
|
307
|
+
mode: File mode
|
|
308
|
+
encoding: Text encoding
|
|
309
|
+
**kwargs: Additional arguments (chunk_size, upload_warning_threshold,
|
|
310
|
+
upload_interval supported)
|
|
304
311
|
"""
|
|
305
312
|
if mode not in ("r", "rb", "w", "wb", "a", "ab"):
|
|
306
313
|
raise ValueError(f"Unsupported mode '{mode}'. Use 'r', 'rb', 'w', 'wb', 'a', or 'ab'.")
|
|
@@ -180,7 +180,15 @@ class AzureBlobClient(SyncClient):
|
|
|
180
180
|
encoding: Optional[str] = None,
|
|
181
181
|
**kwargs: Any,
|
|
182
182
|
) -> SyncFileHandle:
|
|
183
|
-
"""Open Azure blob for reading/writing.
|
|
183
|
+
"""Open Azure blob for reading/writing.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
path: Azure path
|
|
187
|
+
mode: File mode
|
|
188
|
+
encoding: Text encoding
|
|
189
|
+
**kwargs: Additional arguments (chunk_size, upload_warning_threshold,
|
|
190
|
+
upload_interval supported)
|
|
191
|
+
"""
|
|
184
192
|
if mode not in ("r", "rb", "w", "wb", "a", "ab"):
|
|
185
193
|
raise ValueError(f"Unsupported mode '{mode}'. Use 'r', 'rb', 'w', 'wb', 'a', or 'ab'.")
|
|
186
194
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import os
|
|
4
4
|
import re
|
|
5
5
|
import sys
|
|
6
|
-
from abc import abstractmethod
|
|
7
6
|
from pathlib import Path as PathlibPath, PurePosixPath
|
|
8
7
|
from typing import TYPE_CHECKING, Any, AsyncGenerator, List, Union
|
|
9
8
|
|
|
@@ -123,32 +122,31 @@ class PanPath(PathlibPath):
|
|
|
123
122
|
except KeyError:
|
|
124
123
|
raise ValueError(f"Unsupported URI scheme: {scheme!r}")
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
# These methods are used for IDE type hinting and documentation generation.
|
|
126
|
+
# Actual implementations are in LocalPath and CloudPath subclasses and
|
|
127
|
+
# are routed via __new__.
|
|
128
|
+
async def a_resolve(self) -> "PanPath": # type: ignore[empty-body]
|
|
128
129
|
"""Resolve to absolute path (no-op for cloud paths).
|
|
129
130
|
|
|
130
131
|
Returns:
|
|
131
132
|
Self (cloud paths are already absolute)
|
|
132
133
|
"""
|
|
133
134
|
|
|
134
|
-
|
|
135
|
-
async def a_exists(self) -> bool:
|
|
135
|
+
async def a_exists(self) -> bool: # type: ignore[empty-body]
|
|
136
136
|
"""Asynchronously check if the path exists.
|
|
137
137
|
|
|
138
138
|
Returns:
|
|
139
139
|
True if the path exists, False otherwise.
|
|
140
140
|
"""
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
async def a_read_bytes(self) -> bytes:
|
|
142
|
+
async def a_read_bytes(self) -> bytes: # type: ignore[empty-body]
|
|
144
143
|
"""Asynchronously read the file's bytes.
|
|
145
144
|
|
|
146
145
|
Returns:
|
|
147
146
|
File content as bytes.
|
|
148
147
|
"""
|
|
149
148
|
|
|
150
|
-
|
|
151
|
-
async def a_read_text(self, encoding: str = "utf-8") -> str:
|
|
149
|
+
async def a_read_text(self, encoding: str = "utf-8") -> str: # type: ignore[empty-body]
|
|
152
150
|
"""Asynchronously read the file's text content.
|
|
153
151
|
|
|
154
152
|
Args:
|
|
@@ -158,7 +156,6 @@ class PanPath(PathlibPath):
|
|
|
158
156
|
File content as string.
|
|
159
157
|
"""
|
|
160
158
|
|
|
161
|
-
@abstractmethod
|
|
162
159
|
async def a_write_bytes(self, data: bytes) -> Union[int, None]:
|
|
163
160
|
"""Asynchronously write bytes to the file.
|
|
164
161
|
|
|
@@ -169,8 +166,11 @@ class PanPath(PathlibPath):
|
|
|
169
166
|
Number of bytes written. For some cloud paths, may return None.
|
|
170
167
|
"""
|
|
171
168
|
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
async def a_write_text( # type: ignore[empty-body]
|
|
170
|
+
self,
|
|
171
|
+
data: str,
|
|
172
|
+
encoding: str = "utf-8",
|
|
173
|
+
) -> int:
|
|
174
174
|
"""Asynchronously write text to the file.
|
|
175
175
|
|
|
176
176
|
Args:
|
|
@@ -181,7 +181,6 @@ class PanPath(PathlibPath):
|
|
|
181
181
|
Number of characters written.
|
|
182
182
|
"""
|
|
183
183
|
|
|
184
|
-
@abstractmethod
|
|
185
184
|
async def a_unlink(self, missing_ok: bool = False) -> None:
|
|
186
185
|
"""Asynchronously remove (delete) the file or empty directory.
|
|
187
186
|
|
|
@@ -189,39 +188,37 @@ class PanPath(PathlibPath):
|
|
|
189
188
|
missing_ok: If True, does not raise an error if the file does not exist.
|
|
190
189
|
"""
|
|
191
190
|
|
|
192
|
-
|
|
193
|
-
async def a_iterdir(self) -> AsyncGenerator["PanPath", None]:
|
|
191
|
+
async def a_iterdir(self) -> AsyncGenerator["PanPath", None]: # type: ignore[empty-body]
|
|
194
192
|
"""Asynchronously iterate over directory contents.
|
|
195
193
|
|
|
196
194
|
Yields:
|
|
197
195
|
PanPath instances for each item in the directory.
|
|
198
196
|
"""
|
|
199
197
|
|
|
200
|
-
|
|
201
|
-
async def a_is_dir(self) -> bool:
|
|
198
|
+
async def a_is_dir(self) -> bool: # type: ignore[empty-body]
|
|
202
199
|
"""Asynchronously check if the path is a directory.
|
|
203
200
|
|
|
204
201
|
Returns:
|
|
205
202
|
True if the path is a directory, False otherwise.
|
|
206
203
|
"""
|
|
207
204
|
|
|
208
|
-
|
|
209
|
-
async def a_is_file(self) -> bool:
|
|
205
|
+
async def a_is_file(self) -> bool: # type: ignore[empty-body]
|
|
210
206
|
"""Asynchronously check if the path is a file.
|
|
211
207
|
|
|
212
208
|
Returns:
|
|
213
209
|
True if the path is a file, False otherwise.
|
|
214
210
|
"""
|
|
215
211
|
|
|
216
|
-
|
|
217
|
-
|
|
212
|
+
async def a_stat( # type: ignore[empty-body]
|
|
213
|
+
self,
|
|
214
|
+
follow_symlinks: bool = True,
|
|
215
|
+
) -> os.stat_result:
|
|
218
216
|
"""Asynchronously get the file or directory's status information.
|
|
219
217
|
|
|
220
218
|
Returns:
|
|
221
219
|
An object containing file status information (platform-dependent).
|
|
222
220
|
"""
|
|
223
221
|
|
|
224
|
-
@abstractmethod
|
|
225
222
|
async def a_mkdir(
|
|
226
223
|
self,
|
|
227
224
|
mode: int = 0o777,
|
|
@@ -236,8 +233,10 @@ class PanPath(PathlibPath):
|
|
|
236
233
|
exist_ok: If True, does not raise an error if the directory already exists.
|
|
237
234
|
"""
|
|
238
235
|
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
async def a_glob( # type: ignore[empty-body]
|
|
237
|
+
self,
|
|
238
|
+
pattern: str,
|
|
239
|
+
) -> AsyncGenerator["PanPath", None]:
|
|
241
240
|
"""Asynchronously yield paths matching a glob pattern.
|
|
242
241
|
|
|
243
242
|
Args:
|
|
@@ -247,8 +246,10 @@ class PanPath(PathlibPath):
|
|
|
247
246
|
List of PanPath instances matching the pattern.
|
|
248
247
|
"""
|
|
249
248
|
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
async def a_rglob( # type: ignore[empty-body]
|
|
250
|
+
self,
|
|
251
|
+
pattern: str,
|
|
252
|
+
) -> AsyncGenerator["PanPath", None]:
|
|
252
253
|
"""Asynchronously yield paths matching a recursive glob pattern.
|
|
253
254
|
|
|
254
255
|
Args:
|
|
@@ -258,16 +259,20 @@ class PanPath(PathlibPath):
|
|
|
258
259
|
List of PanPath instances matching the pattern.
|
|
259
260
|
"""
|
|
260
261
|
|
|
261
|
-
|
|
262
|
-
|
|
262
|
+
async def a_walk( # type: ignore[empty-body]
|
|
263
|
+
self,
|
|
264
|
+
) -> AsyncGenerator[tuple["PanPath", List[str], List[str]], None]:
|
|
263
265
|
"""Asynchronously walk the directory tree.
|
|
264
266
|
|
|
265
267
|
Yields:
|
|
266
268
|
Tuples of (current_path, dirnames, filenames) at each level.
|
|
267
269
|
"""
|
|
268
270
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
+
async def a_touch(
|
|
272
|
+
self,
|
|
273
|
+
mode: int = 0o666,
|
|
274
|
+
exist_ok: bool = True,
|
|
275
|
+
) -> None:
|
|
271
276
|
"""Asynchronously create the file if it does not exist.
|
|
272
277
|
|
|
273
278
|
Args:
|
|
@@ -275,8 +280,10 @@ class PanPath(PathlibPath):
|
|
|
275
280
|
exist_ok: If False, raises an error if the file already exists.
|
|
276
281
|
"""
|
|
277
282
|
|
|
278
|
-
|
|
279
|
-
|
|
283
|
+
async def a_rename( # type: ignore[empty-body]
|
|
284
|
+
self,
|
|
285
|
+
target: Union[str, "PathlibPath"],
|
|
286
|
+
) -> "PanPath":
|
|
280
287
|
"""Asynchronously rename this path to the target path.
|
|
281
288
|
|
|
282
289
|
Args:
|
|
@@ -286,8 +293,10 @@ class PanPath(PathlibPath):
|
|
|
286
293
|
The renamed PanPath instance.
|
|
287
294
|
"""
|
|
288
295
|
|
|
289
|
-
|
|
290
|
-
|
|
296
|
+
async def a_replace( # type: ignore[empty-body]
|
|
297
|
+
self,
|
|
298
|
+
target: Union[str, "PathlibPath"],
|
|
299
|
+
) -> "PanPath":
|
|
291
300
|
"""Asynchronously replace this path with the target path.
|
|
292
301
|
|
|
293
302
|
Args:
|
|
@@ -297,12 +306,10 @@ class PanPath(PathlibPath):
|
|
|
297
306
|
The replaced PanPath instance.
|
|
298
307
|
"""
|
|
299
308
|
|
|
300
|
-
@abstractmethod
|
|
301
309
|
async def a_rmdir(self) -> None:
|
|
302
310
|
"""Asynchronously remove the directory and its contents recursively."""
|
|
303
311
|
|
|
304
|
-
|
|
305
|
-
async def a_is_symlink(self) -> bool:
|
|
312
|
+
async def a_is_symlink(self) -> bool: # type: ignore[empty-body]
|
|
306
313
|
"""Asynchronously check if the path is a symbolic link.
|
|
307
314
|
|
|
308
315
|
For local path, this checks if the path is a symlink.
|
|
@@ -314,8 +321,7 @@ class PanPath(PathlibPath):
|
|
|
314
321
|
True if the path is a symlink, False otherwise.
|
|
315
322
|
"""
|
|
316
323
|
|
|
317
|
-
|
|
318
|
-
async def a_readlink(self) -> "PanPath":
|
|
324
|
+
async def a_readlink(self) -> "PanPath": # type: ignore[empty-body]
|
|
319
325
|
"""Asynchronously read the target of the symbolic link.
|
|
320
326
|
|
|
321
327
|
For local path, this reads the symlink target.
|
|
@@ -325,7 +331,6 @@ class PanPath(PathlibPath):
|
|
|
325
331
|
The target PanPath of the symlink.
|
|
326
332
|
"""
|
|
327
333
|
|
|
328
|
-
@abstractmethod
|
|
329
334
|
async def a_symlink_to(
|
|
330
335
|
self,
|
|
331
336
|
target: Union[str, "PathlibPath"],
|
|
@@ -341,7 +346,6 @@ class PanPath(PathlibPath):
|
|
|
341
346
|
target_is_directory: Whether the target is a directory (ignored for cloud paths).
|
|
342
347
|
"""
|
|
343
348
|
|
|
344
|
-
@abstractmethod
|
|
345
349
|
async def a_rmtree(self, ignore_errors: bool = False, onerror: Any = None) -> None:
|
|
346
350
|
"""Asynchronously remove the directory and all its contents recursively.
|
|
347
351
|
|
|
@@ -350,8 +354,10 @@ class PanPath(PathlibPath):
|
|
|
350
354
|
onerror: Optional function to call on errors.
|
|
351
355
|
"""
|
|
352
356
|
|
|
353
|
-
|
|
354
|
-
|
|
357
|
+
async def a_copy( # type: ignore[empty-body]
|
|
358
|
+
self,
|
|
359
|
+
target: Union[str, "PathlibPath"],
|
|
360
|
+
) -> "PanPath":
|
|
355
361
|
"""Asynchronously copy this path to the target path.
|
|
356
362
|
|
|
357
363
|
Args:
|
|
@@ -361,8 +367,7 @@ class PanPath(PathlibPath):
|
|
|
361
367
|
The copied PanPath instance.
|
|
362
368
|
"""
|
|
363
369
|
|
|
364
|
-
|
|
365
|
-
async def a_copytree(
|
|
370
|
+
async def a_copytree( # type: ignore[empty-body]
|
|
366
371
|
self,
|
|
367
372
|
target: Union[str, "PathlibPath"],
|
|
368
373
|
follow_symlinks: bool = True,
|
|
@@ -377,8 +382,12 @@ class PanPath(PathlibPath):
|
|
|
377
382
|
The copied PanPath instance.
|
|
378
383
|
"""
|
|
379
384
|
|
|
380
|
-
|
|
381
|
-
|
|
385
|
+
def a_open( # type: ignore[empty-body]
|
|
386
|
+
self,
|
|
387
|
+
mode: str = "r",
|
|
388
|
+
encoding: str = "utf-8",
|
|
389
|
+
**kwargs: Any,
|
|
390
|
+
) -> "AsyncFileHandle":
|
|
382
391
|
"""Asynchronously open the file and return an async file handle.
|
|
383
392
|
|
|
384
393
|
Args:
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""Base client classes for sync and async cloud storage operations."""
|
|
2
2
|
|
|
3
3
|
from abc import ABC, abstractmethod
|
|
4
|
+
import asyncio
|
|
5
|
+
import time
|
|
4
6
|
from typing import (
|
|
5
7
|
Any,
|
|
6
8
|
AsyncGenerator,
|
|
@@ -368,6 +370,7 @@ class AsyncFileHandle(ABC):
|
|
|
368
370
|
encoding: Optional[str] = None,
|
|
369
371
|
chunk_size: int = 4096,
|
|
370
372
|
upload_warning_threshold: int = 100,
|
|
373
|
+
upload_interval: float = 1.0,
|
|
371
374
|
):
|
|
372
375
|
"""Initialize async file handle.
|
|
373
376
|
|
|
@@ -381,6 +384,8 @@ class AsyncFileHandle(ABC):
|
|
|
381
384
|
chunk_size: Size of chunks to read
|
|
382
385
|
upload_warning_threshold: Number of chunk uploads before warning (default: 100)
|
|
383
386
|
-1 to disable warning
|
|
387
|
+
upload_interval: Minimum interval (in seconds) between uploads to avoid
|
|
388
|
+
rate limits (default: 1.0)
|
|
384
389
|
"""
|
|
385
390
|
self._client_factory = client_factory
|
|
386
391
|
self._client: Optional[AsyncClient] = None
|
|
@@ -394,6 +399,8 @@ class AsyncFileHandle(ABC):
|
|
|
394
399
|
self._upload_warning_threshold = upload_warning_threshold
|
|
395
400
|
self._upload_count = 0
|
|
396
401
|
self._first_write = True # Track if this is the first write (for 'w' mode clearing)
|
|
402
|
+
self._upload_interval = upload_interval
|
|
403
|
+
self._last_upload_time: Optional[float] = None
|
|
397
404
|
|
|
398
405
|
# For write modes
|
|
399
406
|
self._write_buffer: Union[bytearray, List[str]] = bytearray() if "b" in mode else []
|
|
@@ -453,7 +460,14 @@ class AsyncFileHandle(ABC):
|
|
|
453
460
|
else:
|
|
454
461
|
data = "".join(self._write_buffer) # type: ignore
|
|
455
462
|
|
|
463
|
+
# Rate limiting: wait if needed to respect upload_interval
|
|
464
|
+
if self._upload_interval > 0 and self._last_upload_time is not None:
|
|
465
|
+
elapsed = time.time() - self._last_upload_time
|
|
466
|
+
if elapsed < self._upload_interval:
|
|
467
|
+
await asyncio.sleep(self._upload_interval - elapsed)
|
|
468
|
+
|
|
456
469
|
await self._upload(data)
|
|
470
|
+
self._last_upload_time = time.time()
|
|
457
471
|
self._write_buffer = bytearray() if self._is_binary else []
|
|
458
472
|
|
|
459
473
|
# Track upload count and warn if threshold exceeded
|
|
@@ -763,6 +777,7 @@ class SyncFileHandle(ABC):
|
|
|
763
777
|
encoding: Optional[str] = None,
|
|
764
778
|
chunk_size: int = 4096,
|
|
765
779
|
upload_warning_threshold: int = 100,
|
|
780
|
+
upload_interval: float = 1.0,
|
|
766
781
|
):
|
|
767
782
|
"""Initialize sync file handle.
|
|
768
783
|
|
|
@@ -775,6 +790,8 @@ class SyncFileHandle(ABC):
|
|
|
775
790
|
encoding: Text encoding (for text modes)
|
|
776
791
|
chunk_size: Size of chunks to read
|
|
777
792
|
upload_warning_threshold: Number of chunk uploads before warning (default: 100)
|
|
793
|
+
upload_interval: Minimum interval (in seconds) between uploads to avoid
|
|
794
|
+
rate limits (default: 1.0)
|
|
778
795
|
"""
|
|
779
796
|
self._client = client
|
|
780
797
|
self._bucket = bucket
|
|
@@ -787,6 +804,8 @@ class SyncFileHandle(ABC):
|
|
|
787
804
|
self._upload_warning_threshold = upload_warning_threshold
|
|
788
805
|
self._upload_count = 0
|
|
789
806
|
self._first_write = True # Track if this is the first write (for 'w' mode clearing)
|
|
807
|
+
self._upload_interval = upload_interval
|
|
808
|
+
self._last_upload_time: Optional[float] = None
|
|
790
809
|
|
|
791
810
|
# For write modes
|
|
792
811
|
self._write_buffer: Union[bytearray, List[str]] = bytearray() if "b" in mode else []
|
|
@@ -836,7 +855,14 @@ class SyncFileHandle(ABC):
|
|
|
836
855
|
else:
|
|
837
856
|
data = "".join(self._write_buffer) # type: ignore
|
|
838
857
|
|
|
858
|
+
# Rate limiting: wait if needed to respect upload_interval
|
|
859
|
+
if self._upload_interval > 0 and self._last_upload_time is not None:
|
|
860
|
+
elapsed = time.time() - self._last_upload_time
|
|
861
|
+
if elapsed < self._upload_interval:
|
|
862
|
+
time.sleep(self._upload_interval - elapsed)
|
|
863
|
+
|
|
839
864
|
self._upload(data)
|
|
865
|
+
self._last_upload_time = time.time()
|
|
840
866
|
self._write_buffer = bytearray() if self._is_binary else []
|
|
841
867
|
|
|
842
868
|
# Track upload count and warn if threshold exceeded
|
|
@@ -472,8 +472,8 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
472
472
|
src: str, dst: str, follow_symlinks: bool = True
|
|
473
473
|
) -> None: # pragma: no cover
|
|
474
474
|
"""Copy file across storage boundaries."""
|
|
475
|
-
src_path = PanPath(src)
|
|
476
|
-
dst_path = PanPath(dst)
|
|
475
|
+
src_path = PanPath(src)
|
|
476
|
+
dst_path = PanPath(dst)
|
|
477
477
|
|
|
478
478
|
# Handle symlinks
|
|
479
479
|
if not follow_symlinks and src_path.is_symlink():
|
|
@@ -490,8 +490,8 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
490
490
|
src: str, dst: str, follow_symlinks: bool = True
|
|
491
491
|
) -> None: # pragma: no cover
|
|
492
492
|
"""Copy directory tree across storage boundaries."""
|
|
493
|
-
src_path = PanPath(src)
|
|
494
|
-
dst_path = PanPath(dst)
|
|
493
|
+
src_path = PanPath(src)
|
|
494
|
+
dst_path = PanPath(dst)
|
|
495
495
|
|
|
496
496
|
# Create destination directory
|
|
497
497
|
dst_path.mkdir(parents=True, exist_ok=True)
|
|
@@ -508,7 +508,7 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
508
508
|
|
|
509
509
|
# Copy files
|
|
510
510
|
for filename in filenames:
|
|
511
|
-
src_file = PanPath(dirpath) / filename
|
|
511
|
+
src_file = PanPath(dirpath) / filename
|
|
512
512
|
dst_file = dst_path / rel_dir / filename if rel_dir else dst_path / filename
|
|
513
513
|
# Handle symlinks
|
|
514
514
|
if not follow_symlinks and src_file.is_symlink():
|
|
@@ -666,7 +666,7 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
666
666
|
|
|
667
667
|
target_str = str(target)
|
|
668
668
|
if not isinstance(target, PanPath): # pragma: no cover
|
|
669
|
-
target = PanPath(target_str) # type: ignore[
|
|
669
|
+
target = PanPath(target_str) # type: ignore[assignment]
|
|
670
670
|
|
|
671
671
|
source_is_dir = await self.a_is_dir()
|
|
672
672
|
target_is_dir = await target.a_is_dir() # type: ignore[union-attr]
|
|
@@ -799,7 +799,7 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
799
799
|
# Same storage, use native copy
|
|
800
800
|
await self.async_client.copy(str(self), target_str, follow_symlinks=follow_symlinks)
|
|
801
801
|
|
|
802
|
-
return PanPath(target_str)
|
|
802
|
+
return PanPath(target_str)
|
|
803
803
|
|
|
804
804
|
async def a_copytree(
|
|
805
805
|
self,
|
|
@@ -834,8 +834,8 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
834
834
|
src: str, dst: str, follow_symlinks: bool = True
|
|
835
835
|
) -> None: # pragma: no cover
|
|
836
836
|
"""Copy file across storage boundaries (async)."""
|
|
837
|
-
src_path = PanPath(src)
|
|
838
|
-
dst_path = PanPath(dst)
|
|
837
|
+
src_path = PanPath(src)
|
|
838
|
+
dst_path = PanPath(dst)
|
|
839
839
|
|
|
840
840
|
# Handle symlinks
|
|
841
841
|
if not follow_symlinks and await src_path.a_is_symlink():
|
|
@@ -852,8 +852,8 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
852
852
|
src: str, dst: str, follow_symlinks: bool = True
|
|
853
853
|
) -> None: # pragma: no cover
|
|
854
854
|
"""Copy directory tree across storage boundaries (async)."""
|
|
855
|
-
src_path = PanPath(src)
|
|
856
|
-
dst_path = PanPath(dst)
|
|
855
|
+
src_path = PanPath(src)
|
|
856
|
+
dst_path = PanPath(dst)
|
|
857
857
|
|
|
858
858
|
# Create destination directory
|
|
859
859
|
await dst_path.a_mkdir(parents=True, exist_ok=True)
|
|
@@ -322,7 +322,8 @@ class AsyncGSClient(AsyncClient):
|
|
|
322
322
|
path: GCS path (gs://bucket/blob)
|
|
323
323
|
mode: File mode ('r', 'w', 'rb', 'wb', 'a', 'ab')
|
|
324
324
|
encoding: Text encoding (for text modes)
|
|
325
|
-
**kwargs: Additional arguments (
|
|
325
|
+
**kwargs: Additional arguments (chunk_size, upload_warning_threshold,
|
|
326
|
+
upload_interval supported)
|
|
326
327
|
|
|
327
328
|
Returns:
|
|
328
329
|
GSAsyncFileHandle with streaming support
|
|
@@ -813,19 +814,23 @@ class GSAsyncFileHandle(AsyncFileHandle):
|
|
|
813
814
|
await storage.upload(self._bucket, self._blob, data)
|
|
814
815
|
else:
|
|
815
816
|
# Upload new data to a temporary blob
|
|
816
|
-
|
|
817
|
+
# Use upload count to ensure unique temp blob names across multiple flushes
|
|
818
|
+
temp_blob = f"{self._blob}.tmp.{os.getpid()}.{self._upload_count}"
|
|
817
819
|
await storage.upload(
|
|
818
820
|
self._bucket,
|
|
819
821
|
temp_blob,
|
|
820
822
|
data,
|
|
821
823
|
)
|
|
822
824
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
825
|
+
try:
|
|
826
|
+
# Use compose API to concatenate original + new data
|
|
827
|
+
await storage.compose(
|
|
828
|
+
bucket=self._bucket,
|
|
829
|
+
object_name=self._blob,
|
|
830
|
+
source_object_names=[self._blob, temp_blob],
|
|
831
|
+
)
|
|
832
|
+
except Exception as e: # pragma: no cover
|
|
833
|
+
raise IOError(f"Failed to append data to GCS blob: {self._blob}") from e
|
|
834
|
+
finally:
|
|
835
|
+
# Clean up the temporary blob
|
|
836
|
+
await storage.delete(self._bucket, temp_blob)
|
|
@@ -176,7 +176,8 @@ class GSClient(SyncClient):
|
|
|
176
176
|
path: GCS path (gs://bucket/blob)
|
|
177
177
|
mode: File mode ('r', 'w', 'rb', 'wb', 'a', 'ab')
|
|
178
178
|
encoding: Text encoding (for text modes)
|
|
179
|
-
**kwargs: Additional arguments (chunk_size
|
|
179
|
+
**kwargs: Additional arguments (chunk_size, upload_warning_threshold,
|
|
180
|
+
upload_interval supported)
|
|
180
181
|
|
|
181
182
|
Returns:
|
|
182
183
|
GSSyncFileHandle with streaming support
|
|
@@ -648,14 +649,18 @@ class GSSyncFileHandle(SyncFileHandle):
|
|
|
648
649
|
self._blob.upload_from_string(data)
|
|
649
650
|
else:
|
|
650
651
|
bucket = self._blob.bucket
|
|
651
|
-
|
|
652
|
+
# Use upload count to ensure unique temp blob names across multiple flushes
|
|
653
|
+
temp_blob_name = f"{self._blob.name}.tmp.{os.getpid()}.{self._upload_count}"
|
|
652
654
|
temp_blob = bucket.blob(temp_blob_name)
|
|
653
655
|
|
|
654
656
|
# Upload new data to temp blob
|
|
655
657
|
temp_blob.upload_from_string(data)
|
|
656
658
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
#
|
|
661
|
-
|
|
659
|
+
try:
|
|
660
|
+
# Compose: original + temp = original
|
|
661
|
+
self._blob.compose([self._blob, temp_blob])
|
|
662
|
+
except Exception as e: # pragma: no cover
|
|
663
|
+
raise IOError(f"Failed to append data to GCS blob: {self._blob}") from e
|
|
664
|
+
finally:
|
|
665
|
+
# Clean up temp blob
|
|
666
|
+
temp_blob.delete()
|
|
@@ -79,7 +79,7 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
|
|
|
79
79
|
|
|
80
80
|
target_str = str(target)
|
|
81
81
|
await aiofiles.os.rename(str(self), target_str)
|
|
82
|
-
return PanPath(target_str)
|
|
82
|
+
return PanPath(target_str)
|
|
83
83
|
|
|
84
84
|
async def a_replace(self, target: Union[str, "Path"]) -> "PanPath":
|
|
85
85
|
"""Rename the file or directory to target, overwriting if target exists.
|
|
@@ -131,7 +131,7 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
|
|
|
131
131
|
break
|
|
132
132
|
await df.write(chunk)
|
|
133
133
|
|
|
134
|
-
return PanPath(target_str)
|
|
134
|
+
return PanPath(target_str)
|
|
135
135
|
|
|
136
136
|
async def a_copytree(
|
|
137
137
|
self,
|
|
@@ -154,7 +154,7 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
|
|
|
154
154
|
extra="all-async",
|
|
155
155
|
)
|
|
156
156
|
|
|
157
|
-
target = PanPath(target)
|
|
157
|
+
target = PanPath(target)
|
|
158
158
|
await target.a_mkdir(parents=True, exist_ok=True)
|
|
159
159
|
|
|
160
160
|
async for entry in self.a_iterdir():
|
|
@@ -207,7 +207,7 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
|
|
|
207
207
|
extra="all-async",
|
|
208
208
|
)
|
|
209
209
|
|
|
210
|
-
return PanPath( # type: ignore[return-value
|
|
210
|
+
return PanPath( # type: ignore[return-value]
|
|
211
211
|
await aiofiles.os.readlink(str(self))
|
|
212
212
|
)
|
|
213
213
|
|
|
@@ -298,7 +298,8 @@ class AsyncS3Client(AsyncClient):
|
|
|
298
298
|
path: S3 path (s3://bucket/key)
|
|
299
299
|
mode: File mode ('r', 'w', 'rb', 'wb', 'a', 'ab')
|
|
300
300
|
encoding: Text encoding (for text modes)
|
|
301
|
-
**kwargs: Additional arguments (
|
|
301
|
+
**kwargs: Additional arguments (chunk_size, upload_warning_threshold,
|
|
302
|
+
upload_interval supported)
|
|
302
303
|
|
|
303
304
|
Returns:
|
|
304
305
|
S3AsyncFileHandle with streaming support
|
|
@@ -188,7 +188,8 @@ class S3Client(SyncClient):
|
|
|
188
188
|
path: S3 path (s3://bucket/key)
|
|
189
189
|
mode: File mode ('r', 'w', 'rb', 'wb', 'a', 'ab')
|
|
190
190
|
encoding: Text encoding (for text modes)
|
|
191
|
-
**kwargs: Additional arguments (chunk_size
|
|
191
|
+
**kwargs: Additional arguments (chunk_size, upload_warning_threshold,
|
|
192
|
+
upload_interval supported)
|
|
192
193
|
|
|
193
194
|
Returns:
|
|
194
195
|
S3SyncFileHandle with streaming support
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "panpath"
|
|
7
|
-
version = "0.4.
|
|
7
|
+
version = "0.4.7"
|
|
8
8
|
description = "Universal sync/async local/cloud path library with pathlib-compatible interface"
|
|
9
9
|
authors = ["panpath contributors"]
|
|
10
10
|
readme = "README.md"
|
|
@@ -40,7 +40,7 @@ azure-storage-blob = {version = ">=12.0.0", optional = true}
|
|
|
40
40
|
# Async cloud storage backends
|
|
41
41
|
aioboto3 = {version = ">=11.0.0", optional = true}
|
|
42
42
|
aiofiles = {version = ">=23.0.0", optional = true}
|
|
43
|
-
gcloud-aio-storage = {version = ">=
|
|
43
|
+
gcloud-aio-storage = {version = ">=9.5", optional = true}
|
|
44
44
|
|
|
45
45
|
[tool.poetry.extras]
|
|
46
46
|
s3 = ["boto3"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|