/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""All of bzr.
18
18
 
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.
 
19
Developer documentation is available at
 
20
https://www.breezy-vcs.org/developers/.
22
21
 
23
22
Some particularly interesting things in breezy are:
24
23
 
30
29
We hope you enjoy this library.
31
30
"""
32
31
 
33
 
from __future__ import absolute_import
34
 
 
35
32
import time
36
33
 
37
34
# Keep track of when breezy was first imported, so that we can give rough
42
39
import sys
43
40
 
44
41
 
45
 
IGNORE_FILENAME = ".bzrignore"
46
 
 
47
 
 
48
 
__copyright__ = "Copyright 2005-2012 Canonical Ltd."
 
42
__copyright__ = (
 
43
    "Copyright 2005-2012 Canonical Ltd.\n"
 
44
    "Copyright 2017-2020 Breezy developers"
 
45
)
49
46
 
50
47
# same format as sys.version_info: "A tuple containing the five components of
51
48
# the version number: major, minor, micro, releaselevel, and serial. All
54
51
# Python version 2.0 is (2, 0, 0, 'final', 0)."  Additionally we use a
55
52
# releaselevel of 'dev' for unreleased under-development code.
56
53
 
57
 
version_info = (3, 0, 0, 'dev', 1)
 
54
version_info = (3, 2, 0, 'dev', 0)
 
55
 
58
56
 
59
57
def _format_version_tuple(version_info):
60
58
    """Turn a version number 2, 3 or 5-tuple into a short string.
65
63
    This also checks that the version is reasonable: the sub-release must be
66
64
    zero for final releases.
67
65
 
68
 
    >>> print _format_version_tuple((1, 0, 0, 'final', 0))
 
66
    >>> print(_format_version_tuple((1, 0, 0, 'final', 0)))
69
67
    1.0.0
70
 
    >>> print _format_version_tuple((1, 2, 0, 'dev', 0))
 
68
    >>> print(_format_version_tuple((1, 2, 0, 'dev', 0)))
71
69
    1.2.0dev
72
 
    >>> print _format_version_tuple((1, 2, 0, 'dev', 1))
 
70
    >>> print(_format_version_tuple((1, 2, 0, 'dev', 1)))
73
71
    1.2.0dev1
74
 
    >>> print _format_version_tuple((1, 1, 1, 'candidate', 2))
 
72
    >>> print(_format_version_tuple((1, 1, 1, 'candidate', 2)))
75
73
    1.1.1rc2
76
 
    >>> print _format_version_tuple((2, 1, 0, 'beta', 1))
 
74
    >>> print(_format_version_tuple((2, 1, 0, 'beta', 1)))
77
75
    2.1b1
78
 
    >>> print _format_version_tuple((1, 4, 0))
 
76
    >>> print(_format_version_tuple((1, 4, 0)))
79
77
    1.4.0
80
 
    >>> print _format_version_tuple((1, 4))
 
78
    >>> print(_format_version_tuple((1, 4)))
81
79
    1.4
82
 
    >>> print _format_version_tuple((2, 1, 0, 'final', 42))
 
80
    >>> print(_format_version_tuple((2, 1, 0, 'final', 42)))
83
81
    2.1.0.42
84
 
    >>> print _format_version_tuple((1, 4, 0, 'wibble', 0))
 
82
    >>> print(_format_version_tuple((1, 4, 0, 'wibble', 0)))
85
83
    1.4.0.wibble.0
86
84
    """
87
85
    if len(version_info) == 2:
114
112
    return main_version + sub_string
115
113
 
116
114
 
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
 
 
129
115
__version__ = _format_version_tuple(version_info)
130
116
version_string = __version__
131
117
 
132
118
 
133
119
def _patch_filesystem_default_encoding(new_enc):
134
120
    """Change the Python process global encoding for filesystem names
135
 
    
 
121
 
136
122
    The effect is to change how open() and other builtin functions handle
137
123
    unicode filenames on posix systems. This should only be done near startup.
138
124
 
141
127
    The use of intern() may defer breakage is but is not enough, the string
142
128
    object should be secure against module reloading and during teardown.
143
129
    """
144
 
    is_py3 = sys.version_info > (3,)
145
130
    try:
146
131
        import ctypes
147
132
        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")
152
 
            as_utf8 = ctypes.PYFUNCTYPE(
153
 
                ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
154
 
                    ("PyUnicode_AsUTF8", ctypes.pythonapi))
 
133
                                         "Py_FileSystemDefaultEncoding")
 
134
        has_enc = ctypes.c_int.in_dll(ctypes.pythonapi,
 
135
                                      "Py_HasFileSystemDefaultEncoding")
 
136
        as_utf8 = ctypes.PYFUNCTYPE(
 
137
            ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
 
138
                ("PyUnicode_AsUTF8", ctypes.pythonapi))
155
139
    except (ImportError, ValueError):
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)
 
140
        return  # No ctypes or not CPython implementation, do nothing
 
141
    new_enc = sys.intern(new_enc)
 
142
    enc_ptr = as_utf8(new_enc)
 
143
    has_enc.value = 1
164
144
    old_ptr.value = ctypes.cast(enc_ptr, ctypes.c_void_p).value
165
145
    if sys.getfilesystemencoding() != new_enc:
166
146
        raise RuntimeError("Failed to change the filesystem default encoding")