summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorJonathan Lange <jml@canonical.com>2011-12-08 12:41:20 +0000
committerJonathan Lange <jml@canonical.com>2011-12-08 12:41:20 +0000
commit8343524a5ee5f459e87bc15c85558a33a867f35a (patch)
tree9852585bef947653cd7d977a683c8e8b2e2d1219 /setup.py
parent83e6aa52f7a05690e151771d80a971e5d8c9cf59 (diff)
parentdac8ab1c5452712bc0fe5d389bdfa61b7400aa49 (diff)
downloadsubunit-git-8343524a5ee5f459e87bc15c85558a33a867f35a.tar.gz
Make version guessing more reliable (mgz)
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/setup.py b/setup.py
index bb51a24..a78eb99 100755
--- a/setup.py
+++ b/setup.py
@@ -13,19 +13,22 @@ else:
]
}
-try:
+
+def _get_version_from_file(filename, start_of_line, split_marker):
+ """Extract version from file, giving last matching value or None"""
+ try:
+ return [x for x in open(filename)
+ if x.startswith(start_of_line)][-1].split(split_marker)[1].strip()
+ except (IOError, IndexError):
+ return None
+
+
+VERSION = (
# Assume we are in a distribution, which has PKG-INFO
- version_lines = [x for x in open('PKG-INFO').readlines()
- if x.startswith('Version:')]
- version_line = version_lines and version_lines[-1] or 'VERSION = 0.0'
- VERSION = version_line.split(':')[1].strip()
-
-except IOError:
+ _get_version_from_file('PKG-INFO', 'Version:', ':')
# Must be a development checkout, so use the Makefile
- version_lines = [x for x in open('Makefile').readlines()
- if x.startswith('VERSION')]
- version_line = version_lines and version_lines[-1] or 'VERSION = 0.0'
- VERSION = version_line.split('=')[1].strip()
+ or _get_version_from_file('Makefile', 'VERSION', '=')
+ or "0.0")
setup(