/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/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""All of bzr.
18
18
 
19
 
Developer documentation is available at
20
 
https://www.breezy-vcs.org/developers/.
 
19
Developer documentation for Bazaar is available at
 
20
http://doc.bazaar.canonical.com/bzr.dev/developers/,
 
21
it should mostly also apply to Breezy.
21
22
 
22
23
Some particularly interesting things in breezy are:
23
24
 
29
30
We hope you enjoy this library.
30
31
"""
31
32
 
 
33
from __future__ import absolute_import
 
34
 
32
35
import time
33
36
 
34
37
# Keep track of when breezy was first imported, so that we can give rough
39
42
import sys
40
43
 
41
44
 
42
 
__copyright__ = (
43
 
    "Copyright 2005-2012 Canonical Ltd.\n"
44
 
    "Copyright 2017-2020 Breezy developers"
45
 
)
 
45
IGNORE_FILENAME = ".bzrignore"
 
46
 
 
47
 
 
48
__copyright__ = "Copyright 2005-2012 Canonical Ltd."
46
49
 
47
50
# same format as sys.version_info: "A tuple containing the five components of
48
51
# the version number: major, minor, micro, releaselevel, and serial. All
51
54
# Python version 2.0 is (2, 0, 0, 'final', 0)."  Additionally we use a
52
55
# releaselevel of 'dev' for unreleased under-development code.
53
56
 
54
 
version_info = (3, 2, 0, 'dev', 0)
55
 
 
 
57
version_info = (3, 0, 0, 'dev', 1)
56
58
 
57
59
def _format_version_tuple(version_info):
58
60
    """Turn a version number 2, 3 or 5-tuple into a short string.
63
65
    This also checks that the version is reasonable: the sub-release must be
64
66
    zero for final releases.
65
67
 
66
 
    >>> print(_format_version_tuple((1, 0, 0, 'final', 0)))
 
68
    >>> print _format_version_tuple((1, 0, 0, 'final', 0))
67
69
    1.0.0
68
 
    >>> print(_format_version_tuple((1, 2, 0, 'dev', 0)))
 
70
    >>> print _format_version_tuple((1, 2, 0, 'dev', 0))
69
71
    1.2.0dev
70
 
    >>> print(_format_version_tuple((1, 2, 0, 'dev', 1)))
 
72
    >>> print _format_version_tuple((1, 2, 0, 'dev', 1))
71
73
    1.2.0dev1
72
 
    >>> print(_format_version_tuple((1, 1, 1, 'candidate', 2)))
 
74
    >>> print _format_version_tuple((1, 1, 1, 'candidate', 2))
73
75
    1.1.1rc2
74
 
    >>> print(_format_version_tuple((2, 1, 0, 'beta', 1)))
 
76
    >>> print _format_version_tuple((2, 1, 0, 'beta', 1))
75
77
    2.1b1
76
 
    >>> print(_format_version_tuple((1, 4, 0)))
 
78
    >>> print _format_version_tuple((1, 4, 0))
77
79
    1.4.0
78
 
    >>> print(_format_version_tuple((1, 4)))
 
80
    >>> print _format_version_tuple((1, 4))
79
81
    1.4
80
 
    >>> print(_format_version_tuple((2, 1, 0, 'final', 42)))
 
82
    >>> print _format_version_tuple((2, 1, 0, 'final', 42))
81
83
    2.1.0.42
82
 
    >>> print(_format_version_tuple((1, 4, 0, 'wibble', 0)))
 
84
    >>> print _format_version_tuple((1, 4, 0, 'wibble', 0))
83
85
    1.4.0.wibble.0
84
86
    """
85
87
    if len(version_info) == 2:
112
114
    return main_version + sub_string
113
115
 
114
116
 
 
117
# lazy_regex import must be done after _format_version_tuple definition
 
118
# to avoid "no attribute '_format_version_tuple'" error when using
 
119
# deprecated_function in the lazy_regex module.
 
120
if getattr(sys, '_brz_lazy_regex', False):
 
121
    # The 'brz' executable sets _brz_lazy_regex.  We install the lazy regex
 
122
    # hack as soon as possible so that as much of the standard library can
 
123
    # benefit, including the 'string' module.
 
124
    del sys._brz_lazy_regex
 
125
    import breezy.lazy_regex
 
126
    breezy.lazy_regex.install_lazy_compile()
 
127
 
 
128
 
115
129
__version__ = _format_version_tuple(version_info)
116
130
version_string = __version__
117
131
 
118
132
 
119
133
def _patch_filesystem_default_encoding(new_enc):
120
134
    """Change the Python process global encoding for filesystem names
121
 
 
 
135
    
122
136
    The effect is to change how open() and other builtin functions handle
123
137
    unicode filenames on posix systems. This should only be done near startup.
124
138
 
127
141
    The use of intern() may defer breakage is but is not enough, the string
128
142
    object should be secure against module reloading and during teardown.
129
143
    """
 
144
    is_py3 = sys.version_info > (3,)
130
145
    try:
131
146
        import ctypes
132
 
        pythonapi = getattr(ctypes, 'pythonapi', None)
133
 
        if pythonapi is not None:
134
 
            old_ptr = ctypes.c_void_p.in_dll(pythonapi,
135
 
                                             "Py_FileSystemDefaultEncoding")
136
 
            has_enc = ctypes.c_int.in_dll(pythonapi,
137
 
                                          "Py_HasFileSystemDefaultEncoding")
 
147
        old_ptr = ctypes.c_void_p.in_dll(ctypes.pythonapi,
 
148
            "Py_FileSystemDefaultEncoding")
 
149
        if is_py3:
 
150
            has_enc = ctypes.c_int.in_dll(ctypes.pythonapi,
 
151
                "Py_HasFileSystemDefaultEncoding")
138
152
            as_utf8 = ctypes.PYFUNCTYPE(
139
153
                ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
140
 
                    ("PyUnicode_AsUTF8", pythonapi))
 
154
                    ("PyUnicode_AsUTF8", ctypes.pythonapi))
141
155
    except (ImportError, ValueError):
142
 
        return  # No ctypes or not CPython implementation, do nothing
143
 
    new_enc = sys.intern(new_enc)
144
 
    enc_ptr = as_utf8(new_enc)
145
 
    has_enc.value = 1
 
156
        return # No ctypes or not CPython implementation, do nothing
 
157
    if is_py3:
 
158
        new_enc = sys.intern(new_enc)
 
159
        enc_ptr = as_utf8(new_enc)
 
160
        has_enc.value = 1
 
161
    else:
 
162
        new_enc = intern(new_enc)
 
163
        enc_ptr = ctypes.c_char_p(new_enc)
146
164
    old_ptr.value = ctypes.cast(enc_ptr, ctypes.c_void_p).value
147
165
    if sys.getfilesystemencoding() != new_enc:
148
166
        raise RuntimeError("Failed to change the filesystem default encoding")
174
192
# it is important to store the reference you get, rather than looking it up
175
193
# repeatedly; that way your code will behave properly in the breezy test suite
176
194
# and from programs that do use multiple library contexts.
177
 
_global_state = None
 
195
global_state = None
178
196
 
179
197
 
180
198
def initialize(setup_ui=True, stdin=None, stdout=None, stderr=None):
217
235
    return state
218
236
 
219
237
 
220
 
def get_global_state():
221
 
    if _global_state is None:
222
 
        return initialize()
223
 
    return _global_state
224
 
 
225
 
 
226
238
def test_suite():
227
239
    import tests
228
240
    return tests.test_suite()