Skip to content

Commit

Permalink
Updated info call from 3 back to 1 call.
Browse files Browse the repository at this point in the history
  • Loading branch information
anskhanson committed Nov 7, 2024
1 parent 6d68913 commit d015663
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 56 deletions.
63 changes: 8 additions & 55 deletions src/ansys/sherlock/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,69 +158,22 @@ def list_solder_materials(self):

# First PySherlock Release "0.7.0"
@require_version(251)
def get_sherlock_version(self) -> str:
def get_sherlock_info(self) -> str:
"""Get server Sherlock version.
Returns
-------
str
Sherlock version
Examples
--------
>>> from ansys.sherlock.core.launcher import launch_sherlock
>>> sherlock = launch_sherlock()
>>> sherlock.common.get_sherlock_version()
"""
if not self._is_connection_up():
LOG.error("Not connected to a gRPC service.")
raise RuntimeError("Not connected to a gRPC service.")

request = SherlockCommonService_pb2.SherlockInfoRequest()
response = self.stub.getSherlockInfo(request)
if response is not None:
return response.releaseVersion

# First PySherlock Release "0.7.0"
@require_version(251)
def get_sherlock_default_project_dir(self) -> str:
"""Get server Sherlock default project directory.
Returns
-------
str
Sherlock default project directory
Examples
--------
>>> from ansys.sherlock.core.launcher import launch_sherlock
>>> sherlock = launch_sherlock()
>>> sherlock.common.get_sherlock_default_project_dir()
"""
if not self._is_connection_up():
LOG.error("Not connected to a gRPC service.")
raise RuntimeError("Not connected to a gRPC service.")

request = SherlockCommonService_pb2.SherlockInfoRequest()
response = self.stub.getSherlockInfo(request)
if response is not None:
return response.defaultProjectDir

# First PySherlock Release "0.7.0"
@require_version(251)
def is_single_project_mode(self) -> bool:
"""Get flag indicating single project mode.
Returns
-------
bool
True if Sherlock single project mode is active, False otherwise
SherlockInfoResponse
Sherlock information containing
releaseVersion, defaultProjectDir and isSingleProjectMode flag
Examples
--------
>>> from ansys.sherlock.core.launcher import launch_sherlock
>>> sherlock = launch_sherlock()
>>> sherlock.common.get_sherlock_default_project_dir()
>>> release_version = sherlock.common.get_sherlock_info().releaseVersion
>>> default_dir = sherlock.common.get_sherlock_info().defaultProjectDir
>>> is_single_project = sherlock.common.get_sherlock_info().isSingleProjectMode
"""
if not self._is_connection_up():
LOG.error("Not connected to a gRPC service.")
Expand All @@ -229,4 +182,4 @@ def is_single_project_mode(self) -> bool:
request = SherlockCommonService_pb2.SherlockInfoRequest()
response = self.stub.getSherlockInfo(request)
if response is not None:
return response.isSingleProjectMode
return response
11 changes: 11 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,16 @@ def helper_test_get_solders(common):
pytest.fail(str(e))


def helper_test_get_sherlock_info(common):
"""Test get_sherlock_info API"""

if common._is_connection_up():
try:
sherlock_info_response = common.get_sherlock_info()
assert sherlock_info_response is not None
except Exception as e:
pytest.fail(str(e))


if __name__ == "__main__":
test_all()
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_version_check():
# "get_sherlock_version" was added to PySherlock / Sherlock.
common = Common(channel, 242)
# This should fail since it did not exist in 242
common.get_sherlock_version()
common.get_sherlock_info()
pytest.fail("Sherlock version should be too low to launch this method")
except Exception as e:
if not isinstance(e, SherlockVersionError):
Expand Down

0 comments on commit d015663

Please sign in to comment.