2
version_info = tuple(int(n) for n in __version__.split('.'))
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Aaron Bentley
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
def _format_version_tuple(version_info):
20
"""Turn a version number 2, 3 or 5-tuple into a short string.
22
This format matches <http://docs.python.org/dist/meta-data.html>
23
and the typical presentation used in Python output.
25
This also checks that the version is reasonable: the sub-release must be
26
zero for final releases.
28
>>> print _format_version_tuple((1, 0, 0, 'final', 0))
30
>>> print _format_version_tuple((1, 2, 0, 'dev', 0))
32
>>> print bzrlib._format_version_tuple((1, 2, 0, 'dev', 1))
34
>>> print _format_version_tuple((1, 1, 1, 'candidate', 2))
36
>>> print bzrlib._format_version_tuple((2, 1, 0, 'beta', 1))
38
>>> print _format_version_tuple((1, 4, 0))
40
>>> print _format_version_tuple((1, 4))
42
>>> print bzrlib._format_version_tuple((2, 1, 0, 'final', 1))
43
Traceback (most recent call last):
45
ValueError: version_info (2, 1, 0, 'final', 1) not valid
46
>>> print _format_version_tuple((1, 4, 0, 'wibble', 0))
47
Traceback (most recent call last):
49
ValueError: version_info (1, 4, 0, 'wibble', 0) not valid
51
if len(version_info) == 2:
52
main_version = '%d.%d' % version_info[:2]
54
main_version = '%d.%d.%d' % version_info[:3]
55
if len(version_info) <= 3:
58
release_type = version_info[3]
61
# check they're consistent
62
if release_type == 'final' and sub == 0:
64
elif release_type == 'dev' and sub == 0:
66
elif release_type == 'dev':
67
sub_string = 'dev' + str(sub)
68
elif release_type in ('alpha', 'beta'):
69
sub_string = release_type[0] + str(sub)
70
elif release_type == 'candidate':
71
sub_string = 'rc' + str(sub)
73
raise ValueError("version_info %r not valid" % (version_info,))
75
return main_version + sub_string
78
version_info = (2, 4, 0)
79
__version__ = _format_version_tuple(version_info)