From 6a0ff37573bd4384d00c7a3e4af5a28c962a808a Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 5 Oct 2021 07:30:48 +0200 Subject: [PATCH] CON-92: Handle case in obtaining version where Connector was git cloned (#87) --- .../rticonnextdds_connector.py | 19 ++++++++++++++----- test/python/test_rticonnextdds_connector.py | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/rticonnextdds_connector/rticonnextdds_connector.py b/rticonnextdds_connector/rticonnextdds_connector.py index 005da5f..5635573 100644 --- a/rticonnextdds_connector/rticonnextdds_connector.py +++ b/rticonnextdds_connector/rticonnextdds_connector.py @@ -1372,14 +1372,23 @@ def get_version(): This method provides the build IDs of the native libraries being used by Connector, as well as the version of the Connector API. + Note that if Connector has not been installed via pip, the version of + the Connector API being used will be "unknown". The version of the native + libraries will still be returned correctly. + :return: A string containing information about the version of Connector. :rtype: string """ - # First, get the version of the Connector API from setup.py - setup_py_version = pkg_resources.require("rticonnextdds-connector")[0].version - # The version contained in setup.py contains 3 ints, e.g. 1.1.0 - version_ints = setup_py_version.split(".") - api_version = str(version_ints[0]) + "." + str(version_ints[1]) + "." + str(version_ints[2]) + # First, try to get the version of the Connector API from setup.py + # If Connector was git cloned (as opposed to installed via pip) this + # will fail and we will print "unknown" for the version + try: + setup_py_version = pkg_resources.require("rticonnextdds-connector")[0].version + # The version contained in setup.py contains 3 ints, e.g. 1.1.0 + version_ints = setup_py_version.split(".") + api_version = str(version_ints[0]) + "." + str(version_ints[1]) + "." + str(version_ints[2]) + except pkg_resources.DistributionNotFound: + api_version = "unknown" # Now get the build IDs of the native libraries native_core_c_versions = ctypes.c_void_p() diff --git a/test/python/test_rticonnextdds_connector.py b/test/python/test_rticonnextdds_connector.py index 01b6d3b..9813209 100644 --- a/test/python/test_rticonnextdds_connector.py +++ b/test/python/test_rticonnextdds_connector.py @@ -122,7 +122,7 @@ def test_get_version(self): # - the build ID of core.1.0 # - the build ID of dds_c.1.0 # - the build ID of lua_binding.1.0 - assert bool(re.match("RTI Connector for Python, version ([0-9]\\.){2}[0-9]", version_string, re.DOTALL)) == True + assert bool(re.match("RTI Connector for Python, version (([0-9]\\.){2}[0-9]|unknown)", version_string, re.DOTALL)) == True assert bool(re.match(".*NDDSCORE_BUILD_([0-9]\\.){2}[0-9]_[0-9]{8}T[0-9]{6}Z", version_string, re.DOTALL)) == True assert bool(re.match(".*NDDSC_BUILD_([0-9]\\.){2}[0-9]_[0-9]{8}T[0-9]{6}Z", version_string, re.DOTALL)) == True assert bool(re.match(".*RTICONNECTOR_BUILD_([0-9]\\.){2}[0-9]_[0-9]{8}T[0-9]{6}Z", version_string, re.DOTALL)) == True