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/2311.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return backend info on repr for client and modeler
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [
]

dependencies = [
"ansys-api-geometry==0.4.80",
"ansys-api-geometry==0.4.81",
"ansys-tools-path>=0.3,<1",
"beartype>=0.11.0,<0.22",
"geomdl>=5,<6",
Expand Down
8 changes: 8 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/v0/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,22 @@ def get_backend(self, **kwargs) -> dict: # noqa: D102
if hasattr(response, "version"):
ver = response.version
backend_version = semver.Version(ver.major_release, ver.minor_release, ver.service_pack)
api_server_build_info = f"{ver.build_number}" if ver.build_number != 0 else "N/A"
product_build_info = (
response.backend_version_info.strip() if response.backend_version_info else "N/A"
)
else: # pragma: no cover
# If the version is not available, set a default version
backend_version = semver.Version(24, 1, 0)
api_server_build_info = "N/A"
product_build_info = "N/A"

# Convert the response to a dictionary
return {
"backend": from_grpc_backend_type_to_backend_type(response.type),
"version": backend_version,
"api_server_build_info": api_server_build_info,
"product_build_info": product_build_info,
}

@protect_grpc
Expand Down
19 changes: 19 additions & 0 deletions src/ansys/geometry/core/connection/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def __init__(
# Store the backend type and version
self._backend_type = response.get("backend")
self._backend_version = response.get("version")
self._backend_api_server_build_info = response.get("api_server_build_info")
self._backend_product_build_info = response.get("product_build_info")

# Register the close method to be called at exit - irrespectively of
# the user calling it or not...
Expand Down Expand Up @@ -303,6 +305,21 @@ def healthy(self) -> bool:
except Exception: # pragma: no cover
return False

def backend_info(self, indent=0) -> str:
"""Get a string with the backend information.

Returns
-------
str
String with the backend information.
"""
return (
f"{' ' * indent}Version: {self.backend_version}\n"
f"{' ' * indent}Backend type: {self.backend_type.name}\n"
f"{' ' * indent}Backend number: {self._backend_product_build_info}\n"
f"{' ' * indent}API server number: {self._backend_api_server_build_info}"
)

def __repr__(self) -> str:
"""Represent the client as a string."""
lines = []
Expand All @@ -314,6 +331,8 @@ def __repr__(self) -> str:
lines.append(" Connection: Healthy")
else:
lines.append(" Connection: Unhealthy") # pragma: no cover
lines.append(" Backend info:")
lines.append(self.backend_info(indent=4))
return "\n".join(lines)

def close(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,21 @@ def test_client_init(client: GrpcClient):
client_repr = repr(client)
assert "Target" in client_repr
assert "Connection" in client_repr
assert "Backend info" in client_repr

assert client.channel


def test_client_backend_info(client: GrpcClient):
"""Test the retrieval of the backend information."""
backend_info = client.backend_info()
assert isinstance(backend_info, str)
assert "Version" in backend_info
assert "Backend type" in backend_info
assert "Backend number" in backend_info
assert "API server number" in backend_info


def test_client_through_channel(modeler: Modeler):
"""Test the instantiation of a client from a gRPC channel."""
target = f"{pygeom_defaults.DEFAULT_HOST}:{pygeom_defaults.DEFAULT_PORT}"
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ def test_modeler(modeler: Modeler):
# Get the modeler's string representation and check it
repr = str(modeler)
assert "Ansys Geometry Modeler (" in repr
assert "Target:" in repr
assert "Connection:" in repr
assert "Backend info:" in repr

design = modeler.create_design("MyNewDesign")
assert design is not None
Expand Down
Loading