calibre/setup/git_version.py
un-pogaz 19994000c9 use f-string instead of format call (extra-edit)
ruff 'UP030,UP032' --extend-exclude "src/calibre/*" !partial
2025-01-24 11:14:16 +01:00

32 lines
928 B
Python
Executable File

#!/usr/bin/env python
# License: GPLv3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
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 = ).*', rf'\1{nv!r}', src)
self.info('new version is:', nv)
with open(constants_file, 'wb') as f:
f.write(newsrc.encode('utf-8'))