11import re
22import sys
3+ import toml
34
45
56def 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(
6557if __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