panpath 0.4.10__tar.gz → 0.4.11__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.10 → panpath-0.4.11}/PKG-INFO +40 -26
- {panpath-0.4.10 → panpath-0.4.11}/panpath/__init__.py +1 -1
- {panpath-0.4.10 → panpath-0.4.11}/panpath/azure_async_client.py +33 -31
- {panpath-0.4.10 → panpath-0.4.11}/panpath/azure_client.py +37 -33
- {panpath-0.4.10 → panpath-0.4.11}/panpath/azure_path.py +2 -2
- {panpath-0.4.10 → panpath-0.4.11}/panpath/base.py +22 -22
- {panpath-0.4.10 → panpath-0.4.11}/panpath/cloud.py +41 -21
- {panpath-0.4.10 → panpath-0.4.11}/panpath/gs_async_client.py +36 -32
- {panpath-0.4.10 → panpath-0.4.11}/panpath/gs_client.py +41 -32
- {panpath-0.4.10 → panpath-0.4.11}/panpath/gs_path.py +2 -2
- {panpath-0.4.10 → panpath-0.4.11}/panpath/local_path.py +4 -3
- {panpath-0.4.10 → panpath-0.4.11}/panpath/s3_async_client.py +95 -71
- {panpath-0.4.10 → panpath-0.4.11}/panpath/s3_client.py +27 -27
- panpath-0.4.11/panpath.egg-info/PKG-INFO +268 -0
- panpath-0.4.11/panpath.egg-info/SOURCES.txt +41 -0
- panpath-0.4.11/panpath.egg-info/dependency_links.txt +1 -0
- panpath-0.4.11/panpath.egg-info/requires.txt +41 -0
- panpath-0.4.11/panpath.egg-info/top_level.txt +1 -0
- panpath-0.4.11/pyproject.toml +105 -0
- panpath-0.4.11/setup.cfg +4 -0
- panpath-0.4.11/tests/test_azure.py +74 -0
- panpath-0.4.11/tests/test_azure_async_client.py +742 -0
- panpath-0.4.11/tests/test_azure_client.py +717 -0
- panpath-0.4.11/tests/test_base.py +20 -0
- panpath-0.4.11/tests/test_cloudpath.py +1107 -0
- panpath-0.4.11/tests/test_cloudpath_compat.py +327 -0
- panpath-0.4.11/tests/test_exceptions.py +48 -0
- panpath-0.4.11/tests/test_gs.py +87 -0
- panpath-0.4.11/tests/test_gs_async_client.py +778 -0
- panpath-0.4.11/tests/test_gs_client.py +657 -0
- panpath-0.4.11/tests/test_local.py +631 -0
- panpath-0.4.11/tests/test_registry.py +138 -0
- panpath-0.4.11/tests/test_router.py +72 -0
- panpath-0.4.11/tests/test_s3.py +105 -0
- panpath-0.4.11/tests/test_s3_async_client.py +727 -0
- panpath-0.4.11/tests/test_s3_client.py +560 -0
- panpath-0.4.10/pyproject.toml +0 -95
- {panpath-0.4.10 → panpath-0.4.11}/LICENSE +0 -0
- {panpath-0.4.10 → panpath-0.4.11}/README.md +0 -0
- {panpath-0.4.10 → panpath-0.4.11}/panpath/clients.py +0 -0
- {panpath-0.4.10 → panpath-0.4.11}/panpath/exceptions.py +0 -0
- {panpath-0.4.10 → panpath-0.4.11}/panpath/py.typed +0 -0
- {panpath-0.4.10 → panpath-0.4.11}/panpath/registry.py +0 -0
- {panpath-0.4.10 → panpath-0.4.11}/panpath/s3_path.py +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: panpath
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.11
|
|
4
4
|
Summary: Universal sync/async local/cloud path library with pathlib-compatible interface
|
|
5
|
+
Author: panpath contributors
|
|
5
6
|
License: MIT
|
|
6
|
-
|
|
7
|
+
Project-URL: Homepage, https://github.com/pwwang/panpath
|
|
8
|
+
Project-URL: Repository, https://github.com/pwwang/panpath
|
|
9
|
+
Project-URL: Documentation, https://github.com/pwwang/panpath#readme
|
|
7
10
|
Keywords: path,pathlib,s3,gcs,azure,cloud,async,asyncio
|
|
8
|
-
Author: panpath contributors
|
|
9
|
-
Requires-Python: >=3.9,<4.0
|
|
10
11
|
Classifier: Development Status :: 3 - Alpha
|
|
11
12
|
Classifier: Intended Audience :: Developers
|
|
12
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -15,30 +16,44 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
15
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
20
19
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
20
|
Classifier: Topic :: System :: Filesystems
|
|
22
|
-
|
|
23
|
-
Provides-Extra: all-async
|
|
24
|
-
Provides-Extra: all-sync
|
|
25
|
-
Provides-Extra: async-azure
|
|
26
|
-
Provides-Extra: async-gs
|
|
27
|
-
Provides-Extra: async-s3
|
|
28
|
-
Provides-Extra: azure
|
|
29
|
-
Provides-Extra: gs
|
|
30
|
-
Provides-Extra: s3
|
|
31
|
-
Requires-Dist: aioboto3 (>=11.0.0) ; extra == "async-s3" or extra == "all-async" or extra == "all"
|
|
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
|
-
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
|
-
Requires-Dist: boto3 (>=1.20.0) ; extra == "s3" or extra == "all-sync" or extra == "all"
|
|
35
|
-
Requires-Dist: gcloud-aio-storage (>=9.5) ; extra == "async-gs" or extra == "all-async" or extra == "all"
|
|
36
|
-
Requires-Dist: google-cloud-storage (>=2.0.0) ; extra == "gs" or extra == "all-sync" or extra == "all"
|
|
37
|
-
Requires-Dist: typing-extensions (>=4.0.0)
|
|
38
|
-
Project-URL: Documentation, https://github.com/pwwang/panpath#readme
|
|
39
|
-
Project-URL: Homepage, https://github.com/pwwang/panpath
|
|
40
|
-
Project-URL: Repository, https://github.com/pwwang/panpath
|
|
21
|
+
Requires-Python: <4.0,>=3.9
|
|
41
22
|
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
25
|
+
Provides-Extra: s3
|
|
26
|
+
Requires-Dist: boto3>=1.20.0; extra == "s3"
|
|
27
|
+
Provides-Extra: gs
|
|
28
|
+
Requires-Dist: google-cloud-storage>=2.0.0; extra == "gs"
|
|
29
|
+
Provides-Extra: azure
|
|
30
|
+
Requires-Dist: azure-storage-blob>=12.0.0; extra == "azure"
|
|
31
|
+
Provides-Extra: async-s3
|
|
32
|
+
Requires-Dist: aioboto3>=11.0.0; extra == "async-s3"
|
|
33
|
+
Requires-Dist: aiofiles>=23.0.0; extra == "async-s3"
|
|
34
|
+
Provides-Extra: async-gs
|
|
35
|
+
Requires-Dist: gcloud-aio-storage>=9.5; extra == "async-gs"
|
|
36
|
+
Requires-Dist: aiofiles>=23.0.0; extra == "async-gs"
|
|
37
|
+
Provides-Extra: async-azure
|
|
38
|
+
Requires-Dist: azure-storage-blob>=12.0.0; extra == "async-azure"
|
|
39
|
+
Requires-Dist: aiofiles>=23.0.0; extra == "async-azure"
|
|
40
|
+
Provides-Extra: all-sync
|
|
41
|
+
Requires-Dist: boto3>=1.20.0; extra == "all-sync"
|
|
42
|
+
Requires-Dist: google-cloud-storage>=2.0.0; extra == "all-sync"
|
|
43
|
+
Requires-Dist: azure-storage-blob>=12.0.0; extra == "all-sync"
|
|
44
|
+
Provides-Extra: all-async
|
|
45
|
+
Requires-Dist: aioboto3>=11.0.0; extra == "all-async"
|
|
46
|
+
Requires-Dist: gcloud-aio-storage>=9.5; extra == "all-async"
|
|
47
|
+
Requires-Dist: azure-storage-blob>=12.0.0; extra == "all-async"
|
|
48
|
+
Requires-Dist: aiofiles>=23.0.0; extra == "all-async"
|
|
49
|
+
Provides-Extra: all
|
|
50
|
+
Requires-Dist: boto3>=1.20.0; extra == "all"
|
|
51
|
+
Requires-Dist: google-cloud-storage>=2.0.0; extra == "all"
|
|
52
|
+
Requires-Dist: azure-storage-blob>=12.0.0; extra == "all"
|
|
53
|
+
Requires-Dist: aioboto3>=11.0.0; extra == "all"
|
|
54
|
+
Requires-Dist: gcloud-aio-storage>=9.5; extra == "all"
|
|
55
|
+
Requires-Dist: aiofiles>=23.0.0; extra == "all"
|
|
56
|
+
Dynamic: license-file
|
|
42
57
|
|
|
43
58
|
# PanPath
|
|
44
59
|
|
|
@@ -251,4 +266,3 @@ path = PanPath("/local/file.txt")
|
|
|
251
266
|
## License
|
|
252
267
|
|
|
253
268
|
MIT License - see LICENSE file for details.
|
|
254
|
-
|
|
@@ -88,7 +88,7 @@ class AsyncAzureBlobClient(AsyncClient):
|
|
|
88
88
|
self._kwargs = kwargs
|
|
89
89
|
self._client_ref: Optional[weakref.ref] = None # type: ignore[type-arg]
|
|
90
90
|
|
|
91
|
-
async def _get_client(self) -> BlobServiceClient:
|
|
91
|
+
async def _get_client(self) -> Optional[BlobServiceClient]:
|
|
92
92
|
"""Get or create shared BlobServiceClient."""
|
|
93
93
|
# Check if client needs to be recreated (closed or never created)
|
|
94
94
|
needs_recreation = False
|
|
@@ -552,20 +552,20 @@ class AsyncAzureBlobClient(AsyncClient):
|
|
|
552
552
|
|
|
553
553
|
await blob_client.upload_blob(b"", overwrite=True)
|
|
554
554
|
|
|
555
|
-
async def rename(self,
|
|
555
|
+
async def rename(self, src: str, dst: str) -> None:
|
|
556
556
|
"""Rename/move file.
|
|
557
557
|
|
|
558
558
|
Args:
|
|
559
559
|
source: Source Azure path
|
|
560
560
|
target: Target Azure path
|
|
561
561
|
"""
|
|
562
|
-
if not await self.exists(
|
|
563
|
-
raise FileNotFoundError(f"Source not found: {
|
|
562
|
+
if not await self.exists(src):
|
|
563
|
+
raise FileNotFoundError(f"Source not found: {src}")
|
|
564
564
|
|
|
565
565
|
# Copy to new location
|
|
566
566
|
client = await self._get_client()
|
|
567
|
-
src_container, src_blob = self.__class__._parse_path(
|
|
568
|
-
tgt_container, tgt_blob = self.__class__._parse_path(
|
|
567
|
+
src_container, src_blob = self.__class__._parse_path(src)
|
|
568
|
+
tgt_container, tgt_blob = self.__class__._parse_path(dst)
|
|
569
569
|
|
|
570
570
|
src_blob_client = client.get_blob_client(src_container, src_blob)
|
|
571
571
|
tgt_blob_client = client.get_blob_client(tgt_container, tgt_blob)
|
|
@@ -610,7 +610,7 @@ class AsyncAzureBlobClient(AsyncClient):
|
|
|
610
610
|
Args:
|
|
611
611
|
path: Azure path
|
|
612
612
|
ignore_errors: If True, errors are ignored
|
|
613
|
-
onerror:
|
|
613
|
+
onerror: Async callable that accepts (function, path, excinfo)
|
|
614
614
|
"""
|
|
615
615
|
if not await self.exists(path):
|
|
616
616
|
if ignore_errors:
|
|
@@ -630,6 +630,7 @@ class AsyncAzureBlobClient(AsyncClient):
|
|
|
630
630
|
if prefix and not prefix.endswith("/"):
|
|
631
631
|
prefix += "/"
|
|
632
632
|
|
|
633
|
+
delete_blob = None
|
|
633
634
|
try:
|
|
634
635
|
client = await self._get_client()
|
|
635
636
|
container_client = client.get_container_client(container_name)
|
|
@@ -637,37 +638,38 @@ class AsyncAzureBlobClient(AsyncClient):
|
|
|
637
638
|
# List and delete all blobs with this prefix
|
|
638
639
|
async for blob in container_client.list_blobs(name_starts_with=prefix):
|
|
639
640
|
blob_client = client.get_blob_client(container_name, blob.name)
|
|
640
|
-
|
|
641
|
+
delete_blob = blob_client.delete_blob
|
|
642
|
+
await delete_blob()
|
|
641
643
|
except Exception: # pragma: no cover
|
|
642
644
|
if ignore_errors:
|
|
643
645
|
return
|
|
644
646
|
if onerror is not None:
|
|
645
647
|
import sys
|
|
646
648
|
|
|
647
|
-
onerror(
|
|
649
|
+
await onerror(delete_blob, path, sys.exc_info())
|
|
648
650
|
else:
|
|
649
651
|
raise
|
|
650
652
|
|
|
651
|
-
async def copy(self,
|
|
653
|
+
async def copy(self, src: str, dst: str, follow_symlinks: bool = True) -> None:
|
|
652
654
|
"""Copy file to target.
|
|
653
655
|
|
|
654
656
|
Args:
|
|
655
|
-
|
|
656
|
-
|
|
657
|
+
src: Source Azure path
|
|
658
|
+
dst: Target Azure path
|
|
657
659
|
follow_symlinks: If False, symlinks are copied as symlinks (not dereferenced)
|
|
658
660
|
"""
|
|
659
|
-
if not await self.exists(
|
|
660
|
-
raise FileNotFoundError(f"Source not found: {
|
|
661
|
+
if not await self.exists(src):
|
|
662
|
+
raise FileNotFoundError(f"Source not found: {src}")
|
|
661
663
|
|
|
662
|
-
if follow_symlinks and await self.is_symlink(
|
|
663
|
-
|
|
664
|
+
if follow_symlinks and await self.is_symlink(src):
|
|
665
|
+
src = await self.readlink(src)
|
|
664
666
|
|
|
665
|
-
if await self.is_dir(
|
|
666
|
-
raise IsADirectoryError(f"Source is a directory: {
|
|
667
|
+
if await self.is_dir(src):
|
|
668
|
+
raise IsADirectoryError(f"Source is a directory: {src}")
|
|
667
669
|
|
|
668
670
|
client = await self._get_client()
|
|
669
|
-
src_container_name, src_blob_name = self.__class__._parse_path(
|
|
670
|
-
tgt_container_name, tgt_blob_name = self.__class__._parse_path(
|
|
671
|
+
src_container_name, src_blob_name = self.__class__._parse_path(src)
|
|
672
|
+
tgt_container_name, tgt_blob_name = self.__class__._parse_path(dst)
|
|
671
673
|
|
|
672
674
|
src_blob_client = client.get_blob_client(src_container_name, src_blob_name)
|
|
673
675
|
tgt_blob_client = client.get_blob_client(tgt_container_name, tgt_blob_name)
|
|
@@ -676,25 +678,25 @@ class AsyncAzureBlobClient(AsyncClient):
|
|
|
676
678
|
source_url = src_blob_client.url
|
|
677
679
|
await tgt_blob_client.start_copy_from_url(source_url)
|
|
678
680
|
|
|
679
|
-
async def copytree(self,
|
|
681
|
+
async def copytree(self, src: str, dst: str, follow_symlinks: bool = True) -> None:
|
|
680
682
|
"""Copy directory tree to target recursively.
|
|
681
683
|
|
|
682
684
|
Args:
|
|
683
|
-
|
|
684
|
-
|
|
685
|
+
src: Source Azure path
|
|
686
|
+
dst: Target Azure path
|
|
685
687
|
follow_symlinks: If False, symlinks are copied as symlinks (not dereferenced)
|
|
686
688
|
"""
|
|
687
|
-
if not await self.exists(
|
|
688
|
-
raise FileNotFoundError(f"Source not found: {
|
|
689
|
+
if not await self.exists(src):
|
|
690
|
+
raise FileNotFoundError(f"Source not found: {src}")
|
|
689
691
|
|
|
690
|
-
if follow_symlinks and await self.is_symlink(
|
|
691
|
-
|
|
692
|
+
if follow_symlinks and await self.is_symlink(src):
|
|
693
|
+
src = await self.readlink(src)
|
|
692
694
|
|
|
693
|
-
if not await self.is_dir(
|
|
694
|
-
raise NotADirectoryError(f"Source is not a directory: {
|
|
695
|
+
if not await self.is_dir(src):
|
|
696
|
+
raise NotADirectoryError(f"Source is not a directory: {src}")
|
|
695
697
|
|
|
696
|
-
src_container_name, src_prefix = self.__class__._parse_path(
|
|
697
|
-
tgt_container_name, tgt_prefix = self.__class__._parse_path(
|
|
698
|
+
src_container_name, src_prefix = self.__class__._parse_path(src)
|
|
699
|
+
tgt_container_name, tgt_prefix = self.__class__._parse_path(dst)
|
|
698
700
|
|
|
699
701
|
# Ensure prefixes end with / for directory operations
|
|
700
702
|
if src_prefix and not src_prefix.endswith("/"):
|
|
@@ -419,19 +419,19 @@ class AzureBlobClient(SyncClient):
|
|
|
419
419
|
blob_client = self._client.get_blob_client(container_name, blob_name)
|
|
420
420
|
blob_client.upload_blob(b"", overwrite=True)
|
|
421
421
|
|
|
422
|
-
def rename(self,
|
|
422
|
+
def rename(self, src: str, dst: str) -> None:
|
|
423
423
|
"""Rename/move file.
|
|
424
424
|
|
|
425
425
|
Args:
|
|
426
|
-
|
|
427
|
-
|
|
426
|
+
src: Source Azure path
|
|
427
|
+
dst: Target Azure path
|
|
428
428
|
"""
|
|
429
|
-
if not self.exists(
|
|
430
|
-
raise FileNotFoundError(f"Source not found: {
|
|
429
|
+
if not self.exists(src):
|
|
430
|
+
raise FileNotFoundError(f"Source not found: {src}")
|
|
431
431
|
|
|
432
432
|
# Copy to new location
|
|
433
|
-
src_container, src_blob = self.__class__._parse_path(
|
|
434
|
-
tgt_container, tgt_blob = self.__class__._parse_path(
|
|
433
|
+
src_container, src_blob = self.__class__._parse_path(src)
|
|
434
|
+
tgt_container, tgt_blob = self.__class__._parse_path(dst)
|
|
435
435
|
|
|
436
436
|
src_blob_client = self._client.get_blob_client(src_container, src_blob)
|
|
437
437
|
tgt_blob_client = self._client.get_blob_client(tgt_container, tgt_blob)
|
|
@@ -491,42 +491,46 @@ class AzureBlobClient(SyncClient):
|
|
|
491
491
|
if prefix and not prefix.endswith("/"):
|
|
492
492
|
prefix += "/"
|
|
493
493
|
|
|
494
|
+
blobs_delete = None
|
|
494
495
|
try:
|
|
495
496
|
container_client = self._client.get_container_client(container_name)
|
|
496
497
|
|
|
497
498
|
# List and delete all blobs with this prefix
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
499
|
+
def _blobs_delete():
|
|
500
|
+
for blob in container_client.list_blobs(name_starts_with=prefix):
|
|
501
|
+
blob_client = self._client.get_blob_client(container_name, blob.name)
|
|
502
|
+
blob_client.delete_blob()
|
|
503
|
+
blobs_delete = _blobs_delete
|
|
504
|
+
blobs_delete()
|
|
501
505
|
except Exception: # pragma: no cover
|
|
502
506
|
if ignore_errors:
|
|
503
507
|
return
|
|
504
508
|
if onerror is not None:
|
|
505
509
|
import sys
|
|
506
510
|
|
|
507
|
-
onerror(
|
|
511
|
+
onerror(blobs_delete, path, sys.exc_info())
|
|
508
512
|
else:
|
|
509
513
|
raise
|
|
510
514
|
|
|
511
|
-
def copy(self,
|
|
515
|
+
def copy(self, src: str, dst: str, follow_symlinks: bool = True) -> None:
|
|
512
516
|
"""Copy file to target.
|
|
513
517
|
|
|
514
518
|
Args:
|
|
515
|
-
|
|
516
|
-
|
|
519
|
+
src: Source Azure path
|
|
520
|
+
dst: Target Azure path
|
|
517
521
|
follow_symlinks: If False, symlinks are copied as symlinks (not dereferenced)
|
|
518
522
|
"""
|
|
519
|
-
if not self.exists(
|
|
520
|
-
raise FileNotFoundError(f"Source not found: {
|
|
523
|
+
if not self.exists(src):
|
|
524
|
+
raise FileNotFoundError(f"Source not found: {src}")
|
|
521
525
|
|
|
522
|
-
if follow_symlinks and self.is_symlink(
|
|
523
|
-
|
|
526
|
+
if follow_symlinks and self.is_symlink(src):
|
|
527
|
+
src = self.readlink(src)
|
|
524
528
|
|
|
525
|
-
if self.is_dir(
|
|
526
|
-
raise IsADirectoryError(f"Source is a directory: {
|
|
529
|
+
if self.is_dir(src):
|
|
530
|
+
raise IsADirectoryError(f"Source is a directory: {src}")
|
|
527
531
|
|
|
528
|
-
src_container_name, src_blob_name = self.__class__._parse_path(
|
|
529
|
-
tgt_container_name, tgt_blob_name = self.__class__._parse_path(
|
|
532
|
+
src_container_name, src_blob_name = self.__class__._parse_path(src)
|
|
533
|
+
tgt_container_name, tgt_blob_name = self.__class__._parse_path(dst)
|
|
530
534
|
|
|
531
535
|
src_blob_client = self._client.get_blob_client(src_container_name, src_blob_name)
|
|
532
536
|
tgt_blob_client = self._client.get_blob_client(tgt_container_name, tgt_blob_name)
|
|
@@ -535,25 +539,25 @@ class AzureBlobClient(SyncClient):
|
|
|
535
539
|
source_url = src_blob_client.url
|
|
536
540
|
tgt_blob_client.start_copy_from_url(source_url)
|
|
537
541
|
|
|
538
|
-
def copytree(self,
|
|
542
|
+
def copytree(self, src: str, dst: str, follow_symlinks: bool = True) -> None:
|
|
539
543
|
"""Copy directory tree to target recursively.
|
|
540
544
|
|
|
541
545
|
Args:
|
|
542
|
-
|
|
543
|
-
|
|
546
|
+
src: Source Azure path
|
|
547
|
+
dst: Target Azure path
|
|
544
548
|
follow_symlinks: If False, symlinks are copied as symlinks (not dereferenced)
|
|
545
549
|
"""
|
|
546
|
-
if not self.exists(
|
|
547
|
-
raise FileNotFoundError(f"Source not found: {
|
|
550
|
+
if not self.exists(src):
|
|
551
|
+
raise FileNotFoundError(f"Source not found: {src}")
|
|
548
552
|
|
|
549
|
-
if follow_symlinks and self.is_symlink(
|
|
550
|
-
|
|
553
|
+
if follow_symlinks and self.is_symlink(src):
|
|
554
|
+
src = self.readlink(src)
|
|
551
555
|
|
|
552
|
-
if not self.is_dir(
|
|
553
|
-
raise NotADirectoryError(f"Source is not a directory: {
|
|
556
|
+
if not self.is_dir(src):
|
|
557
|
+
raise NotADirectoryError(f"Source is not a directory: {src}")
|
|
554
558
|
|
|
555
|
-
src_container_name, src_prefix = self.__class__._parse_path(
|
|
556
|
-
tgt_container_name, tgt_prefix = self.__class__._parse_path(
|
|
559
|
+
src_container_name, src_prefix = self.__class__._parse_path(src)
|
|
560
|
+
tgt_container_name, tgt_prefix = self.__class__._parse_path(dst)
|
|
557
561
|
|
|
558
562
|
# Ensure prefixes end with / for directory operations
|
|
559
563
|
if src_prefix and not src_prefix.endswith("/"):
|
|
@@ -11,8 +11,8 @@ if TYPE_CHECKING:
|
|
|
11
11
|
class AzurePath(CloudPath):
|
|
12
12
|
"""Azure Blob Storage path implementation (sync and async methods)."""
|
|
13
13
|
|
|
14
|
-
_client: Optional[Client] = None
|
|
15
|
-
_default_client: Optional[Client] = None
|
|
14
|
+
_client: Optional[Client] = None # type: ignore[assignment]
|
|
15
|
+
_default_client: Optional[Client] = None # type: ignore[assignment]
|
|
16
16
|
|
|
17
17
|
@classmethod
|
|
18
18
|
def _create_default_client(cls) -> "Client": # type: ignore[override]
|
|
@@ -166,11 +166,11 @@ class PanPath(PathlibPath):
|
|
|
166
166
|
Number of bytes written. For some cloud paths, may return None.
|
|
167
167
|
"""
|
|
168
168
|
|
|
169
|
-
async def a_write_text(
|
|
169
|
+
async def a_write_text(
|
|
170
170
|
self,
|
|
171
171
|
data: str,
|
|
172
172
|
encoding: str = "utf-8",
|
|
173
|
-
) -> int:
|
|
173
|
+
) -> int: # type: ignore[empty-body]
|
|
174
174
|
"""Asynchronously write text to the file.
|
|
175
175
|
|
|
176
176
|
Args:
|
|
@@ -209,10 +209,10 @@ class PanPath(PathlibPath):
|
|
|
209
209
|
True if the path is a file, False otherwise.
|
|
210
210
|
"""
|
|
211
211
|
|
|
212
|
-
async def a_stat(
|
|
212
|
+
async def a_stat(
|
|
213
213
|
self,
|
|
214
214
|
follow_symlinks: bool = True,
|
|
215
|
-
) -> os.stat_result:
|
|
215
|
+
) -> os.stat_result: # type: ignore[empty-body]
|
|
216
216
|
"""Asynchronously get the file or directory's status information.
|
|
217
217
|
|
|
218
218
|
Returns:
|
|
@@ -233,10 +233,10 @@ class PanPath(PathlibPath):
|
|
|
233
233
|
exist_ok: If True, does not raise an error if the directory already exists.
|
|
234
234
|
"""
|
|
235
235
|
|
|
236
|
-
async def a_glob(
|
|
236
|
+
async def a_glob(
|
|
237
237
|
self,
|
|
238
238
|
pattern: str,
|
|
239
|
-
) -> AsyncGenerator["PanPath", None]:
|
|
239
|
+
) -> AsyncGenerator["PanPath", None]: # type: ignore[empty-body]
|
|
240
240
|
"""Asynchronously yield paths matching a glob pattern.
|
|
241
241
|
|
|
242
242
|
Args:
|
|
@@ -246,10 +246,10 @@ class PanPath(PathlibPath):
|
|
|
246
246
|
List of PanPath instances matching the pattern.
|
|
247
247
|
"""
|
|
248
248
|
|
|
249
|
-
async def a_rglob(
|
|
249
|
+
async def a_rglob(
|
|
250
250
|
self,
|
|
251
251
|
pattern: str,
|
|
252
|
-
) -> AsyncGenerator["PanPath", None]:
|
|
252
|
+
) -> AsyncGenerator["PanPath", None]: # type: ignore[empty-body]
|
|
253
253
|
"""Asynchronously yield paths matching a recursive glob pattern.
|
|
254
254
|
|
|
255
255
|
Args:
|
|
@@ -259,9 +259,9 @@ class PanPath(PathlibPath):
|
|
|
259
259
|
List of PanPath instances matching the pattern.
|
|
260
260
|
"""
|
|
261
261
|
|
|
262
|
-
async def a_walk(
|
|
262
|
+
async def a_walk(
|
|
263
263
|
self,
|
|
264
|
-
) -> AsyncGenerator[tuple["PanPath", List[str], List[str]], None]:
|
|
264
|
+
) -> AsyncGenerator[tuple["PanPath", List[str], List[str]], None]: # type: ignore[empty-body]
|
|
265
265
|
"""Asynchronously walk the directory tree.
|
|
266
266
|
|
|
267
267
|
Yields:
|
|
@@ -280,10 +280,10 @@ class PanPath(PathlibPath):
|
|
|
280
280
|
exist_ok: If False, raises an error if the file already exists.
|
|
281
281
|
"""
|
|
282
282
|
|
|
283
|
-
async def a_rename(
|
|
283
|
+
async def a_rename(
|
|
284
284
|
self,
|
|
285
285
|
target: Union[str, "PathlibPath"],
|
|
286
|
-
) -> "PanPath":
|
|
286
|
+
) -> "PanPath": # type: ignore[empty-body]
|
|
287
287
|
"""Asynchronously rename this path to the target path.
|
|
288
288
|
|
|
289
289
|
Args:
|
|
@@ -293,10 +293,10 @@ class PanPath(PathlibPath):
|
|
|
293
293
|
The renamed PanPath instance.
|
|
294
294
|
"""
|
|
295
295
|
|
|
296
|
-
async def a_replace(
|
|
296
|
+
async def a_replace(
|
|
297
297
|
self,
|
|
298
298
|
target: Union[str, "PathlibPath"],
|
|
299
|
-
) -> "PanPath":
|
|
299
|
+
) -> "PanPath": # type: ignore[empty-body]
|
|
300
300
|
"""Asynchronously replace this path with the target path.
|
|
301
301
|
|
|
302
302
|
Args:
|
|
@@ -351,13 +351,13 @@ class PanPath(PathlibPath):
|
|
|
351
351
|
|
|
352
352
|
Args:
|
|
353
353
|
ignore_errors: If True, ignores errors during removal.
|
|
354
|
-
onerror: Optional function to call on errors.
|
|
354
|
+
onerror: Optional async function to call on errors.
|
|
355
355
|
"""
|
|
356
356
|
|
|
357
|
-
async def a_copy(
|
|
357
|
+
async def a_copy(
|
|
358
358
|
self,
|
|
359
359
|
target: Union[str, "PathlibPath"],
|
|
360
|
-
) -> "PanPath":
|
|
360
|
+
) -> "PanPath": # type: ignore[empty-body]
|
|
361
361
|
"""Asynchronously copy this path to the target path.
|
|
362
362
|
|
|
363
363
|
Args:
|
|
@@ -367,11 +367,11 @@ class PanPath(PathlibPath):
|
|
|
367
367
|
The copied PanPath instance.
|
|
368
368
|
"""
|
|
369
369
|
|
|
370
|
-
async def a_copytree(
|
|
370
|
+
async def a_copytree(
|
|
371
371
|
self,
|
|
372
372
|
target: Union[str, "PathlibPath"],
|
|
373
373
|
follow_symlinks: bool = True,
|
|
374
|
-
) -> "PanPath":
|
|
374
|
+
) -> "PanPath": # type: ignore[empty-body]
|
|
375
375
|
"""Asynchronously copy the directory and all its contents recursively to the target path.
|
|
376
376
|
|
|
377
377
|
Args:
|
|
@@ -382,12 +382,12 @@ class PanPath(PathlibPath):
|
|
|
382
382
|
The copied PanPath instance.
|
|
383
383
|
"""
|
|
384
384
|
|
|
385
|
-
def a_open(
|
|
385
|
+
def a_open(
|
|
386
386
|
self,
|
|
387
387
|
mode: str = "r",
|
|
388
388
|
encoding: str = "utf-8",
|
|
389
389
|
**kwargs: Any,
|
|
390
|
-
) -> "AsyncFileHandle":
|
|
390
|
+
) -> "AsyncFileHandle": # type: ignore[empty-body]
|
|
391
391
|
"""Asynchronously open the file and return an async file handle.
|
|
392
392
|
|
|
393
393
|
Args:
|
|
@@ -400,7 +400,7 @@ class PanPath(PathlibPath):
|
|
|
400
400
|
"""
|
|
401
401
|
|
|
402
402
|
# backports
|
|
403
|
-
def walk(self) -> Any:
|
|
403
|
+
def walk(self) -> Any: # type: ignore[empty-body]
|
|
404
404
|
"""Walk the directory tree.
|
|
405
405
|
|
|
406
406
|
Yields:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Base classes for cloud path implementations."""
|
|
2
|
+
from __future__ import annotations
|
|
2
3
|
|
|
3
4
|
import sys
|
|
4
5
|
|
|
@@ -150,8 +151,14 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
150
151
|
return ""
|
|
151
152
|
|
|
152
153
|
# Cloud storage operations delegated to client
|
|
153
|
-
def exists(self) -> bool:
|
|
154
|
-
"""Check if path exists.
|
|
154
|
+
def exists(self, *, follow_symlinks: bool = True) -> bool:
|
|
155
|
+
"""Check if path exists.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
follow_symlinks: If False, report existence of the symlink itself.
|
|
159
|
+
"""
|
|
160
|
+
if not follow_symlinks and self.is_symlink():
|
|
161
|
+
return True
|
|
155
162
|
return self.client.exists(str(self))
|
|
156
163
|
|
|
157
164
|
def read_bytes(self) -> bytes:
|
|
@@ -191,7 +198,7 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
191
198
|
"""Check if path is a file."""
|
|
192
199
|
return self.client.is_file(str(self))
|
|
193
200
|
|
|
194
|
-
def stat(self, follow_symlinks: bool = True) -> Any:
|
|
201
|
+
def stat(self, *, follow_symlinks: bool = True) -> Any:
|
|
195
202
|
"""Get file stats."""
|
|
196
203
|
if follow_symlinks and self.is_symlink():
|
|
197
204
|
target = self.readlink()
|
|
@@ -246,7 +253,12 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
246
253
|
"""Return the path as a URI (same as string representation)."""
|
|
247
254
|
return str(self)
|
|
248
255
|
|
|
249
|
-
def match(
|
|
256
|
+
def match(
|
|
257
|
+
self,
|
|
258
|
+
path_pattern: str,
|
|
259
|
+
*,
|
|
260
|
+
case_sensitive: Optional[bool] = None,
|
|
261
|
+
) -> bool:
|
|
250
262
|
"""Match path against glob pattern.
|
|
251
263
|
|
|
252
264
|
Override to work correctly with cloud URIs by matching against
|
|
@@ -260,13 +272,21 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
260
272
|
|
|
261
273
|
# If no key parts, can only match empty patterns
|
|
262
274
|
if not our_parts: # pragma: no cover
|
|
263
|
-
return
|
|
275
|
+
return path_pattern in ("", "*", "**")
|
|
264
276
|
|
|
265
277
|
# Create a PurePosixPath from the key parts to do matching
|
|
266
278
|
key_path = PurePosixPath(*our_parts)
|
|
267
279
|
|
|
280
|
+
# Python 3.12+ supports case_sensitive keyword argument
|
|
281
|
+
if sys.version_info >= (3, 12):
|
|
282
|
+
return key_path.match(path_pattern, case_sensitive=case_sensitive)
|
|
283
|
+
|
|
284
|
+
# Python < 3.12 fallback (only case-sensitive matching is natively supported)
|
|
285
|
+
if case_sensitive is False:
|
|
286
|
+
return PurePosixPath(str(key_path).lower()).match(path_pattern.lower())
|
|
287
|
+
|
|
268
288
|
# Use PurePosixPath's match which handles ** correctly
|
|
269
|
-
return key_path.match(
|
|
289
|
+
return key_path.match(path_pattern)
|
|
270
290
|
|
|
271
291
|
def glob(self, pattern: str) -> Iterator["CloudPath"]: # type: ignore[override]
|
|
272
292
|
"""Glob for files matching pattern.
|
|
@@ -385,10 +405,10 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
385
405
|
"""
|
|
386
406
|
target = self.client.readlink(str(self))
|
|
387
407
|
|
|
388
|
-
return PanPath(
|
|
408
|
+
return PanPath(
|
|
389
409
|
target,
|
|
390
|
-
client=self._client,
|
|
391
|
-
async_client=self._async_client,
|
|
410
|
+
client=self._client, # type: ignore
|
|
411
|
+
async_client=self._async_client, # type: ignore
|
|
392
412
|
)
|
|
393
413
|
|
|
394
414
|
def symlink_to(self, target: Union[str, "CloudPath"]) -> None: # type: ignore[override]
|
|
@@ -472,8 +492,8 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
472
492
|
|
|
473
493
|
@staticmethod
|
|
474
494
|
def _copy_cross_storage(
|
|
475
|
-
src: str,
|
|
476
|
-
dst: str,
|
|
495
|
+
src: "str | CloudPath | Path",
|
|
496
|
+
dst: "str | CloudPath | Path",
|
|
477
497
|
follow_symlinks: bool = True,
|
|
478
498
|
chunk_size: int = 1024 * 1024,
|
|
479
499
|
) -> None: # pragma: no cover
|
|
@@ -501,8 +521,8 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
501
521
|
|
|
502
522
|
@staticmethod
|
|
503
523
|
def _copytree_cross_storage(
|
|
504
|
-
src: str,
|
|
505
|
-
dst: str,
|
|
524
|
+
src: "str | CloudPath | Path",
|
|
525
|
+
dst: "str | CloudPath | Path",
|
|
506
526
|
follow_symlinks: bool = True,
|
|
507
527
|
chunk_size: int = 1024 * 1024,
|
|
508
528
|
) -> None: # pragma: no cover
|
|
@@ -769,10 +789,10 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
769
789
|
"""
|
|
770
790
|
target = await self.async_client.readlink(str(self))
|
|
771
791
|
|
|
772
|
-
return PanPath(
|
|
792
|
+
return PanPath(
|
|
773
793
|
target,
|
|
774
|
-
client=self._client,
|
|
775
|
-
async_client=self._async_client,
|
|
794
|
+
client=self._client, # type: ignore
|
|
795
|
+
async_client=self._async_client, # type: ignore
|
|
776
796
|
)
|
|
777
797
|
|
|
778
798
|
async def a_symlink_to( # type: ignore[override]
|
|
@@ -798,7 +818,7 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
798
818
|
|
|
799
819
|
Args:
|
|
800
820
|
ignore_errors: If True, errors are ignored
|
|
801
|
-
onerror:
|
|
821
|
+
onerror: Async callable that accepts (function, path, excinfo)
|
|
802
822
|
"""
|
|
803
823
|
await self.async_client.rmtree(str(self), ignore_errors=ignore_errors, onerror=onerror)
|
|
804
824
|
|
|
@@ -853,8 +873,8 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
853
873
|
|
|
854
874
|
@staticmethod
|
|
855
875
|
async def _a_copy_cross_storage(
|
|
856
|
-
src: str,
|
|
857
|
-
dst: str,
|
|
876
|
+
src: "str | CloudPath | Path",
|
|
877
|
+
dst: "str | CloudPath | Path",
|
|
858
878
|
follow_symlinks: bool = True,
|
|
859
879
|
chunk_size: int = 1024 * 1024,
|
|
860
880
|
) -> None:
|
|
@@ -883,8 +903,8 @@ class CloudPath(PanPath, PurePosixPath, ABC):
|
|
|
883
903
|
|
|
884
904
|
@staticmethod
|
|
885
905
|
async def _a_copytree_cross_storage(
|
|
886
|
-
src: str,
|
|
887
|
-
dst: str,
|
|
906
|
+
src: "str | CloudPath | Path",
|
|
907
|
+
dst: "str | CloudPath | Path",
|
|
888
908
|
follow_symlinks: bool = True,
|
|
889
909
|
chunk_size: int = 1024 * 1024,
|
|
890
910
|
) -> None:
|