Ask Your Question
1

ROS2: Read package version at runtime from python

asked 2021-07-26 13:58:12 -0500

danbrooks gravatar image

Is it possible to read the version number listed in package.xml at runtime from python?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-07-27 10:58:19 -0500

danbrooks gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2021-07-26 13:58:12 -0500

Seen: 42 times

Last updated: Jul 27 '21