Skip to content

Commit 1ef2779

Browse files
feat: properly handling v0 and v1 initialization (#2368)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 4ca98ce commit 1ef2779

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

doc/changelog.d/2368.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Properly handling v0 and v1 initialization

src/ansys/geometry/core/_grpc/_version.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,34 @@
2323

2424
from enum import Enum, unique
2525

26-
from google.protobuf.empty_pb2 import Empty
2726
import grpc
2827

2928
# ATTEMPT v0 IMPORT
3029
try:
31-
import ansys.api.dbu.v0.admin_pb2_grpc as dbu_v0_admin_pb2_grpc
30+
from ansys.api.dbu.v0.admin_pb2_grpc import AdminStub as V0HealthStub
31+
from google.protobuf.empty_pb2 import Empty as V0HealthRequest
3232
except ImportError:
33-
dbu_v0_admin_pb2_grpc = None
33+
V0HealthStub = None
34+
V0HealthRequest = None
35+
3436

3537
# ATTEMPT v1 IMPORT
3638
try:
37-
import ansys.api.dbu.v1.admin_pb2_grpc as dbu_v1_admin_pb2_grpc
39+
from ansys.api.discovery.v1.commands.communication_pb2 import HealthRequest as V1HealthRequest
40+
from ansys.api.discovery.v1.commands.communication_pb2_grpc import (
41+
CommunicationStub as V1HealthStub,
42+
)
3843
except ImportError:
39-
dbu_v1_admin_pb2_grpc = None
44+
V1HealthStub = None
45+
V1HealthRequest = None
4046

4147

4248
@unique
4349
class GeometryApiProtos(Enum):
4450
"""Enumeration of the supported versions of the gRPC API protocol."""
4551

46-
V0 = 0, dbu_v0_admin_pb2_grpc
47-
V1 = 1, dbu_v1_admin_pb2_grpc
52+
V0 = 0, V0HealthStub, V0HealthRequest
53+
V1 = 1, V1HealthStub, V1HealthRequest
4854

4955
@staticmethod
5056
def get_latest_version() -> "GeometryApiProtos":
@@ -85,13 +91,14 @@ def verify_supported(self, channel: grpc.Channel) -> bool:
8591
-----
8692
This method checks if the server supports the gRPC API protocol version.
8793
"""
88-
pb2_grpc = self.value[1]
89-
if pb2_grpc is None:
94+
StubClass = self.value[1] # noqa: N806
95+
RequestClass = self.value[2] # noqa: N806
96+
if StubClass is None:
9097
return False
9198

9299
try:
93-
admin_stub = pb2_grpc.AdminStub(channel)
94-
admin_stub.Health(Empty())
100+
admin_stub = StubClass(channel)
101+
admin_stub.Health(RequestClass())
95102
return True
96103
except grpc.RpcError:
97104
return False
@@ -126,9 +133,17 @@ def set_proto_version(
126133
# If no version specified... Attempt to use all of them, starting
127134
# with the latest version
128135
if version is None:
129-
version = GeometryApiProtos.get_latest_version()
130-
while not version.verify_supported(channel):
131-
version = GeometryApiProtos.from_int_value(version.value[0] - 1)
136+
# TODO: Once blitz is over, we will enable this...
137+
# https://github.com/ansys/pyansys-geometry/issues/2366
138+
#
139+
# ---> REPLACE THIS BLOCK <---
140+
# version = GeometryApiProtos.get_latest_version()
141+
# while not version.verify_supported(channel):
142+
# version = GeometryApiProtos.from_int_value(version.value[0] - 1)
143+
# ---> REPLACE THIS BLOCK <---
144+
# ---> DELETE THIS BLOCK <---
145+
version = GeometryApiProtos.V0
146+
# ---> DELETE THIS BLOCK <---
132147

133148
# Return the version
134149
return version

src/ansys/geometry/core/connection/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ class GrpcClient:
176176
Logging level to apply to the client.
177177
logging_file : str or Path, default: None
178178
File to output the log to, if requested.
179-
proto_version: str or None, default: None
180-
Version of the gRPC protocol to use. If ``None``, the latest version is used.
179+
proto_version : str | None, default: None
180+
Protocol version to use for communication with the server. If None, v0 is used.
181+
Available versions are "v0", "v1", etc.
181182
"""
182183

183184
@check_input_types

src/ansys/geometry/core/modeler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class Modeler:
8383
Logging level to apply to the client.
8484
logging_file : str, Path, default: None
8585
File to output the log to, if requested.
86+
proto_version : str | None, default: None
87+
Protocol version to use for communication with the server. If None, v0 is used.
88+
Available versions are "v0", "v1", etc.
8689
"""
8790

8891
def __init__(
@@ -96,6 +99,7 @@ def __init__(
9699
timeout: Real = 120,
97100
logging_level: int = logging.INFO,
98101
logging_file: Path | str | None = None,
102+
proto_version: str | None = None,
99103
):
100104
"""Initialize the ``Modeler`` class."""
101105
from ansys.geometry.core.designer.geometry_commands import GeometryCommands
@@ -110,6 +114,7 @@ def __init__(
110114
timeout=timeout,
111115
logging_level=logging_level,
112116
logging_file=logging_file,
117+
proto_version=proto_version,
113118
)
114119

115120
# Single design for the Modeler

0 commit comments

Comments
 (0)