Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2368.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Properly handling v0 and v1 initialization
43 changes: 29 additions & 14 deletions src/ansys/geometry/core/_grpc/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@

from enum import Enum, unique

from google.protobuf.empty_pb2 import Empty
import grpc

# ATTEMPT v0 IMPORT
try:
import ansys.api.dbu.v0.admin_pb2_grpc as dbu_v0_admin_pb2_grpc
from ansys.api.dbu.v0.admin_pb2_grpc import AdminStub as V0HealthStub
from google.protobuf.empty_pb2 import Empty as V0HealthRequest
except ImportError:
dbu_v0_admin_pb2_grpc = None
V0HealthStub = None
V0HealthRequest = None


# ATTEMPT v1 IMPORT
try:
import ansys.api.dbu.v1.admin_pb2_grpc as dbu_v1_admin_pb2_grpc
from ansys.api.discovery.v1.commands.communication_pb2 import HealthRequest as V1HealthRequest
from ansys.api.discovery.v1.commands.communication_pb2_grpc import (
CommunicationStub as V1HealthStub,
)
except ImportError:
dbu_v1_admin_pb2_grpc = None
V1HealthStub = None
V1HealthRequest = None


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

V0 = 0, dbu_v0_admin_pb2_grpc
V1 = 1, dbu_v1_admin_pb2_grpc
V0 = 0, V0HealthStub, V0HealthRequest
V1 = 1, V1HealthStub, V1HealthRequest

@staticmethod
def get_latest_version() -> "GeometryApiProtos":
Expand Down Expand Up @@ -85,13 +91,14 @@ def verify_supported(self, channel: grpc.Channel) -> bool:
-----
This method checks if the server supports the gRPC API protocol version.
"""
pb2_grpc = self.value[1]
if pb2_grpc is None:
StubClass = self.value[1] # noqa: N806
RequestClass = self.value[2] # noqa: N806
if StubClass is None:
return False

try:
admin_stub = pb2_grpc.AdminStub(channel)
admin_stub.Health(Empty())
admin_stub = StubClass(channel)
admin_stub.Health(RequestClass())
return True
except grpc.RpcError:
return False
Expand Down Expand Up @@ -126,9 +133,17 @@ def set_proto_version(
# If no version specified... Attempt to use all of them, starting
# with the latest version
if version is None:
version = GeometryApiProtos.get_latest_version()
while not version.verify_supported(channel):
version = GeometryApiProtos.from_int_value(version.value[0] - 1)
# TODO: Once blitz is over, we will enable this...
# https://github.com/ansys/pyansys-geometry/issues/2366
#
# ---> REPLACE THIS BLOCK <---
# version = GeometryApiProtos.get_latest_version()
# while not version.verify_supported(channel):
# version = GeometryApiProtos.from_int_value(version.value[0] - 1)
# ---> REPLACE THIS BLOCK <---
# ---> DELETE THIS BLOCK <---
version = GeometryApiProtos.V0
# ---> DELETE THIS BLOCK <---

# Return the version
return version
5 changes: 3 additions & 2 deletions src/ansys/geometry/core/connection/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ class GrpcClient:
Logging level to apply to the client.
logging_file : str or Path, default: None
File to output the log to, if requested.
proto_version: str or None, default: None
Version of the gRPC protocol to use. If ``None``, the latest version is used.
proto_version : str | None, default: None
Protocol version to use for communication with the server. If None, v0 is used.
Available versions are "v0", "v1", etc.
"""

@check_input_types
Expand Down
5 changes: 5 additions & 0 deletions src/ansys/geometry/core/modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Modeler:
Logging level to apply to the client.
logging_file : str, Path, default: None
File to output the log to, if requested.
proto_version : str | None, default: None
Protocol version to use for communication with the server. If None, v0 is used.
Available versions are "v0", "v1", etc.
"""

def __init__(
Expand All @@ -96,6 +99,7 @@ def __init__(
timeout: Real = 120,
logging_level: int = logging.INFO,
logging_file: Path | str | None = None,
proto_version: str | None = None,
):
"""Initialize the ``Modeler`` class."""
from ansys.geometry.core.designer.geometry_commands import GeometryCommands
Expand All @@ -110,6 +114,7 @@ def __init__(
timeout=timeout,
logging_level=logging_level,
logging_file=logging_file,
proto_version=proto_version,
)

# Single design for the Modeler
Expand Down
Loading