diff options
author | Martin <gzlist@googlemail.com> | 2011-08-07 18:10:03 +0100 |
---|---|---|
committer | Martin <gzlist@googlemail.com> | 2011-08-07 18:10:03 +0100 |
commit | dac8ab1c5452712bc0fe5d389bdfa61b7400aa49 (patch) | |
tree | 39f738f078a5846fc15033d983cf1fc07d39159e /setup.py | |
parent | 9ce3f298dbe17b500879a32b53f440635d522b0f (diff) | |
download | subunit-git-dac8ab1c5452712bc0fe5d389bdfa61b7400aa49.tar.gz |
Make version detection in setup.py slightly more robust
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -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( |