Skip to content

Commit

Permalink
CON-92: Handle case in obtaining version where Connector was git clon…
Browse files Browse the repository at this point in the history
…ed (#87)
  • Loading branch information
samuelraeburn authored Oct 5, 2021
1 parent 62a573c commit 6a0ff37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions rticonnextdds_connector/rticonnextdds_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/python/test_rticonnextdds_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a0ff37

Please sign in to comment.