Merge branch '8784-dir-listings'
[arvados.git] / sdk / cwl / gittaggers.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 from setuptools.command.egg_info import egg_info
6 import subprocess
7 import time
8 import os
9
10 SETUP_DIR = os.path.dirname(__file__) or '.'
11
12 def choose_version_from():
13     sdk_ts = subprocess.check_output(
14         ['git', 'log', '--first-parent', '--max-count=1',
15          '--format=format:%ct', os.path.join(SETUP_DIR, "../python")]).strip()
16     cwl_ts = subprocess.check_output(
17         ['git', 'log', '--first-parent', '--max-count=1',
18          '--format=format:%ct', SETUP_DIR]).strip()
19     if int(sdk_ts) > int(cwl_ts):
20         getver = os.path.join(SETUP_DIR, "../python")
21     else:
22         getver = SETUP_DIR
23     return getver
24
25 class EggInfoFromGit(egg_info):
26     """Tag the build with git commit timestamp.
27
28     If a build tag has already been set (e.g., "egg_info -b", building
29     from source package), leave it alone.
30     """
31
32     def git_timestamp_tag(self):
33         gitinfo = subprocess.check_output(
34             ['git', 'log', '--first-parent', '--max-count=1',
35              '--format=format:%ct', choose_version_from()]).strip()
36         return time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo)))
37
38     def tags(self):
39         if self.tag_build is None:
40             self.tag_build = self.git_timestamp_tag()
41         return egg_info.tags(self)