setup.py: automatically detect version number
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Tue, 17 Sep 2013 14:02:39 +0000 (17:02 +0300)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 19 Sep 2013 10:28:44 +0000 (13:28 +0300)
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@intel.com>
TODO
setup.py

diff --git a/TODO b/TODO
index dd622bc1085d6abc11345082c9a8ea6fb3679acf..7eacd8dbd0c76d81e41e285d9a1b1b1e65e023c1 100644 (file)
--- 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
index cc864a9b3733f25c0f52b9bc06ef0944ca89f9d4..1d38bf7622a2ba9425d3f70be6602a05b6aeeaec 100644 (file)
--- 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@linux.intel.com",
-    version="2.6",
+    version=get_version(),
     scripts=['bmaptool'],
     packages=find_packages(exclude=["test*"]),
     license='GPLv2',