1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 from setuptools.command.egg_info import egg_info
10 SETUP_DIR = os.path.dirname(__file__) or '.'
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")
25 class EggInfoFromGit(egg_info):
26 """Tag the build with git commit timestamp.
28 If a build tag has already been set (e.g., "egg_info -b", building
29 from source package), leave it alone.
31 def git_latest_tag(self):
32 gitinfo = subprocess.check_output(
33 ['git', 'describe', '--abbrev=0']).strip()
34 return str(gitinfo.decode('utf-8'))
36 def git_timestamp_tag(self):
37 gitinfo = subprocess.check_output(
38 ['git', 'log', '--first-parent', '--max-count=1',
39 '--format=format:%ct', choose_version_from()]).strip()
40 return time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo)))
43 if self.tag_build is None:
44 self.tag_build = self.git_latest_tag() + self.git_timestamp_tag()
45 return egg_info.tags(self)