panpath 0.4.7__tar.gz → 0.4.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: panpath
3
- Version: 0.4.7
3
+ Version: 0.4.9
4
4
  Summary: Universal sync/async local/cloud path library with pathlib-compatible interface
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -56,7 +56,7 @@ except ImportError:
56
56
  # Azure dependencies not installed
57
57
  pass
58
58
 
59
- __version__ = "0.4.7"
59
+ __version__ = "0.4.9"
60
60
 
61
61
  __all__ = [
62
62
  "PanPath",
@@ -526,7 +526,7 @@ class AsyncAzureBlobClient(AsyncClient):
526
526
 
527
527
  # Yield each directory tuple
528
528
  for d, (subdirs, files) in sorted(dirs.items()):
529
- yield (d, sorted(subdirs), sorted(files))
529
+ yield (d, sorted(subdirs), sorted(filter(None, files)))
530
530
 
531
531
  async def touch( # type: ignore[no-untyped-def, override]
532
532
  self,
@@ -394,7 +394,7 @@ class AzureBlobClient(SyncClient):
394
394
 
395
395
  # Yield each directory tuple
396
396
  for d, (subdirs, files) in sorted(dirs.items()):
397
- yield (d, sorted(subdirs), sorted(files))
397
+ yield (d, sorted(subdirs), sorted(filter(None, files)))
398
398
 
399
399
  def touch( # type: ignore[no-untyped-def, override]
400
400
  self,
@@ -398,3 +398,11 @@ class PanPath(PathlibPath):
398
398
  Returns:
399
399
  An async file handle.
400
400
  """
401
+
402
+ # backports
403
+ def walk(self) -> Any:
404
+ """Walk the directory tree.
405
+
406
+ Yields:
407
+ Tuples of (current_path, dirnames, filenames) at each level.
408
+ """
@@ -192,7 +192,7 @@ class SyncClient(Client, ABC):
192
192
  raise ValueError(f"Invalid metadata format for: {path}")
193
193
  target: Any = meta_dict.get(self.__class__.symlink_target_metaname, None)
194
194
  if not target or not isinstance(target, str):
195
- raise ValueError(f"Not a symlink: {path}")
195
+ raise ValueError(f"Not a symlink: {path!r}")
196
196
 
197
197
  if any(target.startswith(f"{prefix}://") for prefix in self.__class__.prefix):
198
198
  return str(target)
@@ -322,9 +322,12 @@ class CloudPath(PanPath, PurePosixPath, ABC):
322
322
  target_str = str(target)
323
323
  # Check if cross-storage operation (cloud <-> local or cloud <-> cloud)
324
324
  if self._is_cross_storage_op(str(self), target_str): # pragma: no cover
325
- # Copy then delete for cross-storage
326
- self._copy_cross_storage(str(self), target_str)
327
- self.unlink()
325
+ if self.is_dir():
326
+ self._copytree_cross_storage(str(self), target_str)
327
+ self.rmtree()
328
+ else:
329
+ self._copy_cross_storage(str(self), target_str)
330
+ self.unlink()
328
331
  else:
329
332
  # Same storage, use native rename
330
333
  self.client.rename(str(self), target_str)
@@ -469,27 +472,48 @@ class CloudPath(PanPath, PurePosixPath, ABC):
469
472
 
470
473
  @staticmethod
471
474
  def _copy_cross_storage(
472
- src: str, dst: str, follow_symlinks: bool = True
475
+ src: str,
476
+ dst: str,
477
+ follow_symlinks: bool = True,
478
+ chunk_size: int = 1024 * 1024,
473
479
  ) -> None: # pragma: no cover
474
- """Copy file across storage boundaries."""
480
+ """Copy file across storage boundaries.
481
+
482
+ Args:
483
+ src: Source path
484
+ dst: Destination path
485
+ follow_symlinks: If False, copy symlink as symlink
486
+ chunk_size: Size of chunks to read/write (for large files)
487
+ """
475
488
  src_path = PanPath(src)
476
489
  dst_path = PanPath(dst)
477
490
 
478
- # Handle symlinks
479
- if not follow_symlinks and src_path.is_symlink():
480
- # Copy as symlink
481
- target = src_path.readlink()
482
- dst_path.symlink_to(str(target))
483
- else:
484
- # Read from source and write to destination
485
- data = src_path.read_bytes()
486
- dst_path.write_bytes(data)
491
+ if follow_symlinks and src_path.is_symlink():
492
+ # If following symlinks, read the target and copy that instead
493
+ src_path = src_path.readlink()
494
+
495
+ with src_path.open("rb") as src_file, dst_path.open("wb") as dst_file:
496
+ while True:
497
+ chunk = src_file.read(chunk_size)
498
+ if not chunk:
499
+ break
500
+ dst_file.write(chunk)
487
501
 
488
502
  @staticmethod
489
503
  def _copytree_cross_storage(
490
- src: str, dst: str, follow_symlinks: bool = True
504
+ src: str,
505
+ dst: str,
506
+ follow_symlinks: bool = True,
507
+ chunk_size: int = 1024 * 1024,
491
508
  ) -> None: # pragma: no cover
492
- """Copy directory tree across storage boundaries."""
509
+ """Copy directory tree across storage boundaries.
510
+
511
+ Args:
512
+ src: Source directory path
513
+ dst: Destination directory path
514
+ follow_symlinks: If False, copy symlinks as symlinks
515
+ chunk_size: Size of chunks to read/write (for large files)
516
+ """
493
517
  src_path = PanPath(src)
494
518
  dst_path = PanPath(dst)
495
519
 
@@ -497,9 +521,9 @@ class CloudPath(PanPath, PurePosixPath, ABC):
497
521
  dst_path.mkdir(parents=True, exist_ok=True)
498
522
 
499
523
  # Walk source tree and copy all files
500
- for dirpath, dirnames, filenames in src_path.walk(): # type: ignore[attr-defined]
524
+ for dirpath, dirnames, filenames in src_path.walk():
501
525
  # Calculate relative path from src
502
- rel_dir = dirpath[len(str(src)) :].lstrip("/")
526
+ rel_dir = str(dirpath)[len(str(src)) :].lstrip("/")
503
527
 
504
528
  # Create subdirectories in destination
505
529
  for dirname in dirnames:
@@ -508,16 +532,14 @@ class CloudPath(PanPath, PurePosixPath, ABC):
508
532
 
509
533
  # Copy files
510
534
  for filename in filenames:
511
- src_file = PanPath(dirpath) / filename
535
+ src_file = dirpath / filename
512
536
  dst_file = dst_path / rel_dir / filename if rel_dir else dst_path / filename
513
- # Handle symlinks
514
- if not follow_symlinks and src_file.is_symlink():
515
- # Copy as symlink
516
- target = src_file.readlink()
517
- dst_file.symlink_to(str(target))
518
- else:
519
- data = src_file.read_bytes()
520
- dst_file.write_bytes(data)
537
+ CloudPath._copy_cross_storage(
538
+ str(src_file),
539
+ str(dst_file),
540
+ follow_symlinks=follow_symlinks,
541
+ chunk_size=chunk_size,
542
+ )
521
543
 
522
544
  # Async methods (prefixed with a_)
523
545
  async def a_exists(self) -> bool:
@@ -831,27 +853,49 @@ class CloudPath(PanPath, PurePosixPath, ABC):
831
853
 
832
854
  @staticmethod
833
855
  async def _a_copy_cross_storage(
834
- src: str, dst: str, follow_symlinks: bool = True
835
- ) -> None: # pragma: no cover
836
- """Copy file across storage boundaries (async)."""
856
+ src: str,
857
+ dst: str,
858
+ follow_symlinks: bool = True,
859
+ chunk_size: int = 1024 * 1024,
860
+ ) -> None:
861
+ """Copy file across storage boundaries (async).
862
+
863
+ Args:
864
+ src: Source path
865
+ dst: Destination path
866
+ follow_symlinks: If False, copy symlinks as symlinks
867
+ chunk_size: Size of chunks to read/write (default 1MB)
868
+ """
837
869
  src_path = PanPath(src)
838
870
  dst_path = PanPath(dst)
839
871
 
840
- # Handle symlinks
841
- if not follow_symlinks and await src_path.a_is_symlink():
842
- # Copy as symlink
843
- target = await src_path.a_readlink()
844
- await dst_path.a_symlink_to(str(target))
845
- else:
846
- # Read from source and write to destination
847
- data = await src_path.a_read_bytes()
848
- await dst_path.a_write_bytes(data)
872
+ if follow_symlinks and await src_path.a_is_symlink(): # pragma: no cover
873
+ # If following symlinks, read the target and copy that instead
874
+ src_path = await src_path.a_readlink()
875
+
876
+ async with src_path.a_open("rb") as fsrc:
877
+ async with dst_path.a_open("wb") as fdst:
878
+ while True:
879
+ buf = await fsrc.read(chunk_size) # Read in 1MB chunks
880
+ if not buf:
881
+ break
882
+ await fdst.write(buf)
849
883
 
850
884
  @staticmethod
851
885
  async def _a_copytree_cross_storage(
852
- src: str, dst: str, follow_symlinks: bool = True
853
- ) -> None: # pragma: no cover
854
- """Copy directory tree across storage boundaries (async)."""
886
+ src: str,
887
+ dst: str,
888
+ follow_symlinks: bool = True,
889
+ chunk_size: int = 1024 * 1024,
890
+ ) -> None:
891
+ """Copy directory tree across storage boundaries (async).
892
+
893
+ Args:
894
+ src: Source path
895
+ dst: Destination path
896
+ follow_symlinks: If False, symlinks are copied as symlinks (not dereferenced)
897
+ chunk_size: Size of chunks to read/write (default 1MB)
898
+ """
855
899
  src_path = PanPath(src)
856
900
  dst_path = PanPath(dst)
857
901
 
@@ -872,14 +916,12 @@ class CloudPath(PanPath, PurePosixPath, ABC):
872
916
  for filename in filenames:
873
917
  src_file = dirpath / filename
874
918
  dst_file = dst_path / rel_dir / filename if rel_dir else dst_path / filename
875
- # Handle symlinks
876
- if not follow_symlinks and await src_file.a_is_symlink():
877
- # Copy as symlink
878
- target = await src_file.a_readlink()
879
- await dst_file.a_symlink_to(str(target))
880
- else:
881
- data = await src_file.a_read_bytes()
882
- await dst_file.a_write_bytes(data)
919
+ await CloudPath._a_copy_cross_storage(
920
+ str(src_file),
921
+ str(dst_file),
922
+ follow_symlinks=follow_symlinks,
923
+ chunk_size=chunk_size,
924
+ )
883
925
 
884
926
  def a_open(
885
927
  self,
@@ -424,10 +424,17 @@ class AsyncGSClient(AsyncClient):
424
424
  metadata = await self.get_metadata(path)
425
425
  target = metadata.get("metadata", {}).get( # type: ignore[union-attr, call-overload]
426
426
  self.__class__.symlink_target_metaname,
427
+ None,
427
428
  )
428
429
  if not target:
429
- raise ValueError(f"Not a symlink: {path}")
430
- return target # type: ignore[no-any-return]
430
+ raise ValueError(f"Not a symlink: {path!r}")
431
+
432
+ if any(target.startswith(f"{prefix}://") for prefix in self.__class__.prefix):
433
+ return target # type: ignore[no-any-return]
434
+
435
+ # relative path - construct full path
436
+ path = path.rstrip("/").rsplit("/", 1)[0]
437
+ return f"{path}/{target}"
431
438
 
432
439
  async def symlink_to(self, path: str, target: str) -> None:
433
440
  """Create symlink by storing target in metadata.
@@ -571,7 +578,7 @@ class AsyncGSClient(AsyncClient):
571
578
 
572
579
  # Yield each directory tuple
573
580
  for d, (subdirs, files) in sorted(dirs.items()):
574
- yield (d, sorted(subdirs), sorted(files))
581
+ yield (d, sorted(subdirs), sorted(filter(None, files)))
575
582
 
576
583
  async def touch( # type: ignore[no-untyped-def, override]
577
584
  self,
@@ -302,9 +302,9 @@ class GSClient(SyncClient):
302
302
  Symlink target path
303
303
  """
304
304
  metadata = self.get_metadata(path)
305
- target = metadata.get(self.__class__.symlink_target_metaname)
305
+ target = metadata.get(self.__class__.symlink_target_metaname, None)
306
306
  if not target:
307
- raise ValueError(f"Not a symlink: {path}")
307
+ raise ValueError(f"Not a symlink: {path!r}")
308
308
 
309
309
  if any(target.startswith(f"{prefix}://") for prefix in self.__class__.prefix):
310
310
  return target
@@ -406,6 +406,13 @@ class GSClient(SyncClient):
406
406
  if i < len(parts) - 2: # pragma: no cover
407
407
  dirs[dir_path][0].add(parts[i + 1])
408
408
 
409
+ sub_parent = (
410
+ f"{path}/" + "/".join(parts[: i]) if path else "/".join(parts[: i])
411
+ ).rstrip("/")
412
+ if sub_parent not in dirs: # pragma: no cover
413
+ dirs[sub_parent] = (set(), set())
414
+ dirs[sub_parent][0].add(parts[i])
415
+
409
416
  # Add file to its parent directory
410
417
  parent_dir = f"{path}/" + "/".join(parts[:-1]) if path else "/".join(parts[:-1])
411
418
  if parent_dir not in dirs: # pragma: no cover
@@ -413,7 +420,7 @@ class GSClient(SyncClient):
413
420
  dirs[parent_dir][1].add(parts[-1])
414
421
 
415
422
  for d, (subdirs, files) in dirs.items():
416
- yield d, sorted(subdirs), sorted(files)
423
+ yield d, sorted(subdirs), sorted(filter(None, files))
417
424
 
418
425
  def touch(self, path: str, exist_ok: bool = True) -> None:
419
426
  """Create empty file.
@@ -588,7 +595,7 @@ class GSSyncFileHandle(SyncFileHandle):
588
595
  super().__init__(*args, **kwargs)
589
596
  self._blob: storage.Blob = self._client.bucket(self._bucket).blob(self._blob)
590
597
  if self._is_read and not self._blob.exists():
591
- raise FileNotFoundError(f"GCS blob not found: {self._bucket}/{self._blob}")
598
+ raise FileNotFoundError(f"GCS blob not found: {self._bucket}/{self._blob.name}")
592
599
 
593
600
  @classmethod
594
601
  def _expception_as_filenotfound(cls, exception: Exception) -> bool: # pragma: no cover
@@ -1,9 +1,10 @@
1
1
  """Local filesystem path implementation."""
2
2
 
3
- from pathlib import Path, PosixPath, WindowsPath
4
3
  import os
4
+ import shutil
5
5
  import sys
6
- from typing import Any, AsyncGenerator, List, Optional, Tuple, Union
6
+ from pathlib import Path, PosixPath, WindowsPath
7
+ from typing import Any, AsyncGenerator, Iterator, List, Optional, Tuple, Union
7
8
  from panpath.base import PanPath
8
9
  from panpath.cloud import CloudPath
9
10
  from panpath.exceptions import MissingDependencyError
@@ -70,15 +71,22 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
70
71
  Returns:
71
72
  New path instance
72
73
  """
73
- if not HAS_AIOFILES:
74
- raise MissingDependencyError(
75
- backend="async local paths",
76
- package="aiofiles",
77
- extra="all-async",
78
- )
79
-
80
74
  target_str = str(target)
81
- await aiofiles.os.rename(str(self), target_str)
75
+ if CloudPath._is_cross_storage_op(str(self), target_str):
76
+ if await self.a_is_dir():
77
+ await CloudPath._a_copytree_cross_storage(str(self), target_str)
78
+ await self.a_rmtree()
79
+ else:
80
+ await CloudPath._a_copy_cross_storage(self, target_str)
81
+ await self.a_unlink()
82
+ else:
83
+ if not HAS_AIOFILES:
84
+ raise MissingDependencyError(
85
+ backend="async local paths",
86
+ package="aiofiles",
87
+ extra="all-async",
88
+ )
89
+ await aiofiles.os.rename(str(self), target_str)
82
90
  return PanPath(target_str)
83
91
 
84
92
  async def a_replace(self, target: Union[str, "Path"]) -> "PanPath":
@@ -111,18 +119,18 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
111
119
  Returns:
112
120
  Target path instance
113
121
  """
114
- if not HAS_AIOFILES:
115
- raise MissingDependencyError(
116
- backend="async local paths",
117
- package="aiofiles",
118
- extra="all-async",
119
- )
120
122
 
121
123
  target_str = str(target)
122
124
  # Check if cross-storage operation
123
- if CloudPath._is_cross_storage_op(str(self), target_str): # pragma: no cover
125
+ if CloudPath._is_cross_storage_op(str(self), target_str):
124
126
  await CloudPath._a_copy_cross_storage(self, target_str, follow_symlinks=follow_symlinks)
125
127
  else:
128
+ if not HAS_AIOFILES:
129
+ raise MissingDependencyError(
130
+ backend="async local paths",
131
+ package="aiofiles",
132
+ extra="all-async",
133
+ )
126
134
  async with aiofiles.open(str(self), mode="rb") as sf:
127
135
  async with aiofiles.open(target_str, mode="wb") as df:
128
136
  while True:
@@ -147,26 +155,28 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
147
155
  Returns:
148
156
  The copied PanPath instance.
149
157
  """
150
- if not HAS_AIOFILES:
151
- raise MissingDependencyError(
152
- backend="async local paths",
153
- package="aiofiles",
154
- extra="all-async",
155
- )
158
+ target_str = str(target)
156
159
 
157
- target = PanPath(target)
158
- await target.a_mkdir(parents=True, exist_ok=True)
160
+ if CloudPath._is_cross_storage_op(str(self), target_str):
161
+ await CloudPath._a_copytree_cross_storage(
162
+ self,
163
+ target_str,
164
+ follow_symlinks=follow_symlinks,
165
+ )
166
+ else:
167
+ target = PanPath(target)
168
+ await target.a_mkdir(parents=True, exist_ok=True)
159
169
 
160
- async for entry in self.a_iterdir():
161
- src_path = entry
162
- dest_path = target / entry.name
170
+ async for entry in self.a_iterdir():
171
+ src_path = entry
172
+ dest_path = target / entry.name
163
173
 
164
- if await src_path.a_is_dir():
165
- await src_path.a_copytree(dest_path, follow_symlinks=follow_symlinks)
166
- else:
167
- await src_path.a_copy(dest_path, follow_symlinks=follow_symlinks)
174
+ if await src_path.a_is_dir():
175
+ await src_path.a_copytree(dest_path, follow_symlinks=follow_symlinks)
176
+ else:
177
+ await src_path.a_copy(dest_path, follow_symlinks=follow_symlinks)
168
178
 
169
- return target
179
+ return PanPath(target)
170
180
 
171
181
  async def a_walk( # type: ignore[override]
172
182
  self,
@@ -207,9 +217,7 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
207
217
  extra="all-async",
208
218
  )
209
219
 
210
- return PanPath( # type: ignore[return-value]
211
- await aiofiles.os.readlink(str(self))
212
- )
220
+ return PanPath(await aiofiles.os.readlink(str(self))) # type: ignore[return-value]
213
221
 
214
222
  async def a_symlink_to(
215
223
  self,
@@ -512,3 +520,112 @@ class LocalPath(_ConcretePath, PanPath): # type: ignore[valid-type, misc]
512
520
  errors=errors,
513
521
  newline=newline,
514
522
  )
523
+
524
+ def rename(self, target: Union[str, "Path"]) -> "PanPath": # type: ignore[override]
525
+ """Rename the file or directory to target.
526
+
527
+ Args:
528
+ target: New path
529
+
530
+ Returns:
531
+ New path instance
532
+ """
533
+ target_str = str(target)
534
+ if CloudPath._is_cross_storage_op(str(self), target_str):
535
+ if self.is_dir():
536
+ CloudPath._copytree_cross_storage(self, target_str)
537
+ self.rmtree()
538
+ else:
539
+ CloudPath._copy_cross_storage(self, target_str)
540
+ self.unlink()
541
+ else:
542
+ os.rename(str(self), target_str)
543
+
544
+ return PanPath(target_str)
545
+
546
+ def copy(self, target: Union[str, "Path"], follow_symlinks: bool = True) -> "PanPath":
547
+ """Copy file to target.
548
+
549
+ Can copy between cloud and local paths.
550
+
551
+ Args:
552
+ target: Destination path (can be cloud or local)
553
+ follow_symlinks: If True, follow symbolic links
554
+
555
+ Returns:
556
+ Target path instance
557
+ """
558
+ target_str = str(target)
559
+ if CloudPath._is_cross_storage_op(str(self), target_str):
560
+ CloudPath._copy_cross_storage(self, target_str, follow_symlinks=follow_symlinks)
561
+ else:
562
+ shutil.copy2(str(self), target_str, follow_symlinks=follow_symlinks)
563
+
564
+ return PanPath(target)
565
+
566
+ def copytree(
567
+ self,
568
+ target: Union[str, "Path"],
569
+ follow_symlinks: bool = True,
570
+ ) -> "PanPath":
571
+ """Recursively copy the directory and all its contents to the target path.
572
+
573
+ Args:
574
+ target: Destination PanPath to copy to.
575
+ follow_symlinks: If True, copies the contents of symlinks.
576
+
577
+ Returns:
578
+ The copied PanPath instance.
579
+ """
580
+ target_str = str(target)
581
+ if CloudPath._is_cross_storage_op(str(self), target_str):
582
+ CloudPath._copytree_cross_storage(self, target_str, follow_symlinks=follow_symlinks)
583
+ else:
584
+ target = PanPath(target)
585
+
586
+ target.mkdir(parents=True, exist_ok=True)
587
+
588
+ for entry in self.iterdir():
589
+ src_path = entry
590
+ dest_path = target / entry.name
591
+
592
+ if src_path.is_dir():
593
+ src_path.copytree(dest_path, follow_symlinks=follow_symlinks)
594
+ else:
595
+ src_path.copy(dest_path, follow_symlinks=follow_symlinks)
596
+
597
+ return PanPath(target)
598
+
599
+ def rmdir(self) -> None:
600
+ """Remove empty directory."""
601
+ os.rmdir(str(self))
602
+
603
+ def rmtree(self) -> None:
604
+ """Recursively remove directory and its contents."""
605
+ shutil.rmtree(str(self))
606
+
607
+ # backports, walk is introduced in Python 3.12
608
+ def walk( # type: ignore[no-untyped-def]
609
+ self,
610
+ *args,
611
+ **kwargs,
612
+ ) -> Iterator[Tuple["LocalPath", List[str], List[str]]]:
613
+ """Walk the directory tree.
614
+
615
+ Returns:
616
+ A list of tuples (dirpath, dirnames, filenames)
617
+ """
618
+ if sys.version_info >= (3, 12):
619
+ yield from Path.walk(self, *args, **kwargs) # type: ignore[no-untyped-call]
620
+
621
+ if args or kwargs: # pragma: no cover
622
+ raise NotImplementedError(
623
+ "walk() does not accept arguments in this backport."
624
+ )
625
+ else: # pragma: no cover
626
+ for dirpath, dirnames, filenames in os.walk(str(self)):
627
+ yield ( # type: ignore[misc]
628
+ PanPath(dirpath),
629
+ dirnames,
630
+ filenames,
631
+ )
@@ -427,8 +427,14 @@ class AsyncS3Client(AsyncClient):
427
427
  metadata = await self.get_metadata(path)
428
428
  target = metadata.get("Metadata", {}).get(self.__class__.symlink_target_metaname)
429
429
  if not target:
430
- raise ValueError(f"Not a symlink: {path}")
431
- return target # type: ignore[no-any-return]
430
+ raise ValueError(f"Not a symlink: {path!r}")
431
+
432
+ if any(target.startswith(f"{p}://") for p in self.prefix):
433
+ return target # type: ignore[no-any-return]
434
+
435
+ # relative path - construct full path
436
+ path = path.rstrip("/").rsplit("/", 1)[0]
437
+ return f"{path}/{target}"
432
438
 
433
439
  async def symlink_to(self, path: str, target: str) -> None:
434
440
  """Create symlink by storing target in metadata.
@@ -568,7 +574,7 @@ class AsyncS3Client(AsyncClient):
568
574
 
569
575
  # Yield tuples
570
576
  for d, (subdirs, files) in sorted(dirs.items()):
571
- yield (d, sorted(subdirs), sorted(files))
577
+ yield (d, sorted(subdirs), sorted(filter(None, files)))
572
578
 
573
579
  async def touch(self, path: str, exist_ok: bool = True, mode: Optional[int] = None) -> None:
574
580
  """Create empty file.
@@ -315,8 +315,14 @@ class S3Client(SyncClient):
315
315
  self.__class__.symlink_target_metaname
316
316
  )
317
317
  if not target:
318
- raise ValueError(f"Not a symlink: {path}")
319
- return target # type: ignore[no-any-return]
318
+ raise ValueError(f"Not a symlink: {path!r}")
319
+
320
+ if any(target.startswith(f"{p}://") for p in self.prefix):
321
+ return target # type: ignore[no-any-return]
322
+
323
+ # relative path - construct full path
324
+ path = path.rstrip("/").rsplit("/", 1)[0]
325
+ return f"{path}/{target}"
320
326
 
321
327
  def symlink_to(self, path: str, target: str) -> None:
322
328
  """Create symlink by storing target in metadata.
@@ -447,7 +453,7 @@ class S3Client(SyncClient):
447
453
  dirs[parent_dir][1].add(parts[-1])
448
454
 
449
455
  for d, (subdirs, files) in dirs.items():
450
- yield d, sorted(subdirs), sorted(files)
456
+ yield d, sorted(subdirs), sorted(filter(None, files))
451
457
 
452
458
  def touch(self, path: str, exist_ok: bool = True) -> None:
453
459
  """Create empty file.
@@ -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"
7
+ version = "0.4.9"
8
8
  description = "Universal sync/async local/cloud path library with pathlib-compatible interface"
9
9
  authors = ["panpath contributors"]
10
10
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes