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