def parse_version(self, version): # Allow an extra leading v and/or a missing minor version possible_versions = [version.replace("v", ""), version.replace("v", "") + ".0"] for version in possible_versions: try: return VersionInfo.parse(version) except ValueError: continue raise exceptions.InvalidVersionException( self, "Version is invalid: %s" % version )
def find_git_tag(self, tag): def possible_tags(tag): # Examples: # Input: 1.0.1 ; Output: ['1.0.1', 'v1.0.1'] # Input: 1.2.0 ; Output: ['1.2.0', 'v1.2.0', '1.2', 'v1.2'] tags = [tag, "v" + tag] if tag.endswith(".0"): tags.extend([tag[:-2], "v" + tag[:-2]]) return tags git_tags = list(map(str, self.git_repo.tags)) for possible_tag in possible_tags(str(tag)): if possible_tag in git_tags: return possible_tag raise exceptions.InvalidVersionException(self, "Cannot find a tag %s" % tag)