Skip to content

Commit e0c2998

Browse files
committed
deprecations and changelog
1 parent 6712b3a commit e0c2998

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1717
### Added
1818

1919
### Changed
20+
- `Layer.add_mag_as_copy` now automatically uses file-based copy, if possible. Therefore, `Dataset.fs_copy_dataset`, `Dataset.add_fs_copy_layer` and `Layer.add_fs_copy_mag` are deprecated. [#1362](https://github.com/scalableminds/webknossos-libs/pull/1362)
2021

2122
### Fixed
2223

webknossos/webknossos/dataset/dataset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,13 +2524,15 @@ def add_fs_copy_layer(
25242524
foreign_layer: str | Path | Layer,
25252525
new_layer_name: str | None = None,
25262526
) -> Layer:
2527-
"""
2527+
"""Deprecated. File-based copy is automatically used in `Dataset.add_layer_as_copy`.
2528+
25282529
Copies the files at `foreign_layer` which belongs to another dataset
25292530
to the current dataset via the filesystem. Additionally, the relevant
25302531
information from the `datasource-properties.json` of the other dataset
25312532
are copied too. If new_layer_name is None, the name of the foreign
25322533
layer is used.
25332534
"""
2535+
warn_deprecated("add_fs_copy_layer", "add_layer_as_copy")
25342536
self._ensure_writable()
25352537
foreign_layer = Layer._ensure_layer(foreign_layer)
25362538

@@ -2705,7 +2707,8 @@ def fs_copy_dataset(
27052707
exists_ok: bool = False,
27062708
layers_to_ignore: Iterable[str] | None = None,
27072709
) -> "Dataset":
2708-
"""
2710+
"""Deprecated. File-based copy is automatically used by `Dataset.copy_dataset`.
2711+
27092712
Creates an independent copy of the dataset with all layers at a new location.
27102713
27112714
This method copies the files of the dataset as is and, therefore, might be faster than Dataset.copy_dataset, which decodes and encodes all the data.
@@ -2731,6 +2734,7 @@ def fs_copy_dataset(
27312734
Note:
27322735
WKW layers can only be copied to datasets on local file systems.
27332736
"""
2737+
warn_deprecated("fs_copy_dataset", "copy_dataset")
27342738

27352739
new_dataset_path = UPath(new_dataset_path)
27362740

webknossos/webknossos/dataset/layer.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import operator
33
import re
44
import warnings
5+
from inspect import getframeinfo, stack
56
from os import PathLike
67
from os.path import relpath
78
from pathlib import Path
@@ -1076,17 +1077,13 @@ def add_mag_as_ref(
10761077

10771078
return self.get_mag(foreign_mag_view.mag)
10781079

1079-
def add_fs_copy_mag(
1080+
def _add_fs_copy_mag(
10801081
self,
10811082
foreign_mag_view_or_path: PathLike | str | MagView,
10821083
*,
10831084
extend_layer_bounding_box: bool = True,
10841085
exists_ok: bool = False,
10851086
) -> MagView:
1086-
"""
1087-
Copies the data at `foreign_mag_view_or_path` which belongs to another dataset to the current dataset via the filesystem.
1088-
Additionally, the relevant information from the `datasource-properties.json` of the other dataset are copied, too.
1089-
"""
10901087
self._ensure_writable()
10911088
foreign_mag_view = MagView._ensure_mag_view(foreign_mag_view_or_path)
10921089
self._assert_mag_does_not_exist_yet(foreign_mag_view.mag)
@@ -1113,6 +1110,30 @@ def add_fs_copy_mag(
11131110

11141111
return mag
11151112

1113+
def add_fs_copy_mag(
1114+
self,
1115+
foreign_mag_view_or_path: PathLike | str | MagView,
1116+
*,
1117+
extend_layer_bounding_box: bool = True,
1118+
exists_ok: bool = False,
1119+
) -> MagView:
1120+
"""Deprecated. File-copy is automatically selected when using `Layer.add_mag_as_copy`.
1121+
1122+
Copies the data at `foreign_mag_view_or_path` which belongs to another dataset to the current dataset via the filesystem.
1123+
Additionally, the relevant information from the `datasource-properties.json` of the other dataset are copied, too.
1124+
"""
1125+
caller = getframeinfo(stack()[2][0])
1126+
warnings.warn(
1127+
f"[DEPRECATION] Direct use of `Layer.add_fs_copy_mag` is deprecated, please use `Layer.add_mag_as_copy` instead (see {caller.filename}:{caller.lineno}), which automatically uses file-based copy if available.",
1128+
DeprecationWarning,
1129+
stacklevel=2,
1130+
)
1131+
return self._add_fs_copy_mag(
1132+
foreign_mag_view_or_path,
1133+
extend_layer_bounding_box=extend_layer_bounding_box,
1134+
exists_ok=exists_ok,
1135+
)
1136+
11161137
def add_mag_from_zarrarray(
11171138
self,
11181139
mag: MagLike,

0 commit comments

Comments
 (0)