Skip to content

Commit

Permalink
Drop python2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Feb 7, 2020
1 parent f5a85fd commit 2654931
Show file tree
Hide file tree
Showing 278 changed files with 1,147 additions and 3,310 deletions.
2 changes: 1 addition & 1 deletion .testr.conf
@@ -1,4 +1,4 @@
[DEFAULT]
test_command=BRZ_PLUGIN_PATH=-site:-user ./tools/testr-run.py $IDOPTION $LISTOPT
test_command=BRZ_PLUGIN_PATH=-site:-user python3 ./brz selftest --subunit2 $IDOPTION $LISTOPT
test_id_option=--load-list $IDFILE
test_list_option=--list
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -11,8 +11,6 @@ python:

matrix:
include:
- python: 2.7
env: SELFTEST_OPTIONS="--coverage"
- python: 3.7
dist: xenial

Expand Down
14 changes: 4 additions & 10 deletions Makefile
Expand Up @@ -22,9 +22,7 @@

SHELL=bash
PYTHON?=python3
PYTHON2?=python2
PYTHON3?=python3
PYTHON27=python27
BRZ_TARGET=release
PLUGIN_TARGET=plugin-release
PYTHON_BUILDFLAGS=
Expand Down Expand Up @@ -81,10 +79,7 @@ check-ci: docs extensions
# https://github.com/paramiko/paramiko/issues/713 is not a concern
# anymore -- vila 2017-05-24
set -o pipefail; \
BRZ_PLUGIN_PATH=$(BRZ_PLUGIN_PATH) $(PYTHON) -Werror -Wignore::FutureWarning -Wignore::DeprecationWarning -Wignore::ImportWarning -Wignore::ResourceWarning -O \
./brz selftest -v --parallel=fork -Oselftest.timeout=120 --subunit2 \
| subunit-filter -s --passthrough --rename "^" "python2."; \
BRZ_PLUGIN_PATH=$(BRZ_PLUGIN_PATH) $(PYTHON3) -Werror -Wignore::FutureWarning -Wignore::DeprecationWarning -Wignore::PendingDeprecationWarning -Wignore::ImportWarning -Wignore::ResourceWarning -O \
BRZ_PLUGIN_PATH=$(BRZ_PLUGIN_PATH) $(PYTHON3) -Werror -Wignore::FutureWarning -Wignore::DeprecationWarning -Wignore::PendingDeprecationWarning -Wignore::ImportWarning -Wignore::ResourceWarning -O \
./brz selftest -v --parallel=fork -Oselftest.timeout=120 --subunit2 \
| subunit-filter -s --passthrough --rename "^" "python3."

Expand Down Expand Up @@ -266,11 +261,10 @@ installer: exe copy-docs
$(PYTHON) tools/win32/run_script.py cog.py -d -o tools/win32/brz.iss tools/win32/brz.iss.cog
iscc /Q tools/win32/brz.iss

py-inst-27: docs
$(PYTHON27) setup.py bdist_wininst --install-script="brz-win32-bdist-postinstall.py" -d .

python-installer: py-inst-27
py-inst-37: docs
$(PYTHON37) setup.py bdist_wininst --install-script="brz-win32-bdist-postinstall.py" -d .

python-installer: py-inst-37

