/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/api.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 00:21:41 UTC
  • mto: This revision was merged to the branch mainline in revision 6675.
  • Revision ID: jelmer@jelmer.uk-20170610002141-m1z5k7fs8laesa65
Fix import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Library API versioning support.
18
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
 
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
21
21
examples.
22
22
"""
23
23
 
24
 
import bzrlib
25
 
from bzrlib.lazy_import import lazy_import
26
 
lazy_import(globals(), """
27
 
from bzrlib.errors import IncompatibleAPI
28
 
""")
 
24
from __future__ import absolute_import
 
25
 
 
26
import breezy
 
27
from .errors import IncompatibleAPI
29
28
 
30
29
 
31
30
def get_current_api_version(object_with_api):
35
34
        object has a api_current_version attribute, that is used. Otherwise if
36
35
        there is a version_info attribute, its first three elements are used.
37
36
        Finally if there was no version_info attribute, the current api version
38
 
        of bzrlib itself is used.
 
37
        of breezy itself is used.
39
38
 
40
 
    Added in bzrlib 0.18.
 
39
    Added in breezy 0.18.
41
40
    """
42
41
    try:
43
42
        return object_with_api.api_current_version
45
44
        try:
46
45
            return object_with_api.version_info[0:3]
47
46
        except AttributeError:
48
 
            return get_current_api_version(bzrlib)
 
47
            return get_current_api_version(breezy)
49
48
 
50
49
 
51
50
def get_minimum_api_version(object_with_api):
53
52
 
54
53
    :param object_with_api: An object to look for an API version on. If the
55
54
        object has a api_minimum_version attribute, that is used. Otherwise the
56
 
        minimum api version of bzrlib itself is used.
 
55
        minimum api version of breezy itself is used.
57
56
 
58
 
    Added in bzrlib 0.18.
 
57
    Added in breezy 0.18.
59
58
    """
60
59
    try:
61
60
        return object_with_api.api_minimum_version
62
61
    except AttributeError:
63
 
        return get_minimum_api_version(bzrlib)
 
62
        return get_minimum_api_version(breezy)
64
63
 
65
64
 
66
65
def require_api(object_with_api, wanted_api):
74
73
    :raises IncompatibleAPI: When the wanted_api is not supported by
75
74
        object_with_api.
76
75
 
77
 
    Added in bzrlib 0.18.
 
76
    Added in breezy 0.18.
78
77
    """
79
78
    current = get_current_api_version(object_with_api)
80
79
    minimum = get_minimum_api_version(object_with_api)
94
93
    :raises IncompatibleAPI: When the wanted_api is not supported by
95
94
        object_with_api.
96
95
 
97
 
    Added in bzrlib 1.9.
 
96
    Added in breezy 1.9.
98
97
    """
99
98
    for api in wanted_api_list[:-1]:
100
99
        try: