/
version.py
39 lines (30 loc) · 1.08 KB
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright: 2006 Marien Zwart <marienz@gentoo.org>
# License: BSD/GPL2
"""Version information (tied to bzr)."""
import os
__version__ = '0.3.6'
_ver = None
def get_version():
"""@returns: a string describing the snakeoil version."""
global _ver
if _ver is not None:
return _ver
try:
from snakeoil.bzr_verinfo import version_info
except ImportError:
try:
from bzrlib import branch, errors
except ImportError:
ver = 'unknown (not from an sdist tarball, bzr unavailable)'
else:
try:
# Returns a (branch, relpath) tuple, ignore relpath.
b = branch.Branch.open_containing(os.path.realpath(__file__))[0]
except errors.NotBranchError:
ver = 'unknown (not from an sdist tarball, not a bzr branch)'
else:
ver = '%s:%s %s' % (b.nick, b.revno(), b.last_revision())
else:
ver = '%(branch_nick)s:%(revno)s %(revision_id)s' % version_info
_ver = 'snakeoil %s\n(bzr rev %s)' % (__version__, ver)
return _ver