X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f8067dd18b72705f3317e85745e87cffc9e25313..5d825f773a037ccf977918cd4dff866792390826:/sdk/python/gittaggers.py diff --git a/sdk/python/gittaggers.py b/sdk/python/gittaggers.py index ea7898146c..f3278fcc1d 100644 --- a/sdk/python/gittaggers.py +++ b/sdk/python/gittaggers.py @@ -1,40 +1,29 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + from setuptools.command.egg_info import egg_info import subprocess import time -class GitTagger(egg_info): - """Tag the build with git commit info. - - Exact choice and format is determined by subclass's tags_to_add - method. +class EggInfoFromGit(egg_info): + """Tag the build with git commit timestamp. If a build tag has already been set (e.g., "egg_info -b", building from source package), leave it alone. """ - def git_commit_info(self): + def git_latest_tag(self): + gittags = subprocess.check_output(['git', 'tag', '-l']).split() + gittags.sort(key=lambda s: [int(u) for u in s.split(b'.')],reverse=True) + return str(next(iter(gittags)).decode('utf-8')) + + def git_timestamp_tag(self): gitinfo = subprocess.check_output( ['git', 'log', '--first-parent', '--max-count=1', - '--format=format:%ct %h', '.']).split() - assert len(gitinfo) == 2 - return { - 'commit_utc': time.strftime( - '%Y%m%d%H%M%S', time.gmtime(int(gitinfo[0]))), - 'commit_sha1': gitinfo[1], - } + '--format=format:%ct', '.']).strip() + return time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo))) def tags(self): if self.tag_build is None: - self.tag_build = self.tags_to_add() + self.tag_build = self.git_latest_tag()+self.git_timestamp_tag() return egg_info.tags(self) - - -class TagBuildWithCommitDateAndSha1(GitTagger): - """Tag the build with the sha1 and date of the last git commit.""" - def tags_to_add(self): - return '.{commit_utc}+{commit_sha1}'.format(**self.git_commit_info()) - - -class TagBuildWithCommitDate(GitTagger): - """Tag the build with the date of the last git commit.""" - def tags_to_add(self): - return '.{commit_utc}'.format(**self.git_commit_info())