From b0efbf1560f54f2ab10e19c82d1741d74a01bde0 Mon Sep 17 00:00:00 2001 From: h-suzuki Date: Tue, 5 Mar 2024 15:53:58 +0900 Subject: [PATCH] change method of getting version from setup.py to package.xml Signed-off-by: h-suzuki --- ros2caret/verb/version.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ros2caret/verb/version.py b/ros2caret/verb/version.py index e947520..9bcc383 100644 --- a/ros2caret/verb/version.py +++ b/ros2caret/verb/version.py @@ -16,6 +16,7 @@ import re from ros2caret.verb import VerbExtension +from ament_index_python.packages import get_package_share_directory class CaretVersionVerb(VerbExtension): @@ -25,9 +26,10 @@ def main(self, *, args): print('v' + version) def get_version(self): - version_path = f'{os.path.dirname(os.path.realpath(__file__))}/../../setup.py' - version_pattern = re.compile(r"\s*version\s*=\s*['\"](\d+\.\d+\.\d+)['\"]") - with open(version_path) as f: + dir_path = get_package_share_directory('ros2caret') + xml_path = os.path.join(dir_path, 'package.xml') + version_pattern = re.compile(r"\s*\s*(\d+\.\d+\.\d+)\s*\s*") + with open(xml_path) as f: for line in f: match = version_pattern.search(line) if match: