setup.py: Avoid dpkg-parsechangelog
authorGuido Günther <agx@sigxcpu.org>
Wed, 28 Apr 2021 07:03:28 +0000 (09:03 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 28 Apr 2021 07:15:31 +0000 (09:15 +0200)
This helps on non-debian systems

setup.py

index fc99c5a94fcd7a13b9315073a88308564050cdda..962bf14c6f5ab9cbde74457fe9f2adbac16d4f21 100755 (executable)
--- a/setup.py
+++ b/setup.py
 # END OF COPYRIGHT #
 
 import os
+import re
 from setuptools import setup, find_packages
-import subprocess
 
 VERSION_PY_PATH = 'gbp/version.py'
 
 
 def _parse_changelog():
     """Get version from debian changelog and write it to gbp/version.py"""
-    popen = subprocess.Popen('dpkg-parsechangelog', stdout=subprocess.PIPE)
-    out, ret = popen.communicate()
-    for line in out.decode('utf-8').split('\n'):
-        if line.startswith('Version:'):
-            version = line.split(' ')[1].strip()
-            return version
+    with open("debian/changelog") as f:
+        line = f.readline()
+
+    m = re.match(".* \\(([0-9.]+)\\) ", line)
+    if m:
+        return m.group(1)
 
     raise ValueError('Could not parse version from debian/changelog')