aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2019-03-19 15:32:12 +0100
committerGuido Günther <agx@sigxcpu.org>2019-03-19 15:34:34 +0100
commit3e3458fa752d45826de6a1759e9228050825003e (patch)
tree9a8d241e0cbb2e91a087e9ce380f4ec8976cb67b
parent34b9da1de902be0f4e43fd99d0fcb7e278bedbd9 (diff)
setup.py: Move version parser into setup.py
This makes sure it ends up in the sdist tarball.
-rwxr-xr-xsetup.py41
-rw-r--r--version_parser.py42
2 files changed, 40 insertions, 43 deletions
diff --git a/setup.py b/setup.py
index 150dfdd..fc99c5a 100755
--- a/setup.py
+++ b/setup.py
@@ -19,7 +19,46 @@
import os
from setuptools import setup, find_packages
-from version_parser import parse_and_fetch_version
+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
+
+ raise ValueError('Could not parse version from debian/changelog')
+
+
+def _save_version_py(version):
+ with open(VERSION_PY_PATH, 'w') as f:
+ f.write('"The current gbp version number"\n')
+ f.write('gbp_version = "%s"\n' % version)
+
+
+def _load_version():
+ with open(VERSION_PY_PATH, 'r') as f:
+ version_py = f.read()
+ version_py_globals = {}
+ exec(version_py, version_py_globals)
+ return version_py_globals['gbp_version']
+
+
+def parse_and_fetch_version():
+ if os.path.exists('debian/changelog'):
+ version = _parse_changelog()
+ _save_version_py(version)
+ # we could return with the version here, but instead we check that
+ # the file has been properly written and it can be loaded back
+
+ version = _load_version()
+ return version
def readme():
diff --git a/version_parser.py b/version_parser.py
deleted file mode 100644
index 793d77d..0000000
--- a/version_parser.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import os
-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
-
- raise ValueError('Could not parse version from debian/changelog')
-
-
-def _save_version_py(version):
- with open(VERSION_PY_PATH, 'w') as f:
- f.write('"The current gbp version number"\n')
- f.write('gbp_version = "%s"\n' % version)
-
-
-def _load_version():
- with open(VERSION_PY_PATH, 'r') as f:
- version_py = f.read()
- version_py_globals = {}
- exec(version_py, version_py_globals)
- return version_py_globals['gbp_version']
-
-
-def parse_and_fetch_version():
- if os.path.exists('debian/changelog'):
- version = _parse_changelog()
- _save_version_py(version)
- # we could return with the version here, but instead we check that
- # the file has been properly written and it can be loaded back
-
- version = _load_version()
- return version