~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/api.py

  • Committer: Robert Collins
  • Date: 2007-06-26 08:52:20 UTC
  • mto: This revision was merged to the branch mainline in revision 2554.
  • Revision ID: robertc@robertcollins.net-20070626085220-iovhwfjflk8vffbh
Add require_api API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Library API versioning support."""
 
17
"""Library API versioning support.
 
18
 
 
19
Added in bzrlib 0.18 this allows export of compatibility information about
 
20
bzrlib. Please see doc/developers/api-versioning.txt for design details and
 
21
examples.
 
22
"""
18
23
 
19
24
import bzrlib
20
25
from bzrlib.lazy_import import lazy_import
31
36
        there is a version_info attribute, its first three elements are used.
32
37
        Finally if there was no version_info attribute, the current api version
33
38
        of bzrlib itself is used.
 
39
 
 
40
    Added in bzrlib 0.18.
34
41
    """
35
42
    try:
36
43
        return object_with_api.api_current_version
47
54
    :param object_with_api: An object to look for an API version on. If the
48
55
        object has a api_minimum_version attribute, that is used. Otherwise the
49
56
        minimum api version of bzrlib itself is used.
 
57
 
 
58
    Added in bzrlib 0.18.
50
59
    """
51
60
    try:
52
61
        return object_with_api.api_minimum_version
53
62
    except AttributeError:
54
63
        return get_minimum_api_version(bzrlib)
 
64
 
 
65
 
 
66
def require_api(object_with_api, wanted_api):
 
67
    """Check if object_with_api supports the api version wanted_api.
 
68
 
 
69
    :param object_with_api: An object which exports an API minimum and current
 
70
        version. See get_minimum_api_version and get_current_api_version for
 
71
        details.
 
72
    :param wanted_api: The API version for which support is required.
 
73
    :return None:
 
74
    :raises IncompatibleAPI: When the wanted_api is not supported by
 
75
        object_with_api.
 
76
 
 
77
    Added in bzrlib 0.18.
 
78
    """
 
79
    current = get_current_api_version(object_with_api)
 
80
    minimum = get_minimum_api_version(object_with_api)
 
81
    if wanted_api < minimum or wanted_api > current:
 
82
        raise IncompatibleAPI(object_with_api, wanted_api, minimum, current)