Debian Codegraph @

setup/git_version.py

raw
1 #!/usr/bin/env python
2 # License: GPLv3 Copyright: 2019, Eli Schwartz <[email protected]>
3
4
5 import re
6 import subprocess
7
8 from setup import Command
9
10
11 class GitVersion(Command):
12 description = 'Update the version from git metadata'
13
14 def run(self, opts):
15 constants_file = self.j(self.SRC, 'calibre', 'constants.py')
16
17 with open(constants_file, 'rb') as f:
18 src = f.read().decode('utf-8')
19
20 try:
21 nv = subprocess.check_output(['git', 'describe'])
22 nv = re.sub(r'([^-]*-g)', r'r\1', nv.decode('utf-8').strip().lstrip('v'))
23 nv = nv.replace('-', '.')
24 except subprocess.CalledProcessError:
25 raise SystemExit('Error: not a git checkout')
26 newsrc = re.sub(r'(git_version = ).*', rf'\1{nv!r}', src)
27 self.info('new version is:', nv)
28
29 with open(constants_file, 'wb') as f:
30 f.write(newsrc.encode('utf-8'))