@@ -106,29 +106,35 @@ def upload_to_pypi(dist_files, max_attempts=3):
106
106
return False
107
107
108
108
def update_version ():
109
+ with open ('VERSION' , 'r' ) as f :
110
+ current_version = f .read ().strip ()
111
+
112
+ print (f"Current version: { current_version } " )
113
+ while True :
114
+ new_version = input ("Enter new version number (e.g., 0.1.7): " )
115
+ if re .match (r'^\d+(\.\d+){0,2}(\.?[a-zA-Z0-9]+)?$' , new_version ):
116
+ try :
117
+ version .parse (new_version )
118
+ break
119
+ except version .InvalidVersion :
120
+ print ("Invalid version format. Please use a valid version number." )
121
+ else :
122
+ print ("Invalid version format. Please use a valid version number." )
123
+
124
+ # Update VERSION file
125
+ with open ('VERSION' , 'w' ) as f :
126
+ f .write (new_version )
127
+
128
+ # Update setup.py
109
129
with open ('setup.py' , 'r' ) as f :
110
- content = f .readlines ()
130
+ content = f .read ()
111
131
112
- for i , line in enumerate (content ):
113
- if line .strip ().startswith ('version=' ):
114
- current_version = line .split ('=' )[1 ].strip ().strip ("'" ).strip ('"' )
115
- print (f"Current version: { current_version } " )
116
- while True :
117
- new_version = input ("Enter new version number (e.g., 0.1.7): " )
118
- if re .match (r'^\d+(\.\d+){0,2}(\.?[a-zA-Z0-9]+)?$' , new_version ):
119
- try :
120
- version .parse (new_version )
121
- break
122
- except version .InvalidVersion :
123
- print ("Invalid version format. Please use a valid version number." )
124
- else :
125
- print ("Invalid version format. Please use a valid version number." )
126
- content [i ] = f" version='{ new_version } ',\n "
127
- break
132
+ updated_content = re .sub (r"version=['\"][\d.]+['\"]" , f"version='{ new_version } '" , content )
128
133
129
134
with open ('setup.py' , 'w' ) as f :
130
- f .writelines ( content )
135
+ f .write ( updated_content )
131
136
137
+ print (f"Updated VERSION file and setup.py with new version: { new_version } " )
132
138
return new_version
133
139
134
140
def main ():
0 commit comments