1 from setuptools.command.egg_info import egg_info
5 class GitTagger(egg_info):
6 """Tag the build with git commit info.
8 Exact choice and format is determined by subclass's tags_to_add
11 If a build tag has already been set (e.g., "egg_info -b", building
12 from source package), leave it alone.
14 def git_commit_info(self):
15 gitinfo = subprocess.check_output(
16 ['git', 'log', '--first-parent', '--max-count=1',
17 '--format=format:%ct %h', '.']).split()
18 assert len(gitinfo) == 2
20 'commit_utc': time.strftime(
21 '%Y%m%d%H%M%S', time.gmtime(int(gitinfo[0]))),
22 'commit_sha1': gitinfo[1],
26 if self.tag_build is None:
27 self.tag_build = self.tags_to_add()
28 return egg_info.tags(self)
31 class TagBuildWithCommitDateAndSha1(GitTagger):
32 """Tag the build with the sha1 and date of the last git commit."""
33 def tags_to_add(self):
34 return '.{commit_utc}+{commit_sha1}'.format(**self.git_commit_info())
37 class TagBuildWithCommitDate(GitTagger):
38 """Tag the build with the date of the last git commit."""
39 def tags_to_add(self):
40 return '.{commit_utc}'.format(**self.git_commit_info())