@@ -108,7 +108,7 @@ def generate_versionfile(package_version: str, output_filename: str) -> Path:
108108
109109 # Convert version with suffix to Windows-compatible 4-part version
110110 # Windows version files require exactly 4 numeric components
111- windows_version = convert_version_for_windows (package_version )
111+ windows_version = convert_version_to_4part (package_version )
112112 logger .info (f"Converting version '{ package_version } ' to Windows-compatible version '{ windows_version } '" )
113113
114114 pyinstaller_versionfile .create_versionfile (
@@ -125,16 +125,20 @@ def generate_versionfile(package_version: str, output_filename: str) -> Path:
125125 return versionfile_path
126126
127127
128- def convert_version_for_windows (version_string : str ) -> str :
128+ def convert_version_to_4part (version_string : str , always_include_build : bool = False ) -> str :
129129 """
130- Convert a version string with optional suffix to a Windows-compatible 4-part version.
131- Windows version files require exactly 4 numeric components.
130+ Generic function to convert a version string with optional suffix to a compatible version.
131+
132+ Args:
133+ version_string: Version string in X.Y.Z[-SUFFIX] format
134+ always_include_build: If True, always return 4-part version (X.Y.Z.BUILD)
135+ If False, only include build number when suffix exists
132136
133137 Examples:
134- - "1.2.3" -> "1.2.3.0"
135- - "2.0.0-RC1" -> "2.0.0.1" (RC1 = build 1)
136- - "1.0.0-BETA2" -> "1.0.0.2" (BETA2 = build 2)
137- - "3.1.0-ALPHA" -> "3.1.0.3" (ALPHA = build 3)
138+ - "1.2.3" -> "1.2.3" (always_include_build=False) or "1.2.3.0" (always_include_build=True)
139+ - "2.0.0-RC1" -> "2.0.0.1"
140+ - "1.0.0-BETA2" -> "1.0.0.12"
141+ - "3.1.0-ALPHA" -> "3.1.0.20"
138142 """
139143 # Split version and suffix
140144 if '-' in version_string :
@@ -182,9 +186,11 @@ def convert_version_for_windows(version_string: str) -> str:
182186 # Unknown suffix, use a high build number to avoid conflicts
183187 build_number = 100
184188
185- # Return 4-part version: X.Y.Z.BUILD
186- return f"{ version_components [0 ]} .{ version_components [1 ]} .{ version_components [2 ]} .{ build_number } "
187-
189+ # Return version based on always_include_build parameter
190+ if always_include_build or build_number > 0 :
191+ return f"{ version_components [0 ]} .{ version_components [1 ]} .{ version_components [2 ]} .{ build_number } "
192+ else :
193+ return base_version
188194
189195def run_linuxdeploy_appimage (package_version : str ) -> None :
190196 """Build AppImage using linuxdeploy."""
@@ -380,12 +386,17 @@ def update_buildozer_version(package_version: str) -> None:
380386 logger .info ("Updating version in buildozer.spec" )
381387 buildozer_spec_path = ROOT_PATH .joinpath ("buildozer.spec" )
382388
389+ # Convert version with suffix to Android-compatible version
390+ # Android build system expects a version string that can be parsed into numeric components
391+ android_version = convert_version_to_4part (package_version )
392+ logger .info (f"Converting version '{ package_version } ' to Android-compatible version '{ android_version } '" )
393+
383394 with open (buildozer_spec_path , 'r' ) as file :
384395 lines = file .readlines ()
385396
386397 for i , line in enumerate (lines ):
387398 if line .startswith ('version = ' ):
388- lines [i ] = f'version = { package_version } \n '
399+ lines [i ] = f'version = { android_version } \n '
389400 break
390401
391402 with open (buildozer_spec_path , 'w' ) as file :
0 commit comments