← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:unsixify-breezy into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:unsixify-breezy into launchpad:master.

Commit message:
Remove six from code interacting with Breezy

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/436685

On Python 3 we know the types involved (in particular, Breezy always returns the various format strings as bytes), so we can just use `.decode`/`.encode` rather than `six.ensure_*`.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:unsixify-breezy into launchpad:master.
diff --git a/lib/lp/code/bzr.py b/lib/lp/code/bzr.py
index 8c30aed..75e7932 100644
--- a/lib/lp/code/bzr.py
+++ b/lib/lp/code/bzr.py
@@ -20,7 +20,6 @@ __all__ = [
 # line below this comment.
 import lp.codehosting  # noqa: F401  # isort: split
 
-import six
 from breezy.branch import UnstackableBranchFormat
 from breezy.bzr.branch import (
     BranchReferenceFormat,
@@ -65,10 +64,10 @@ from lazr.enum import DBEnumeratedType, DBItem
 def _format_enum(num, format, format_string=None, description=None):
     instance = format()
     if format_string is None:
-        format_string = instance.get_format_string()
+        format_string = instance.get_format_string().decode()
     if description is None:
         description = instance.get_format_description()
-    return DBItem(num, six.ensure_str(format_string), description)
+    return DBItem(num, format_string, description)
 
 
 class BazaarFormatEnum(DBEnumeratedType):
@@ -313,12 +312,10 @@ def get_branch_formats(bzr_branch):
 
     :returns: tuple of (ControlFormat, BranchFormat, RepositoryFormat)
     """
-    control_string = six.ensure_str(
-        bzr_branch.controldir._format.get_format_string()
-    )
-    branch_string = six.ensure_str(bzr_branch._format.get_format_string())
-    repository_string = six.ensure_str(
-        bzr_branch.repository._format.get_format_string()
+    control_string = bzr_branch.controldir._format.get_format_string().decode()
+    branch_string = bzr_branch._format.get_format_string().decode()
+    repository_string = (
+        bzr_branch.repository._format.get_format_string().decode()
     )
     return (
         ControlFormat.get_enum(control_string),
diff --git a/lib/lp/code/interfaces/tests/test_branch.py b/lib/lp/code/interfaces/tests/test_branch.py
index 128d3d1..999a069 100644
--- a/lib/lp/code/interfaces/tests/test_branch.py
+++ b/lib/lp/code/interfaces/tests/test_branch.py
@@ -3,7 +3,6 @@
 
 """Tests of the branch interface."""
 
-import six
 from breezy.branch import format_registry as branch_format_registry
 from breezy.bzr import BzrProber
 from breezy.repository import format_registry as repo_format_registry
@@ -34,7 +33,7 @@ class TestFormatSupport(TestCase):
         """Ensure the Breezy format marker list is a subset of Launchpad."""
         breezy_format_strings = set(breezy_formats)
         launchpad_format_strings = {
-            six.ensure_binary(format.title) for format in launchpad_enum.items
+            format.title.encode() for format in launchpad_enum.items
         }
         self.assertEqual(
             set(), breezy_format_strings.difference(launchpad_format_strings)
diff --git a/lib/lp/code/model/branchjob.py b/lib/lp/code/model/branchjob.py
index 291c1e7..e593b2b 100644
--- a/lib/lp/code/model/branchjob.py
+++ b/lib/lp/code/model/branchjob.py
@@ -20,7 +20,6 @@ import shutil
 import tempfile
 from typing import Optional
 
-import six
 import transaction
 from breezy.branch import Branch as BzrBranch
 from breezy.diff import show_diff_trees
@@ -615,7 +614,7 @@ class RevisionsAddedJob(BranchJobDerived):
         show_diff_trees(
             from_tree, to_tree, diff_content, old_label="", new_label=""
         )
-        return six.ensure_text(diff_content.getvalue(), errors="replace")
+        return diff_content.getvalue().decode(errors="replace")
 
     def getMailerForRevision(self, revision, revno, generate_diff):
         """Return a BranchMailer for a revision.
diff --git a/lib/lp/code/xmlrpc/tests/test_codehosting.py b/lib/lp/code/xmlrpc/tests/test_codehosting.py
index b25fc57..c604c36 100644
--- a/lib/lp/code/xmlrpc/tests/test_codehosting.py
+++ b/lib/lp/code/xmlrpc/tests/test_codehosting.py
@@ -8,7 +8,6 @@ import os
 import threading
 
 import pytz
-import six
 import transaction
 from breezy import controldir
 from breezy.urlutils import escape
@@ -708,12 +707,12 @@ class CodehostingTest(WithScenarios, TestCaseWithFactory):
 
     def getFormatStringsForFormatName(self, format_name):
         default_format = controldir.format_registry.get(format_name)()
-        control_string = six.ensure_str(default_format.get_format_string())
-        branch_string = six.ensure_str(
-            default_format.get_branch_format().get_format_string()
+        control_string = default_format.get_format_string().decode()
+        branch_string = (
+            default_format.get_branch_format().get_format_string().decode()
         )
-        repository_string = six.ensure_str(
-            default_format.repository_format.get_format_string()
+        repository_string = (
+            default_format.repository_format.get_format_string().decode()
         )
         return (control_string, branch_string, repository_string)
 
diff --git a/lib/lp/codehosting/bzrutils.py b/lib/lp/codehosting/bzrutils.py
index 43e7abb..c3e1d32 100644
--- a/lib/lp/codehosting/bzrutils.py
+++ b/lib/lp/codehosting/bzrutils.py
@@ -27,7 +27,6 @@ import os
 import sys
 from contextlib import contextmanager
 
-import six
 from breezy import config, trace
 from breezy.branch import UnstackableBranchFormat
 from breezy.bzr.remote import RemoteBranch, RemoteBzrDir, RemoteRepository
@@ -316,13 +315,13 @@ def get_branch_info(branch):
     # XXX: Aaron Bentley 2008-06-13
     # Bazaar does not provide a public API for learning about
     # format markers.  Fix this in Bazaar, then here.
-    info["control_string"] = six.ensure_str(
-        branch.controldir._format.get_format_string()
-    )
-    info["branch_string"] = six.ensure_str(branch._format.get_format_string())
-    info["repository_string"] = six.ensure_str(
-        branch.repository._format.get_format_string()
-    )
+    info[
+        "control_string"
+    ] = branch.controldir._format.get_format_string().decode()
+    info["branch_string"] = branch._format.get_format_string().decode()
+    info[
+        "repository_string"
+    ] = branch.repository._format.get_format_string().decode()
     return info
 
 
diff --git a/lib/lp/codehosting/puller/tests/test_scheduler.py b/lib/lp/codehosting/puller/tests/test_scheduler.py
index ee089d0..b3eb82e 100644
--- a/lib/lp/codehosting/puller/tests/test_scheduler.py
+++ b/lib/lp/codehosting/puller/tests/test_scheduler.py
@@ -684,12 +684,12 @@ class TestPullerMasterIntegration(PullerBranchTestCase):
 
         def check_authserver_called(ignored):
             default_format = format_registry.get("default")()
-            control_string = six.ensure_str(default_format.get_format_string())
-            branch_string = six.ensure_str(
+            control_string = default_format.get_format_string().decode()
+            branch_string = (
                 default_format.get_branch_format().get_format_string()
-            )
-            repository_string = six.ensure_str(
-                default_format.repository_format.get_format_string()
+            ).decode()
+            repository_string = (
+                default_format.repository_format.get_format_string().decode()
             )
             self.assertEqual(
                 [
diff --git a/lib/lp/codehosting/puller/worker.py b/lib/lp/codehosting/puller/worker.py
index 662d6dd..465fca7 100644
--- a/lib/lp/codehosting/puller/worker.py
+++ b/lib/lp/codehosting/puller/worker.py
@@ -484,11 +484,15 @@ class PullerWorker:
             # XXX: Aaron Bentley 2008-06-13
             # Bazaar does not provide a public API for learning about
             # format markers.  Fix this in Bazaar, then here.
-            control_string = dest_branch.controldir._format.get_format_string()
+            control_string = (
+                dest_branch.controldir._format.get_format_string().decode()
+            )
             if dest_branch._format.__class__ is BzrBranchFormat4:
                 branch_string = BranchFormat.BZR_BRANCH_4.title
             else:
-                branch_string = dest_branch._format.get_format_string()
+                branch_string = (
+                    dest_branch._format.get_format_string().decode()
+                )
             repository_format = dest_branch.repository._format
             if repository_format.__class__ is RepositoryFormat6:
                 repository_string = RepositoryFormat.BZR_REPOSITORY_6.title
@@ -497,14 +501,16 @@ class PullerWorker:
             elif repository_format.__class__ is RepositoryFormat4:
                 repository_string = RepositoryFormat.BZR_REPOSITORY_4.title
             else:
-                repository_string = repository_format.get_format_string()
+                repository_string = (
+                    repository_format.get_format_string().decode()
+                )
             self.protocol.branchChanged(
                 stacked_on_url,
                 revid_before,
                 revid_after,
-                six.ensure_str(control_string),
-                six.ensure_str(branch_string),
-                six.ensure_str(repository_string),
+                control_string,
+                branch_string,
+                repository_string,
             )
 
     def __eq__(self, other):
diff --git a/lib/lp/codehosting/vfs/tests/test_branchfs.py b/lib/lp/codehosting/vfs/tests/test_branchfs.py
index 5d9c713..bc9b414 100644
--- a/lib/lp/codehosting/vfs/tests/test_branchfs.py
+++ b/lib/lp/codehosting/vfs/tests/test_branchfs.py
@@ -9,7 +9,6 @@ import re
 import sys
 import xmlrpc.client
 
-import six
 from breezy import errors
 from breezy.bzr.bzrdir import BzrDir
 from breezy.controldir import format_registry
@@ -268,9 +267,7 @@ class TestLaunchpadServer(MixinBaseLaunchpadServerTests, BzrTestCase):
             % (branch.owner.name, branch.product.name)
         )
         self.assertEqual(
-            six.ensure_binary(
-                "default_stack_on = %s\n" % branch_id_alias(branch)
-            ),
+            ("default_stack_on = %s\n" % branch_id_alias(branch)).encode(),
             transport.get_bytes(path),
         )
 
@@ -1087,12 +1084,10 @@ class TestBranchChangedNotification(TestCaseWithTransport):
 
     def assertFormatStringsPassed(self, branch):
         self.assertEqual(1, len(self._branch_changed_log))
-        control_string = six.ensure_str(
-            branch.controldir._format.get_format_string()
-        )
-        branch_string = six.ensure_str(branch._format.get_format_string())
-        repository_string = six.ensure_str(
-            branch.repository._format.get_format_string()
+        control_string = branch.controldir._format.get_format_string().decode()
+        branch_string = branch._format.get_format_string().decode()
+        repository_string = (
+            branch.repository._format.get_format_string().decode()
         )
         self.assertEqual(
             (control_string, branch_string, repository_string),