copy-docs: docs
$(PYTHON) tools/win32/ostools.py copytodir README win32_brz.exe/doc
Expand Down
22 changes: 8 additions & 14 deletions breezy/__init__.py
Expand Up @@ -129,26 +129,20 @@ def _patch_filesystem_default_encoding(new_enc):
The use of intern() may defer breakage is but is not enough, the string
object should be secure against module reloading and during teardown.
"""
is_py3 = sys.version_info > (3,)
try:
import ctypes
old_ptr = ctypes.c_void_p.in_dll(ctypes.pythonapi,
"Py_FileSystemDefaultEncoding")
if is_py3:
has_enc = ctypes.c_int.in_dll(ctypes.pythonapi,
"Py_HasFileSystemDefaultEncoding")
as_utf8 = ctypes.PYFUNCTYPE(
ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
("PyUnicode_AsUTF8", ctypes.pythonapi))
has_enc = ctypes.c_int.in_dll(ctypes.pythonapi,
"Py_HasFileSystemDefaultEncoding")
as_utf8 = ctypes.PYFUNCTYPE(
ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
("PyUnicode_AsUTF8", ctypes.pythonapi))
except (ImportError, ValueError):
return # No ctypes or not CPython implementation, do nothing
if is_py3:
new_enc = sys.intern(new_enc)
enc_ptr = as_utf8(new_enc)
has_enc.value = 1
else:
new_enc = intern(new_enc)
enc_ptr = ctypes.c_char_p(new_enc)
new_enc = sys.intern(new_enc)
enc_ptr = as_utf8(new_enc)
has_enc.value = 1
old_ptr.value = ctypes.cast(enc_ptr, ctypes.c_void_p).value
if sys.getfilesystemencoding() != new_enc:
raise RuntimeError("Failed to change the filesystem default encoding")
Expand Down
6 changes: 1 addition & 5 deletions breezy/_annotator_py.py
Expand Up @@ -33,10 +33,6 @@
osutils,
ui,
)
from .sixish import (
range,
viewitems,
)


class Annotator(object):
Expand Down Expand Up @@ -95,7 +91,7 @@ def _get_needed_keys(self, key):
vf_keys_needed.add(key)
needed_keys = set()
next_parent_map.update(self._vf.get_parent_map(parent_lookup))
for key, parent_keys in viewitems(next_parent_map):
for key, parent_keys in next_parent_map.items():
if parent_keys is None: # No graph versionedfile
parent_keys = ()
next_parent_map[key] = ()
Expand Down
16 changes: 6 additions & 10 deletions breezy/_known_graph_py.py
Expand Up @@ -27,10 +27,6 @@
errors,
revision,
)
from .sixish import (
viewitems,
viewvalues,
)


class _KnownGraphNode(object):
Expand Down Expand Up @@ -88,7 +84,7 @@ def _initialize_nodes(self, parent_map):
child_keys,
"""
nodes = self._nodes
for key, parent_keys in viewitems(parent_map):
for key, parent_keys in parent_map.items():
if key in nodes:
node = nodes[key]
node.parent_keys = parent_keys
Expand All @@ -104,11 +100,11 @@ def _initialize_nodes(self, parent_map):
parent_node.child_keys.append(key)

