diff options
| author | Jonathan Lange <jml@canonical.com> | 2010-10-18 14:14:01 +0100 |
|---|---|---|
| committer | Jonathan Lange <jml@canonical.com> | 2010-10-18 14:14:01 +0100 |
| commit | c5a2725d503f5bce9d51a69134a0de88420a5bf2 (patch) | |
| tree | 36b78ba34c6022024704949e61ee0e5330dc07cc /setup.py | |
| parent | 907a20490d51f6cf1609c9553622af0f845cfefa (diff) | |
| download | testtools-c5a2725d503f5bce9d51a69134a0de88420a5bf2.tar.gz | |
Get the version from PKG-INFO if it exists
Diffstat (limited to 'setup.py')
| -rwxr-xr-x | setup.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -2,6 +2,7 @@ """Distutils installer for testtools.""" from distutils.core import setup +import email import os import testtools @@ -13,12 +14,30 @@ def get_revno(): return t.branch.revno() +def get_version_from_pkg_info(): + """Get the version from PKG-INFO file if we can.""" + pkg_info_path = os.path.join(os.path.dirname(__file__), 'PKG-INFO') + try: + pkg_info_file = open(pkg_info_path, 'r') + except (IOError, OSError): + return None + try: + pkg_info = email.message_from_file(pkg_info_file) + except email.MessageError: + return None + return pkg_info.get('Version', None) + + def get_version(): + """Return the version of testtools that we are building.""" version = '.'.join( str(component) for component in testtools.__version__[0:3]) phase = testtools.__version__[3] if phase == 'final': return version + pkg_info_version = get_version_from_pkg_info() + if pkg_info_version: + return pkg_info_version revno = get_revno() if phase == 'alpha': # No idea what the next version will be |
