Skip to content

Commit 0b4b7c5

Browse files
committed
Allow marking 'supported_since' on class level
Add a '_SUPPORTED_SINCE' class attribute to the 'GrpcObjectBase' class, which has two effects: - upon storing an object, check the server version and raise an appropriate exception if the server version is too low - in the 'mark_grpc_properties' class decorator, add a line at the end of the class docstring indicating the server version at which the class was introduced
1 parent e8862c9 commit 0b4b7c5

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/ansys/acp/core/_tree_objects/_grpc_helpers/property_helper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def mark_grpc_properties(cls: T) -> T:
9191
if name not in props_unique:
9292
props_unique.append(name)
9393
cls._GRPC_PROPERTIES = tuple(props_unique)
94+
if cls._SUPPORTED_SINCE is not None:
95+
if isinstance(cls.__doc__, str):
96+
cls.__doc__ += f"\n\nSupported since ACP gRPC server version {cls._SUPPORTED_SINCE}."
9497
return cls
9598

9699

src/ansys/acp/core/_tree_objects/_grpc_helpers/protocols.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class GrpcObjectBase(Protocol):
151151

152152
__slots__: Iterable[str] = tuple()
153153
_GRPC_PROPERTIES: tuple[str, ...] = tuple()
154+
_SUPPORTED_SINCE: str | None = None
154155

155156
def __str__(self) -> str:
156157
string_items = []

src/ansys/acp/core/_tree_objects/_grpc_helpers/supported_since.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def supported_since(
4545
4646
Parameters
4747
----------
48-
version : Optional[str]
48+
version :
4949
The server version since which the method is supported. If ``None``, the
5050
decorator does nothing.
51-
err_msg_tpl : Optional[str]
51+
err_msg_tpl :
5252
A custom error message template. If ``None``, a default error message is used.
5353
"""
5454
if version is None:
@@ -69,7 +69,7 @@ def inner(self: T, /, *args: P.args, **kwargs: P.kwargs) -> R:
6969
if server_version < required_version:
7070
if err_msg_tpl is None:
7171
err_msg = (
72-
f"The method '{func.__name__}' is only supported since version {version} "
72+
f"The '{func.__name__}' method is only supported since version {version} "
7373
f"of the ACP gRPC server. The current server version is {server_version}."
7474
)
7575
else:

src/ansys/acp/core/_tree_objects/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ def store(self: Self, parent: TreeObject) -> None:
328328
Parent object to store the object under.
329329
"""
330330
self._server_wrapper_store = parent._server_wrapper
331+
if self._SUPPORTED_SINCE is not None:
332+
assert self._server_version is not None
333+
if self._server_version < parse_version(self._SUPPORTED_SINCE):
334+
raise RuntimeError(
335+
f"The '{type(self).__name__}' object is only supported since version "
336+
f"{self._SUPPORTED_SINCE} of the ACP gRPC server. The current server version is "
337+
f"{self._server_version}."
338+
)
331339

332340
collection_path = CollectionPath(
333341
value=_rp_join(parent._resource_path.value, self._COLLECTION_LABEL)

0 commit comments

Comments
 (0)