From 33343f14fb3e449653101fc23e65b70b7f888db0 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Tue, 17 Sep 2013 17:02:39 +0300 Subject: [PATCH] setup.py: automatically detect version number 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 --- 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@linux.intel.com", - version="2.6", + version=get_version(), scripts=['bmaptool'], packages=find_packages(exclude=["test*"]), license='GPLv2', -- 2.7.4