[bmap-tools] [PATCH 08/14] setup.py: automatically detect version number

Artem Bityutskiy dedekind1 at gmail.com
Thu Sep 19 06:35:21 EDT 2013


From: Artem Bityutskiy <artem.bityutskiy at intel.com>

We currently duplicate the project version number in bmaptool and setup.py
files. Let's get rid of the duplication and have setup.py parse the bmaptool
file and fetch the version number.

Change-Id: I06ee68ca29b16fac2cbfa53cd9a61329b8606409
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at intel.com>
---
 TODO     |  1 -
 setup.py | 14 +++++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/TODO b/TODO
index dd622bc..7eacd8d 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,5 @@
 Current TODO list, any help with these is appreciated.
 
-3. In setup.py, fetch the version from 'bmaptool' file.
 4. Teach the 'make_a_release.sh' script to update the version and the
    changelog.
 6. Write in the man page, docs, and may be --help that it is very important
diff --git a/setup.py b/setup.py
index cc864a9..1d38bf7 100644
--- a/setup.py
+++ b/setup.py
@@ -1,13 +1,25 @@
 #!/usr/bin/env python
 
+import re
 from setuptools import setup, find_packages
 
+def get_version():
+    """Fetch the project version number from the 'bmaptool' file."""
+
+    with open("bmaptool", "r") as fobj:
+        for line in fobj:
+            matchobj = re.match(r'^VERSION = "(\d+.\d+)"$', line)
+            if matchobj:
+                return matchobj.group(1)
+
+    return None
+
 setup(
     name="bmap-tools",
     description="Bmap tools",
     author="Artem Bityutskiy",
     author_email="artem.bityutskiy at linux.intel.com",
-    version="2.6",
+    version=get_version(),
     scripts=['bmaptool'],
     packages=find_packages(exclude=["test*"]),
     license='GPLv2',
-- 
1.8.1.4




More information about the Bmap-tools mailing list