ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Answering my own question...
import os
import xml.etree.ElementTree as ET
from ament_index_python import get_package_share_directory
def get_package_version(pkg_name):
pkg_share_dir = get_package_share_directory(pkg_name)
package_xml_path = os.path.join(pkg_share_dir, "package.xml")
xmldata = ET.parse(package_xml_path)
version = xmldata.findall("version")[0].text
return version
Credit to @daniel-stonier for the suggestion.