Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Nov 7, 2023
1 parent 1ae3afb commit 70b54e9
Show file tree
Hide file tree
Showing 988 changed files with 125,600 additions and 99,558 deletions.
44 changes: 0 additions & 44 deletions .flake8

This file was deleted.

25 changes: 13 additions & 12 deletions apport/source_brz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

from apport.hookutils import * # noqa: F403

brz_log = os.path.expanduser('~/.brz.log')
dot_brz = os.path.expanduser('~/.config/breezy')
brz_log = os.path.expanduser("~/.brz.log")
dot_brz = os.path.expanduser("~/.config/breezy")


def _add_log_tail(report):
# may have already been added in-process
if 'BrzLogTail' in report:
if "BrzLogTail" in report:
return

with open(brz_log) as f:
Expand All @@ -23,33 +24,33 @@ def _add_log_tail(report):
brz_log_tail = []
blanks = 0
for line in brz_log_lines:
if line == '\n':
if line == "\n":
blanks += 1
brz_log_tail.append(line)
if blanks >= 2:
break

brz_log_tail.reverse()
report['BrzLogTail'] = ''.join(brz_log_tail)
report["BrzLogTail"] = "".join(brz_log_tail)


def add_info(report):
_add_log_tail(report)
if 'BrzPlugins' not in report:
if "BrzPlugins" not in report:
# may already be present in-process
report['BrzPlugins'] = command_output(['brz', 'plugins', '-v'])
report["BrzPlugins"] = command_output(["brz", "plugins", "-v"])

# by default assume brz crashes are upstream bugs; this relies on
# having a brz entry under /etc/apport/crashdb.conf.d/
report['CrashDB'] = 'brz'
report["CrashDB"] = "brz"

# these may contain some sensitive info (smtp_passwords)
# TODO: strip that out and attach the rest

#attach_file_if_exists(report,
# os.path.join(dot_brz, 'breezy.conf', 'BrzConfig')
#attach_file_if_exists(report,
# os.path.join(dot_brz, 'locations.conf', 'BrzLocations')
# attach_file_if_exists(report,
# os.path.join(dot_brz, 'breezy.conf', 'BrzConfig')
# attach_file_if_exists(report,
# os.path.join(dot_brz, 'locations.conf', 'BrzLocations')


# vim: expandtab shiftwidth=4
57 changes: 29 additions & 28 deletions breezy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
import sys

__copyright__ = (
"Copyright 2005-2012 Canonical Ltd.\n"
"Copyright 2017-2023 Breezy developers"
"Copyright 2005-2012 Canonical Ltd.\n" "Copyright 2017-2023 Breezy developers"
)

# same format as sys.version_info: "A tuple containing the five components of
Expand All @@ -50,7 +49,7 @@
# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a
# releaselevel of 'dev' for unreleased under-development code.

version_info = (3, 4, 0, 'dev', 0)
version_info = (3, 4, 0, "dev", 0)


def _format_version_tuple(version_info):
Expand Down Expand Up @@ -82,38 +81,38 @@ def _format_version_tuple(version_info):
1.4.0.wibble.0
"""
if len(version_info) == 2:
main_version = '%d.%d' % version_info[:2]
main_version = "%d.%d" % version_info[:2]
else:
main_version = '%d.%d.%d' % version_info[:3]
main_version = "%d.%d.%d" % version_info[:3]
if len(version_info) <= 3:
return main_version

release_type = version_info[3]
sub = version_info[4]

if release_type == 'final' and sub == 0:
sub_string = ''
elif release_type == 'final':
sub_string = '.' + str(sub)
elif release_type == 'dev' and sub == 0:
sub_string = '.dev'
elif release_type == 'dev':
sub_string = '.dev' + str(sub)
elif release_type in ('alpha', 'beta'):
if release_type == "final" and sub == 0:
sub_string = ""
elif release_type == "final":
sub_string = "." + str(sub)
elif release_type == "dev" and sub == 0:
sub_string = ".dev"
elif release_type == "dev":
sub_string = ".dev" + str(sub)
elif release_type in ("alpha", "beta"):
if version_info[2] == 0:
main_version = '%d.%d' % version_info[:2]
sub_string = '.' + release_type[0] + str(sub)
elif release_type == 'candidate':
sub_string = '.rc' + str(sub)
main_version = "%d.%d" % version_info[:2]
sub_string = "." + release_type[0] + str(sub)
elif release_type == "candidate":
sub_string = ".rc" + str(sub)
else:
return '.'.join(map(str, version_info))
return ".".join(map(str, version_info))

return main_version + sub_string


__version__ = _format_version_tuple(version_info)
version_string = __version__
_core_version_string = '.'.join(map(str, version_info[:3]))
_core_version_string = ".".join(map(str, version_info[:3]))


def _patch_filesystem_default_encoding(new_enc):
Expand All @@ -129,15 +128,14 @@ def _patch_filesystem_default_encoding(new_enc):
"""
try:
import ctypes
pythonapi = getattr(ctypes, 'pythonapi', None)

