11import warnings
2+ from functools import cached_property
23
34from paquo ._config import settings
45from paquo ._config import to_kwargs
@@ -43,6 +44,7 @@ class _Compatibility:
4344 def __init__ (self , version : "QuPathVersion | None" ) -> None :
4445 self .version = version
4546
47+ @cached_property
4648 def requires_missing_classes_json_fix (self ) -> bool :
4749 # older QuPaths crash on project load when classes.json is missing
4850 # see: https://github.com/qupath/qupath/commit/be861cea80b9a8ef300e30d7985fd69791c2432e
@@ -51,6 +53,7 @@ def requires_missing_classes_json_fix(self) -> bool:
5153 else :
5254 return self .version <= QuPathVersion ("0.2.0" )
5355
56+ @cached_property
5457 def requires_annotation_json_fix (self ) -> bool :
5558 # annotations changed between QuPath "0.2.3" and "0.3.x"
5659 # see: https://github.com/qupath/qupath/commit/fef5c43ce3f67e0e062677c407b395ef3e6e27c3
@@ -59,6 +62,15 @@ def requires_annotation_json_fix(self) -> bool:
5962 else :
6063 return self .version <= QuPathVersion ("0.2.3" )
6164
65+ @cached_property
66+ def requires_objecttype_json_fix (self ) -> bool :
67+ # annotations changed between QuPath "0.3.0" and "0.4.x"
68+ if self .version is None :
69+ return False
70+ else :
71+ return QuPathVersion ("0.3.0" ) <= self .version < QuPathVersion ("0.4.0" )
72+
73+ @cached_property
6274 def supports_image_server_recovery (self ) -> bool :
6375 # image_server server.json files are only guaranteed to be written since QuPath "0.2.0"
6476 # see: https://github.com/qupath/qupath/commit/39abee3012da9252ea988308848c5d802164e060
@@ -67,6 +79,7 @@ def supports_image_server_recovery(self) -> bool:
6779 else :
6880 return self .version >= QuPathVersion ("0.2.0" )
6981
82+ @cached_property
7083 def supports_logmanager (self ) -> bool :
7184 # the logmanager class was only added with 0.2.0-m10
7285 # see: https://github.com/qupath/qupath/commit/15b844703b686f7a9a64c50194ebe22fc46924a5
@@ -75,6 +88,7 @@ def supports_logmanager(self) -> bool:
7588 else :
7689 return self .version >= QuPathVersion ("0.2.0-m10" )
7790
91+ @cached_property
7892 def supports_newer_addobject_and_pathclass (self ) -> bool :
7993 # PathObjectHierarchy.addPathObject and .addPathObjectWithoutUpdate are deprecated
8094 # PathClassFactory is deprecated too
@@ -84,6 +98,30 @@ def supports_newer_addobject_and_pathclass(self) -> bool:
8498 else :
8599 return self .version >= QuPathVersion ("0.4.0" )
86100
101+ @cached_property
102+ def supports_addobjects (self ) -> bool :
103+ # PathObjectHierarchy.addPathObjects was removed
104+ if self .version is None :
105+ return False
106+ else :
107+ return self .version >= QuPathVersion ("0.6.0" )
108+
109+ @cached_property
110+ def supports_get_uris (self ) -> bool :
111+ # .getServerURIs was removed
112+ if self .version is None :
113+ return False
114+ else :
115+ return self .version >= QuPathVersion ("0.6.0" )
116+
117+ @cached_property
118+ def supports_newer_measurements_interface (self ) -> bool :
119+ # .putMeasurement is gone?
120+ if self .version is None :
121+ return False
122+ else :
123+ return self .version >= QuPathVersion ("0.6.0" )
124+
87125
88126compatibility = _Compatibility (qupath_version )
89127
@@ -112,15 +150,15 @@ def supports_newer_addobject_and_pathclass(self) -> bool:
112150ImageServers = JClass ('qupath.lib.images.servers.ImageServers' ) # NOTE: this is needed to make QuPath v0.3.0-rc1 work
113151ImageServerProvider = JClass ('qupath.lib.images.servers.ImageServerProvider' )
114152
115- if compatibility .supports_logmanager () :
153+ if compatibility .supports_logmanager :
116154 LogManager = JClass ('qupath.lib.gui.logging.LogManager' )
117155else :
118156 LogManager = None
119157
120158PathAnnotationObject = JClass ("qupath.lib.objects.PathAnnotationObject" )
121159PathClass = JClass ('qupath.lib.objects.classes.PathClass' )
122160
123- if not compatibility .supports_newer_addobject_and_pathclass () :
161+ if not compatibility .supports_newer_addobject_and_pathclass :
124162 PathClassFactory = JClass ('qupath.lib.objects.classes.PathClassFactory' )
125163else :
126164 PathClassFactory = None
@@ -157,6 +195,7 @@ def supports_newer_addobject_and_pathclass(self) -> bool:
157195IllegalArgumentException = JClass ('java.lang.IllegalArgumentException' )
158196FileNotFoundException = JClass ('java.io.FileNotFoundException' )
159197NoSuchFileException = JClass ('java.nio.file.NoSuchFileException' )
198+ RuntimeException = JClass ('java.lang.RuntimeException' )
160199
161200
162201def __getattr__ (name ):
0 commit comments