22"""
33Version Synchronization Script for project-x-py
44
5- This script ensures all version references are synchronized with the single
5+ This script ensures all version references are synchronized with the single
66source of truth in src/project_x_py/__init__.py before building.
77
88Usage:
@@ -21,12 +21,12 @@ def get_version_from_init():
2121 init_file = Path ("src/project_x_py/__init__.py" )
2222 if not init_file .exists ():
2323 raise FileNotFoundError (f"Cannot find { init_file } " )
24-
24+
2525 content = init_file .read_text ()
2626 match = re .search (r'__version__ = ["\']([^"\']+)["\']' , content )
2727 if not match :
2828 raise ValueError ("Cannot find __version__ in __init__.py" )
29-
29+
3030 return match .group (1 )
3131
3232
@@ -36,15 +36,15 @@ def update_pyproject_toml(version):
3636 if not pyproject_file .exists ():
3737 print ("⚠️ pyproject.toml not found, skipping" )
3838 return False
39-
39+
4040 content = pyproject_file .read_text ()
4141 new_content = re .sub (
4242 r'^version = ["\'][^"\']+["\']' ,
4343 f'version = "{ version } "' ,
4444 content ,
45- flags = re .MULTILINE
45+ flags = re .MULTILINE ,
4646 )
47-
47+
4848 if content != new_content :
4949 pyproject_file .write_text (new_content )
5050 print (f"✅ Updated pyproject.toml to version { version } " )
@@ -60,14 +60,12 @@ def update_indicators_init(version):
6060 if not indicators_file .exists ():
6161 print ("⚠️ indicators/__init__.py not found, skipping" )
6262 return False
63-
63+
6464 content = indicators_file .read_text ()
6565 new_content = re .sub (
66- r'__version__ = ["\'][^"\']+["\']' ,
67- f'__version__ = "{ version } "' ,
68- content
66+ r'__version__ = ["\'][^"\']+["\']' , f'__version__ = "{ version } "' , content
6967 )
70-
68+
7169 if content != new_content :
7270 indicators_file .write_text (new_content )
7371 print (f"✅ Updated indicators/__init__.py to version { version } " )
@@ -83,31 +81,27 @@ def update_readme(version):
8381 if not readme_file .exists ():
8482 print ("⚠️ README.md not found, skipping" )
8583 return False
86-
84+
8785 content = readme_file .read_text ()
8886 changes_made = False
89-
87+
9088 # Update "Current Version" section
9189 new_content = re .sub (
92- r'\*\*Current Version\*\*: v[\d.]+' ,
93- f'**Current Version**: v{ version } ' ,
94- content
90+ r"\*\*Current Version\*\*: v[\d.]+" , f"**Current Version**: v{ version } " , content
9591 )
96-
92+
9793 # Update changelog section
9894 new_content = re .sub (
99- r'### Version [\d.]+ \(Latest\)' ,
100- f'### Version { version } (Latest)' ,
101- new_content
95+ r"### Version [\d.]+ \(Latest\)" , f"### Version { version } (Latest)" , new_content
10296 )
103-
97+
10498 if content != new_content :
10599 readme_file .write_text (new_content )
106100 print (f"✅ Updated README.md to version { version } " )
107101 changes_made = True
108102 else :
109103 print (f"✓ README.md already at version { version } " )
110-
104+
111105 return changes_made
112106
113107
@@ -117,19 +111,15 @@ def update_docs_conf(version):
117111 if not conf_file .exists ():
118112 print ("⚠️ docs/conf.py not found, skipping" )
119113 return False
120-
114+
121115 content = conf_file .read_text ()
122116 new_content = re .sub (
123- r'release = ["\'][^"\']+["\']' ,
124- f'release = "{ version } "' ,
125- content
117+ r'release = ["\'][^"\']+["\']' , f'release = "{ version } "' , content
126118 )
127119 new_content = re .sub (
128- r'version = ["\'][^"\']+["\']' ,
129- f'version = "{ version } "' ,
130- new_content
120+ r'version = ["\'][^"\']+["\']' , f'version = "{ version } "' , new_content
131121 )
132-
122+
133123 if content != new_content :
134124 conf_file .write_text (new_content )
135125 print (f"✅ Updated docs/conf.py to version { version } " )
@@ -142,32 +132,32 @@ def update_docs_conf(version):
142132def main ():
143133 """Main synchronization process."""
144134 print ("🔄 Synchronizing version numbers..." )
145-
135+
146136 try :
147137 # Get the authoritative version
148138 version = get_version_from_init ()
149139 print (f"📋 Source version: { version } " )
150-
140+
151141 # Update all files
152142 changes = []
153143 changes .append (update_pyproject_toml (version ))
154144 changes .append (update_indicators_init (version ))
155145 changes .append (update_readme (version ))
156146 changes .append (update_docs_conf (version ))
157-
147+
158148 # Summary
159149 if any (changes ):
160150 print (f"\n ✅ Version synchronization complete! All files now at v{ version } " )
161151 print (" Ready for: uv build" )
162152 else :
163153 print (f"\n ✓ All files already synchronized at v{ version } " )
164-
154+
165155 return 0
166-
156+
167157 except Exception as e :
168158 print (f"\n ❌ Error during version sync: { e } " )
169159 return 1
170160
171161
172162if __name__ == "__main__" :
173- sys .exit (main ())
163+ sys .exit (main ())
0 commit comments