Skip to content

Commit 998f3a5

Browse files
committed
Update get_semantic_version to handle the latest Qt version format
1 parent 0819495 commit 998f3a5

File tree

1 file changed

+59
-23
lines changed

1 file changed

+59
-23
lines changed

aqt/metadata.py

+59-23
Original file line numberDiff line numberDiff line change
@@ -170,31 +170,67 @@ def flattened(self) -> List[Version]:
170170

171171

172172
def get_semantic_version(qt_ver: str, is_preview: bool) -> Optional[Version]:
173-
"""Converts a Qt version string (596, 512, 5132, etc) into a semantic version.
174-
This makes a lot of assumptions based on established patterns:
175-
If is_preview is True, the number is interpreted as ver[0].ver[1:], with no patch.
176-
If the version is 3 digits, then major, minor, and patch each get 1 digit.
177-
If the version is 4 or more digits, then major gets 1 digit, minor gets 2 digits
178-
and patch gets all the rest.
179-
As of May 2021, the version strings at https://download.qt.io/online/qtsdkrepository
180-
conform to this pattern; they are not guaranteed to do so in the future.
173+
"""Converts a Qt version string into a semantic version.
174+
Handles both traditional format (e.g. '51212' -> '5.12.12') and
175+
new format with underscores (e.g. '6_7_3' -> '6.7.3').
176+
177+
Args:
178+
qt_ver: Version string (e.g. '51212', '600', '6_7_3')
179+
is_preview: Whether this is a preview version
180+
181+
Returns:
182+
Version object or None if invalid format
183+
184+
Examples:
185+
>>> get_semantic_version('51212', False)
186+
Version('5.12.12')
187+
>>> get_semantic_version('600', False)
188+
Version('6.0.0')
189+
>>> get_semantic_version('6_7_3', False)
190+
Version('6.7.3')
181191
"""
182-
if not qt_ver or any(not ch.isdigit() for ch in qt_ver):
192+
if not qt_ver:
193+
return None
194+
195+
try:
196+
# Handle versions with underscores (new format)
197+
if '_' in qt_ver:
198+
parts = qt_ver.split('_')
199+
if len(parts) < 2 or len(parts) > 3:
200+
return None
201+
202+
major = int(parts[0])
203+
minor = int(parts[1])
204+
patch = int(parts[2]) if len(parts) == 3 else 0
205+
206+
version_str = f"{major}.{minor}.{patch}"
207+
if is_preview:
208+
version_str += ".dev0"
209+
return Version(version_str)
210+
211+
# Handle traditional format (continuous digits)
212+
if any(not ch.isdigit() for ch in qt_ver):
213+
return None
214+
215+
# For traditional format, construct version parts first
216+
if len(qt_ver) >= 4:
217+
major, minor, patch = int(qt_ver[:1]), int(qt_ver[1:3]), int(qt_ver[3:])
218+
elif len(qt_ver) == 3:
219+
major, minor, patch = int(qt_ver[:1]), int(qt_ver[1:2]), int(qt_ver[2:])
220+
elif len(qt_ver) == 2:
221+
major, minor, patch = int(qt_ver[:1]), int(qt_ver[1:]), 0
222+
else:
223+
return None
224+
225+
# Then create the version string with appropriate preview suffix
226+
version_str = f"{major}.{minor}.{patch}"
227+
if is_preview:
228+
version_str += ".dev0"
229+
230+
return Version(version_str)
231+
232+
except ValueError:
183233
return None
184-
if is_preview:
185-
return Version(
186-
major=int(qt_ver[:1]),
187-
minor=int(qt_ver[1:]),
188-
patch=0,
189-
prerelease=("preview",),
190-
)
191-
elif len(qt_ver) >= 4:
192-
return Version(major=int(qt_ver[:1]), minor=int(qt_ver[1:3]), patch=int(qt_ver[3:]))
193-
elif len(qt_ver) == 3:
194-
return Version(major=int(qt_ver[:1]), minor=int(qt_ver[1:2]), patch=int(qt_ver[2:]))
195-
elif len(qt_ver) == 2:
196-
return Version(major=int(qt_ver[:1]), minor=int(qt_ver[1:2]), patch=0)
197-
raise ValueError("Invalid version string '{}'".format(qt_ver))
198234

199235

200236
class ArchiveId:

0 commit comments

Comments
 (0)