def _find_tails(self):
return [node for node in viewvalues(self._nodes)
return [node for node in self._nodes.values()
if not node.parent_keys]

def _find_tips(self):
return [node for node in viewvalues(self._nodes)
return [node for node in self._nodes.values()
if not node.child_keys]

def _find_gdfo(self):
Expand Down Expand Up @@ -242,7 +238,7 @@ def heads(self, keys):
seen = set()
pending = []
min_gdfo = None
for node in viewvalues(candidate_nodes):
for node in candidate_nodes.values():
if node.parent_keys:
pending.extend(node.parent_keys)
if min_gdfo is None or node.gdfo < min_gdfo:
Expand All @@ -269,7 +265,7 @@ def topo_sort(self):
All parents must occur before all children.
"""
for node in viewvalues(self._nodes):
for node in self._nodes.values():
if node.gdfo is None:
raise errors.GraphCycleError(self._nodes)
pending = self._find_tails()
Expand Down Expand Up @@ -347,7 +343,7 @@ def merge_sort(self, tip_key):
"""Compute the merge sorted graph output."""
from breezy import tsort
as_parent_map = dict((node.key, node.parent_keys)
for node in viewvalues(self._nodes)
for node in self._nodes.values()
if node.parent_keys is not None)
# We intentionally always generate revnos and never force the
# mainline_revisions
Expand Down
2 changes: 0 additions & 2 deletions breezy/_static_tuple_py.py
Expand Up @@ -76,8 +76,6 @@ def from_sequence(seq):


_valid_types = (bytes, str, StaticTuple, int, float, None.__class__, bool)
if sys.version_info < (3,):
_valid_types += (long, unicode)


# Have to set it to None first, so that __new__ can determine whether
Expand Down
20 changes: 7 additions & 13 deletions breezy/archive/tar.py
Expand Up @@ -19,6 +19,7 @@
from __future__ import absolute_import

from contextlib import closing
from io import BytesIO
import os
import sys
import tarfile
Expand All @@ -28,9 +29,6 @@
osutils,
)
from ..export import _export_iter_entries
from ..sixish import (
BytesIO,
)


def prepare_tarball_item(tree, root, final_path, tree_path, entry, force_mtime=None):
Expand Down Expand Up @@ -185,16 +183,12 @@ def tar_lzma_generator(tree, dest, root, subdir, force_mtime=None,
except ImportError as e:
raise errors.DependencyNotPresent('lzma', e)

if sys.version_info[0] == 2:
compressor = lzma.LZMACompressor(
options={"format": compression_format})
else:
compressor = lzma.LZMACompressor(
format={
'xz': lzma.FORMAT_XZ,
'raw': lzma.FORMAT_RAW,
'alone': lzma.FORMAT_ALONE,
}[compression_format])
compressor = lzma.LZMACompressor(
format={
'xz': lzma.FORMAT_XZ,
'raw': lzma.FORMAT_RAW,
'alone': lzma.FORMAT_ALONE,
}[compression_format])

for chunk in tarball_generator(
tree, root, subdir, force_mtime=force_mtime):
Expand Down
7 changes: 0 additions & 7 deletions breezy/bedding.py
Expand Up @@ -33,9 +33,6 @@
from . import (
errors,
)
from .sixish import (
PY3,
)


def ensure_config_dir_exists(path=None):
Expand Down Expand Up @@ -213,13 +210,9 @@ def _get_default_mail_domain(mailname_file='/etc/mailname'):
def default_email():
v = os.environ.get('BRZ_EMAIL')
if v:
if not PY3:
v = v.decode(osutils.get_user_encoding())
return v
v = os.environ.get('EMAIL')
if v:
if not PY3:
v = v.decode(osutils.get_user_encoding())
return v
name, email = _auto_user_id()
if name and email:
Expand Down
5 changes: 1 addition & 4 deletions breezy/bisect.py
Expand Up @@ -24,9 +24,6 @@
from .commands import Command
from .errors import BzrCommandError
from .option import Option
from .sixish import (
text_type,
)
from .trace import note

BISECT_INFO_PATH = "bisect"
Expand Down Expand Up @@ -314,7 +311,7 @@ class cmd_bisect(Command):

takes_args = ['subcommand', 'args*']
takes_options = [Option('output', short_name='o',
help='Write log to this file.', type=text_type),
help='Write log to this file.', type=str),
'revision', 'directory']

def _check(self, controldir):
Expand Down
14 changes: 5 additions & 9 deletions breezy/branch.py
Expand Up @@ -18,9 +18,9 @@

from .lazy_import import lazy_import
lazy_import(globals(), """
import contextlib
import itertools
from breezy import (
cleanup,
config as _mod_config,
debug,
memorytree,
Expand All @@ -47,10 +47,6 @@
from .hooks import Hooks
from .inter import InterObject
from .lock import LogicalLockResult
from .sixish import (
text_type,
viewitems,
)
from .trace import mutter, mutter_callsite, note, is_quiet, warning


Expand Down Expand Up @@ -371,7 +367,7 @@ def _do_dotted_revno_to_revision_id(self, revno):
raise errors.GhostRevisionsHaveNoRevno(revno[0], e.revision_id)
revision_id_to_revno = self.get_revision_id_to_revno_map()
revision_ids = [revision_id for revision_id, this_revno
in viewitems(revision_id_to_revno)
in revision_id_to_revno.items()
if revno == this_revno]
if len(revision_ids) == 1:
return revision_ids[0]
Expand Down Expand Up @@ -779,7 +775,7 @@ def set_parent(self, url):
# FIXUP this and get_parent in a future branch format bump:
# read and rewrite the file. RBC 20060125
if url is not None:
if isinstance(url, text_type):
if isinstance(url, str):
try:
url.encode('ascii')
except UnicodeEncodeError:
Expand Down Expand Up @@ -2213,7 +2209,7 @@ def pull(self, overwrite=False, stop_revision=None,
is being called because it's the master of the primary branch,
so it should not run its hooks.
"""
with cleanup.ExitStack() as exit_stack:
with contextlib.ExitStack() as exit_stack:
exit_stack.enter_context(self.target.lock_write())
bound_location = self.target.get_bound_location()
if local and not bound_location:
Expand Down Expand Up @@ -2392,7 +2388,7 @@ def update_references(self):
old_base = self.source.base
new_base = self.target.base
target_reference_dict = self.target._get_all_reference_info()
for tree_path, (branch_location, file_id) in viewitems(reference_dict):
for tree_path, (branch_location, file_id) in reference_dict.items():
try:
branch_location = urlutils.rebase_url(branch_location,
old_base, new_base)
Expand Down
9 changes: 3 additions & 6 deletions breezy/branchbuilder.py
Expand Up @@ -24,9 +24,6 @@
errors,
revision,
)
from .sixish import (
viewitems,
)


class BranchBuilder(object):
Expand All @@ -48,11 +45,11 @@ class BranchBuilder(object):
... ('add', ('', b'root-id', 'directory', '')),
... ('add', ('filename', b'f-id', 'file', b'content\n'))],
... revision_id=b'rev-id')
'rev-id'
b'rev-id'
>>> builder.build_snapshot([b'rev-id'],
... [('modify', ('filename', b'new-content\n'))],
... revision_id=b'rev2-id')
'rev2-id'
b'rev2-id'
>>> builder.finish_series()
>>> branch = builder.get_branch()
Expand Down Expand Up @@ -275,7 +272,7 @@ def _flush_pending(self, tree, pending):
tree.unversion(pending.to_unversion_paths)
tree.add(pending.to_add_files, pending.to_add_file_ids,
pending.to_add_kinds)
for path, content in viewitems(pending.new_contents):
for path, content in pending.new_contents.items():
tree.put_file_bytes_non_atomic(path, content)

def get_branch(self):
Expand Down

0 comments on commit 2654931

Please sign in to comment.