pythonapi = getattr(ctypes, "pythonapi", None)
if pythonapi is not None:
old_ptr = ctypes.c_void_p.in_dll(pythonapi,
"Py_FileSystemDefaultEncoding")
has_enc = ctypes.c_int.in_dll(pythonapi,
"Py_HasFileSystemDefaultEncoding")
old_ptr = ctypes.c_void_p.in_dll(pythonapi, "Py_FileSystemDefaultEncoding")
has_enc = ctypes.c_int.in_dll(pythonapi, "Py_HasFileSystemDefaultEncoding")
as_utf8 = ctypes.PYFUNCTYPE(
ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
("PyUnicode_AsUTF8", pythonapi))
ctypes.POINTER(ctypes.c_char), ctypes.py_object
)(("PyUnicode_AsUTF8", pythonapi))
except (ImportError, ValueError):
return # No ctypes or not CPython implementation, do nothing
new_enc = sys.intern(new_enc)
Expand All @@ -154,7 +152,7 @@ def _patch_filesystem_default_encoding(new_enc):
# just ensure a usable locale is set via the $LANG variable on posix systems.
_fs_enc = sys.getfilesystemencoding()
if getattr(sys, "_brz_default_fs_enc", None) is not None:
if (_fs_enc is None or codecs.lookup(_fs_enc).name == "ascii"):
if _fs_enc is None or codecs.lookup(_fs_enc).name == "ascii":
_fs_enc = _patch_filesystem_default_encoding(sys._brz_default_fs_enc) # type: ignore
if _fs_enc is None:
_fs_enc = "ascii"
Expand Down Expand Up @@ -202,8 +200,10 @@ def initialize(setup_ui=True, stdin=None, stdout=None, stderr=None):
BzrLibraryState directly.
"""
from breezy import library_state, trace

if setup_ui:
import breezy.ui

stdin = stdin or sys.stdin
stdout = stdout or sys.stdout
stderr = stderr or sys.stderr
Expand All @@ -225,4 +225,5 @@ def get_global_state():

def test_suite():
import tests

return tests.test_suite()
20 changes: 12 additions & 8 deletions breezy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,26 @@
import sys

profiling = False
if '--profile-imports' in sys.argv:
if "--profile-imports" in sys.argv:
import profile_imports

profile_imports.install()
profiling = True


if os.name == "posix":
import locale

try:
locale.setlocale(locale.LC_ALL, '')
locale.setlocale(locale.LC_ALL, "")
except locale.Error as e:
sys.stderr.write(
'brz: warning: %s\n'
' bzr could not set the application locale.\n'
' Although this should be no problem for bzr itself, it might\n'
' cause problems with some plugins. To investigate the issue,\n'
' look at the output of the locale(1p) tool.\n' % e)
"brz: warning: %s\n"
" bzr could not set the application locale.\n"
" Although this should be no problem for bzr itself, it might\n"
" cause problems with some plugins. To investigate the issue,\n"
" look at the output of the locale(1p) tool.\n" % e
)
# Use better default than ascii with posix filesystems that deal in bytes
# natively even when the C locale or no locale at all is given. Note that
# we need an immortal string for the hack, hence the lack of a hyphen.
Expand All @@ -46,6 +49,7 @@

def main():
import breezy.breakin

breezy.breakin.hook_debugger_to_signal()

import breezy.commands
Expand All @@ -69,5 +73,5 @@ def main():
os._exit(exit_val)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading

0 comments on commit 70b54e9

Please sign in to comment.