From b0efbf1560f54f2ab10e19c82d1741d74a01bde0 Mon Sep 17 00:00:00 2001 From: h-suzuki Date: Tue, 5 Mar 2024 15:53:58 +0900 Subject: [PATCH 1/8] 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: From 1b298536ffdd61d363a34a65761cc8a7a207bfe8 Mon Sep 17 00:00:00 2001 From: h-suzuki Date: Thu, 7 Mar 2024 14:07:34 +0900 Subject: [PATCH 2/8] Update: using xml.etree.ElementTree Signed-off-by: h-suzuki --- package.xml | 1 + ros2caret/verb/version.py | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package.xml b/package.xml index d6099b0..b160395 100644 --- a/package.xml +++ b/package.xml @@ -9,6 +9,7 @@ Apache License 2.0 python3-tabulate + ament_index_python ros2cli caret_analyze caret_msgs diff --git a/ros2caret/verb/version.py b/ros2caret/verb/version.py index 9bcc383..928bbc4 100644 --- a/ros2caret/verb/version.py +++ b/ros2caret/verb/version.py @@ -13,10 +13,10 @@ # limitations under the License. import os.path -import re from ros2caret.verb import VerbExtension -from ament_index_python.packages import get_package_share_directory +from ament_index_python.packages import get_package_share_directory, PackageNotFoundError +import xml.etree.ElementTree as ET class CaretVersionVerb(VerbExtension): @@ -26,13 +26,15 @@ def main(self, *, args): print('v' + version) def get_version(self): - 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: - return match.group(1) - else: - raise RuntimeError('Unable to find version string.') + # FileNotFoundError + try: + dir_path = get_package_share_directory('ros2caret') + xml_path = os.path.join(dir_path, 'package.xml') + tree = ET.parse(xml_path) + root = tree.getroot() + version_element = root.find('version') + if version_element is None: + raise RuntimeError("Error: Package version not found in package.xml") + return version_element.text + except(PackageNotFoundError, FileNotFoundError): + raise RuntimeError("Error: package or file share/ros2caret/package.xml not found") From 1d32d270b9f81f025085fb24b3d5222b65e9b032 Mon Sep 17 00:00:00 2001 From: h-suzuki Date: Thu, 7 Mar 2024 14:21:07 +0900 Subject: [PATCH 3/8] Fix: code style Signed-off-by: h-suzuki --- ros2caret/verb/version.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ros2caret/verb/version.py b/ros2caret/verb/version.py index 928bbc4..f70ebd4 100644 --- a/ros2caret/verb/version.py +++ b/ros2caret/verb/version.py @@ -13,11 +13,11 @@ # limitations under the License. import os.path - -from ros2caret.verb import VerbExtension from ament_index_python.packages import get_package_share_directory, PackageNotFoundError import xml.etree.ElementTree as ET +from ros2caret.verb import VerbExtension + class CaretVersionVerb(VerbExtension): @@ -34,7 +34,7 @@ def get_version(self): root = tree.getroot() version_element = root.find('version') if version_element is None: - raise RuntimeError("Error: Package version not found in package.xml") + raise RuntimeError('Error: Package version not found in package.xml') return version_element.text except(PackageNotFoundError, FileNotFoundError): - raise RuntimeError("Error: package or file share/ros2caret/package.xml not found") + raise RuntimeError('Error: package or file share/ros2caret/package.xml not found') From b0353eca4074f69b8b960de4e19f3822e3d66e1b Mon Sep 17 00:00:00 2001 From: h-suzuki Date: Thu, 7 Mar 2024 14:27:52 +0900 Subject: [PATCH 4/8] Fix: code style Signed-off-by: h-suzuki --- ros2caret/verb/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2caret/verb/version.py b/ros2caret/verb/version.py index f70ebd4..02efd71 100644 --- a/ros2caret/verb/version.py +++ b/ros2caret/verb/version.py @@ -13,9 +13,9 @@ # limitations under the License. import os.path + from ament_index_python.packages import get_package_share_directory, PackageNotFoundError import xml.etree.ElementTree as ET - from ros2caret.verb import VerbExtension From a972e73944bafbe10b12f942bf280a8ceda27324 Mon Sep 17 00:00:00 2001 From: h-suzuki Date: Thu, 7 Mar 2024 14:33:46 +0900 Subject: [PATCH 5/8] Fix: code style Signed-off-by: h-suzuki --- ros2caret/verb/version.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ros2caret/verb/version.py b/ros2caret/verb/version.py index 02efd71..f65e5d2 100644 --- a/ros2caret/verb/version.py +++ b/ros2caret/verb/version.py @@ -13,9 +13,10 @@ # limitations under the License. import os.path +import xml.etree.ElementTree as ET from ament_index_python.packages import get_package_share_directory, PackageNotFoundError -import xml.etree.ElementTree as ET + from ros2caret.verb import VerbExtension From eefec83c784213bee82f1172299c3762c270f394 Mon Sep 17 00:00:00 2001 From: h-suzuki Date: Fri, 8 Mar 2024 17:58:31 +0900 Subject: [PATCH 6/8] Update: error message Signed-off-by: h-suzuki --- ros2caret/verb/version.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ros2caret/verb/version.py b/ros2caret/verb/version.py index f65e5d2..026a855 100644 --- a/ros2caret/verb/version.py +++ b/ros2caret/verb/version.py @@ -38,4 +38,5 @@ def get_version(self): raise RuntimeError('Error: Package version not found in package.xml') return version_element.text except(PackageNotFoundError, FileNotFoundError): - raise RuntimeError('Error: package or file share/ros2caret/package.xml not found') + xml_path = os.path.join(get_package_share_directory('ros2caret'), 'package.xml') + raise RuntimeError(f'Error: not found {xml_path}') From 590ad0ec3c1fdd7f49f3148b0f88fb657369f9b8 Mon Sep 17 00:00:00 2001 From: h-suzuki-isp <146712054+h-suzuki-isp@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:48:40 +0900 Subject: [PATCH 7/8] Update ros2caret/verb/version.py Co-authored-by: ymski --- ros2caret/verb/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2caret/verb/version.py b/ros2caret/verb/version.py index 026a855..d04ab8d 100644 --- a/ros2caret/verb/version.py +++ b/ros2caret/verb/version.py @@ -39,4 +39,4 @@ def get_version(self): return version_element.text except(PackageNotFoundError, FileNotFoundError): xml_path = os.path.join(get_package_share_directory('ros2caret'), 'package.xml') - raise RuntimeError(f'Error: not found {xml_path}') + raise RuntimeError(f'Error: Cannot find {xml_path}') From 621b125d6a77ee47b85ff3a7d6fe6437adfea15b Mon Sep 17 00:00:00 2001 From: h-suzuki Date: Wed, 13 Mar 2024 11:37:14 +0900 Subject: [PATCH 8/8] Fix: delete comment Signed-off-by: h-suzuki --- ros2caret/verb/version.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ros2caret/verb/version.py b/ros2caret/verb/version.py index d04ab8d..b162133 100644 --- a/ros2caret/verb/version.py +++ b/ros2caret/verb/version.py @@ -27,7 +27,6 @@ def main(self, *, args): print('v' + version) def get_version(self): - # FileNotFoundError try: dir_path = get_package_share_directory('ros2caret') xml_path = os.path.join(dir_path, 'package.xml')