forked from kovidgoyal/calibre
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_version.py
executable file
·33 lines (23 loc) · 1.02 KB
/
git_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2019, Eli Schwartz <[email protected]>
from __future__ import absolute_import, division, print_function, unicode_literals
import re
import subprocess
from setup import Command
class GitVersion(Command):
description = 'Update the version from git metadata'
def run(self, opts):
constants_file = self.j(self.SRC, 'calibre', 'constants.py')
with open(constants_file, 'rb') as f:
src = f.read().decode('utf-8')
try:
nv = subprocess.check_output(['git', 'describe'])
nv = re.sub(r'([^-]*-g)', r'r\1', nv.decode('utf-8').strip().lstrip('v'))
nv = nv.replace('-', '.')
except subprocess.CalledProcessError:
raise SystemExit('Error: not a git checkout')
newsrc = re.sub(r'(git_version = ).*', r'\1%s' % repr(nv), src)
self.info('new version is:', nv)
with open(constants_file, 'wb') as f:
f.write(newsrc.encode('utf-8'))