Skip to content

Commit 91354ff

Browse files
updated add build prefix file to parse name using toml
1 parent 008f8c3 commit 91354ff

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

.github/actions/validator_pypi_publish/add_build_prefix.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import sys
3+
import toml
34

45

56
def add_package_name_prefix(
@@ -8,19 +9,10 @@ def add_package_name_prefix(
89
# Read the existing pyproject.toml file
910
with open(pyproject_path, "r") as f:
1011
content = f.read()
12+
parsed_toml = toml.loads(content)
1113

12-
try:
13-
# Check for the presence of the project.name key using a regular expression
14-
project_name_match = re.search(
15-
r'^name\s*=\s*"(.*?)"', content, flags=re.MULTILINE
16-
)
17-
if not project_name_match:
18-
print(f"Could not find the 'project.name' in {pyproject_path}.")
19-
sys.exit(1)
20-
existing_name = project_name_match.group(1)
21-
except Exception as e:
22-
print(f"Failed to parse project name in {pyproject_path}: {e}")
23-
sys.exit(1)
14+
# get the existing package name
15+
existing_name = parsed_toml.get("project", {}).get("name")
2416

2517
# Update the project name to the new PEP 503-compliant name
2618
# The package name would've been converted to PEP 503-compliant anyways
@@ -65,8 +57,8 @@ def add_package_name_prefix(
6557
if __name__ == "__main__":
6658
if len(sys.argv) < 3:
6759
print(
68-
"Usage: python script.py <pyproject_path> "
69-
"<pep_503_new_package_name> <validator-folder-name>"
60+
"Usage: python script.py <pyproject_path>"
61+
" <pep_503_new_package_name> <validator-folder-name>"
7062
)
7163
sys.exit(1)
7264

0 commit comments

Comments
 (0)