1
# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Library API versioning support.
19
Added in breezy 0.18 this allows export of compatibility information about
20
breezy. Please see doc/developers/api-versioning.txt for design details and
24
from __future__ import absolute_import
27
from .errors import IncompatibleAPI
30
def get_current_api_version():
31
"""Return the API version tuple for breezy.
35
return breezy.version_info[0:3]
38
def require_api(wanted_api):
39
"""Check if breezy supports the api version wanted_api.
41
:param wanted_api: The API version for which support is required.
43
:raises IncompatibleAPI: When the wanted_api is not supported by
48
current = get_current_api_version()
49
if wanted_api != current:
50
raise IncompatibleAPI(breezy, wanted_api, current)
53
def require_any_api(wanted_api_list):
54
"""Check if breezy supports the api version wanted_api.
56
:param wanted_api: A list of API versions, any of which being available is
59
:raises IncompatibleAPI: When the wanted_api is not supported by
64
current = get_current_api_version()
65
if not current in wanted_api_list:
66
raise IncompatibleAPI(breezy, wanted_api_list[-1], current)