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