1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 from builtins import str
6 from builtins import next
8 from setuptools.command.egg_info import egg_info
13 SETUP_DIR = os.path.dirname(__file__) or '.'
15 def choose_version_from():
16 sdk_ts = subprocess.check_output(
17 ['git', 'log', '--first-parent', '--max-count=1',
18 '--format=format:%ct', os.path.join(SETUP_DIR, "../python")]).strip()
19 cwl_ts = subprocess.check_output(
20 ['git', 'log', '--first-parent', '--max-count=1',
21 '--format=format:%ct', SETUP_DIR]).strip()
22 if int(sdk_ts) > int(cwl_ts):
23 getver = os.path.join(SETUP_DIR, "../python")
28 class EggInfoFromGit(egg_info):
29 """Tag the build with git commit timestamp.
31 If a build tag has already been set (e.g., "egg_info -b", building
32 from source package), leave it alone.
34 def git_latest_tag(self):
35 gittags = subprocess.check_output(['git', 'tag', '-l']).split()
36 gittags.sort(key=lambda s: [int(u) for u in s.split(b'.')],reverse=True)
37 return str(next(iter(gittags)).decode('utf-8'))
39 def git_timestamp_tag(self):
40 gitinfo = subprocess.check_output(
41 ['git', 'log', '--first-parent', '--max-count=1',
42 '--format=format:%ct', choose_version_from()]).strip()
43 return time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo)))
46 if self.tag_build is None:
47 self.tag_build = self.git_latest_tag() + self.git_timestamp_tag()
48 return egg_info.tags(self)