Merge branch '17044-remove-debian-stretch' into master
[arvados.git] / sdk / python / gittaggers.py
index ea7898146c5cb9bf059c260d5d6f3acdc5fd79cd..f3278fcc1d5e7aeab1f6748f90bc80040e6fce37 100644 (file)
@@ -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())