From 83abc7fab1764c4a025e873a9a0261c96cfb7125 Mon Sep 17 00:00:00 2001 From: qiujiacai Date: Mon, 25 Sep 2023 17:34:06 +0800 Subject: [PATCH] add conditional judgment to avoid string matching errors --- pyporter/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyporter/utils.py b/pyporter/utils.py index 1c8e3d4..c445694 100644 --- a/pyporter/utils.py +++ b/pyporter/utils.py @@ -3,7 +3,12 @@ import re # TODO: this should be more compatible for https://peps.python.org/pep-0508/ def transform_module_name(input_str): - module_name = re.match(r"([a-zA-Z0-9_-]+)", input_str).group(1).strip() + match = re.match(r"([a-zA-Z0-9_-]+)", input_str) + if match: + module_name = match.group(1).strip() + else: + raise ValueError("Invalid input format") + version_names = input_str[len(module_name):].strip().strip("()") version_constraint = version_names.split(",") package_name = "python3-" + module_name -- Gitee