diff --git a/git_utils.py b/git_utils.py index abfcea7192155a9025b62abed8dbdd5b3f931631..580b3f34ffda36f6822f2bee7d30bc11bc942985 100644 --- a/git_utils.py +++ b/git_utils.py @@ -111,4 +111,5 @@ COMMIT_RE = re.compile(COMMIT_PATTERN) def is_commit(commit): + """Whether a string looks like a SHA1 hash.""" return bool(COMMIT_RE.match(commit)) diff --git a/updater_utils.py b/updater_utils.py index cb1de54593a07e3b9283e0c8a665b3dd426465c9..b72d9cf2522125ef086037af66f98be9d9ae1dd3 100644 --- a/updater_utils.py +++ b/updater_utils.py @@ -64,7 +64,7 @@ VERSION_PATTERN = (r'^(?P<prefix>[^\d]*)' + VERSION_RE = re.compile(VERSION_PATTERN) -def parse_version(version): +def _parse_version(version): match = VERSION_RE.match(version) if match is None: raise ValueError('Invalid version.') @@ -76,7 +76,7 @@ def parse_version(version): def _match_and_get_version(prefix, suffix, version): try: - version_prefix, version, version_suffix = parse_version(version) + version_prefix, version, version_suffix = _parse_version(version) except ValueError: return [] @@ -86,13 +86,15 @@ def _match_and_get_version(prefix, suffix, version): return [int(v) for v in version.split('.')] -def get_latest_version(old_version, version_list): - old_prefix, _, old_suffix = parse_version(old_version) +def get_latest_version(current_version, version_list): + """Gets the latest version name from a list of versions. - latest = max(version_list + [old_version], - key=lambda ver: _match_and_get_version( - old_prefix, old_suffix, ver)) - if not latest: - return None + The new version must have the same prefix and suffix with old version. + If no matched version is newer, current version name will be returned. + """ + prefix, _, suffix = _parse_version(current_version) + latest = max(version_list + [current_version], + key=lambda ver: _match_and_get_version( + prefix, suffix, ver)) return latest