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

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 4f3bb6b277c6abd81d3c22476c776b44d53fed86
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:unsixify-breezy
Merge into: launchpad:master
Diff against target: 252 lines (+42/-48)
8 files modified
lib/lp/code/bzr.py (+6/-9)
lib/lp/code/interfaces/tests/test_branch.py (+1/-2)
lib/lp/code/model/branchjob.py (+1/-2)
lib/lp/code/xmlrpc/tests/test_codehosting.py (+5/-6)
lib/lp/codehosting/bzrutils.py (+7/-8)
lib/lp/codehosting/puller/tests/test_scheduler.py (+5/-5)
lib/lp/codehosting/puller/worker.py (+12/-6)
lib/lp/codehosting/vfs/tests/test_branchfs.py (+5/-10)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+436685@code.launchpad.net

Commit message

Remove six from code interacting with Breezy

Description of the change

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_*`.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/bzr.py b/lib/lp/code/bzr.py
2index 8c30aed..75e7932 100644
3--- a/lib/lp/code/bzr.py
4+++ b/lib/lp/code/bzr.py
5@@ -20,7 +20,6 @@ __all__ = [
6 # line below this comment.
7 import lp.codehosting # noqa: F401 # isort: split
8
9-import six
10 from breezy.branch import UnstackableBranchFormat
11 from breezy.bzr.branch import (
12 BranchReferenceFormat,
13@@ -65,10 +64,10 @@ from lazr.enum import DBEnumeratedType, DBItem
14 def _format_enum(num, format, format_string=None, description=None):
15 instance = format()
16 if format_string is None:
17- format_string = instance.get_format_string()
18+ format_string = instance.get_format_string().decode()
19 if description is None:
20 description = instance.get_format_description()
21- return DBItem(num, six.ensure_str(format_string), description)
22+ return DBItem(num, format_string, description)
23
24
25 class BazaarFormatEnum(DBEnumeratedType):
26@@ -313,12 +312,10 @@ def get_branch_formats(bzr_branch):
27
28 :returns: tuple of (ControlFormat, BranchFormat, RepositoryFormat)
29 """
30- control_string = six.ensure_str(
31- bzr_branch.controldir._format.get_format_string()
32- )
33- branch_string = six.ensure_str(bzr_branch._format.get_format_string())
34- repository_string = six.ensure_str(
35- bzr_branch.repository._format.get_format_string()
36+ control_string = bzr_branch.controldir._format.get_format_string().decode()
37+ branch_string = bzr_branch._format.get_format_string().decode()
38+ repository_string = (
39+ bzr_branch.repository._format.get_format_string().decode()
40 )
41 return (
42 ControlFormat.get_enum(control_string),
43diff --git a/lib/lp/code/interfaces/tests/test_branch.py b/lib/lp/code/interfaces/tests/test_branch.py
44index 128d3d1..999a069 100644
45--- a/lib/lp/code/interfaces/tests/test_branch.py
46+++ b/lib/lp/code/interfaces/tests/test_branch.py
47@@ -3,7 +3,6 @@
48
49 """Tests of the branch interface."""
50
51-import six
52 from breezy.branch import format_registry as branch_format_registry
53 from breezy.bzr import BzrProber
54 from breezy.repository import format_registry as repo_format_registry
55@@ -34,7 +33,7 @@ class TestFormatSupport(TestCase):
56 """Ensure the Breezy format marker list is a subset of Launchpad."""
57 breezy_format_strings = set(breezy_formats)
58 launchpad_format_strings = {
59- six.ensure_binary(format.title) for format in launchpad_enum.items
60+ format.title.encode() for format in launchpad_enum.items
61 }
62 self.assertEqual(
63 set(), breezy_format_strings.difference(launchpad_format_strings)
64diff --git a/lib/lp/code/model/branchjob.py b/lib/lp/code/model/branchjob.py
65index 291c1e7..e593b2b 100644
66--- a/lib/lp/code/model/branchjob.py
67+++ b/lib/lp/code/model/branchjob.py
68@@ -20,7 +20,6 @@ import shutil
69 import tempfile
70 from typing import Optional
71
72-import six
73 import transaction
74 from breezy.branch import Branch as BzrBranch
75 from breezy.diff import show_diff_trees
76@@ -615,7 +614,7 @@ class RevisionsAddedJob(BranchJobDerived):
77 show_diff_trees(
78 from_tree, to_tree, diff_content, old_label="", new_label=""
79 )
80- return six.ensure_text(diff_content.getvalue(), errors="replace")
81+ return diff_content.getvalue().decode(errors="replace")
82
83 def getMailerForRevision(self, revision, revno, generate_diff):
84 """Return a BranchMailer for a revision.
85diff --git a/lib/lp/code/xmlrpc/tests/test_codehosting.py b/lib/lp/code/xmlrpc/tests/test_codehosting.py
86index b25fc57..c604c36 100644
87--- a/lib/lp/code/xmlrpc/tests/test_codehosting.py
88+++ b/lib/lp/code/xmlrpc/tests/test_codehosting.py
89@@ -8,7 +8,6 @@ import os
90 import threading
91
92 import pytz
93-import six
94 import transaction
95 from breezy import controldir
96 from breezy.urlutils import escape
97@@ -708,12 +707,12 @@ class CodehostingTest(WithScenarios, TestCaseWithFactory):
98
99 def getFormatStringsForFormatName(self, format_name):
100 default_format = controldir.format_registry.get(format_name)()
101- control_string = six.ensure_str(default_format.get_format_string())
102- branch_string = six.ensure_str(
103- default_format.get_branch_format().get_format_string()
104+ control_string = default_format.get_format_string().decode()
105+ branch_string = (
106+ default_format.get_branch_format().get_format_string().decode()
107 )
108- repository_string = six.ensure_str(
109- default_format.repository_format.get_format_string()
110+ repository_string = (
111+ default_format.repository_format.get_format_string().decode()
112 )
113 return (control_string, branch_string, repository_string)
114
115diff --git a/lib/lp/codehosting/bzrutils.py b/lib/lp/codehosting/bzrutils.py
116index 43e7abb..c3e1d32 100644
117--- a/lib/lp/codehosting/bzrutils.py
118+++ b/lib/lp/codehosting/bzrutils.py
119@@ -27,7 +27,6 @@ import os
120 import sys
121 from contextlib import contextmanager
122
123-import six
124 from breezy import config, trace
125 from breezy.branch import UnstackableBranchFormat
126 from breezy.bzr.remote import RemoteBranch, RemoteBzrDir, RemoteRepository
127@@ -316,13 +315,13 @@ def get_branch_info(branch):
128 # XXX: Aaron Bentley 2008-06-13
129 # Bazaar does not provide a public API for learning about
130 # format markers. Fix this in Bazaar, then here.
131- info["control_string"] = six.ensure_str(
132- branch.controldir._format.get_format_string()
133- )
134- info["branch_string"] = six.ensure_str(branch._format.get_format_string())
135- info["repository_string"] = six.ensure_str(
136- branch.repository._format.get_format_string()
137- )
138+ info[
139+ "control_string"
140+ ] = branch.controldir._format.get_format_string().decode()
141+ info["branch_string"] = branch._format.get_format_string().decode()
142+ info[
143+ "repository_string"
144+ ] = branch.repository._format.get_format_string().decode()
145 return info
146
147
148diff --git a/lib/lp/codehosting/puller/tests/test_scheduler.py b/lib/lp/codehosting/puller/tests/test_scheduler.py
149index ee089d0..b3eb82e 100644
150--- a/lib/lp/codehosting/puller/tests/test_scheduler.py
151+++ b/lib/lp/codehosting/puller/tests/test_scheduler.py
152@@ -684,12 +684,12 @@ class TestPullerMasterIntegration(PullerBranchTestCase):
153
154 def check_authserver_called(ignored):
155 default_format = format_registry.get("default")()
156- control_string = six.ensure_str(default_format.get_format_string())
157- branch_string = six.ensure_str(
158+ control_string = default_format.get_format_string().decode()
159+ branch_string = (
160 default_format.get_branch_format().get_format_string()
161- )
162- repository_string = six.ensure_str(
163- default_format.repository_format.get_format_string()
164+ ).decode()
165+ repository_string = (
166+ default_format.repository_format.get_format_string().decode()
167 )
168 self.assertEqual(
169 [
170diff --git a/lib/lp/codehosting/puller/worker.py b/lib/lp/codehosting/puller/worker.py
171index 662d6dd..465fca7 100644
172--- a/lib/lp/codehosting/puller/worker.py
173+++ b/lib/lp/codehosting/puller/worker.py
174@@ -484,11 +484,15 @@ class PullerWorker:
175 # XXX: Aaron Bentley 2008-06-13
176 # Bazaar does not provide a public API for learning about
177 # format markers. Fix this in Bazaar, then here.
178- control_string = dest_branch.controldir._format.get_format_string()
179+ control_string = (
180+ dest_branch.controldir._format.get_format_string().decode()
181+ )
182 if dest_branch._format.__class__ is BzrBranchFormat4:
183 branch_string = BranchFormat.BZR_BRANCH_4.title
184 else:
185- branch_string = dest_branch._format.get_format_string()
186+ branch_string = (
187+ dest_branch._format.get_format_string().decode()
188+ )
189 repository_format = dest_branch.repository._format
190 if repository_format.__class__ is RepositoryFormat6:
191 repository_string = RepositoryFormat.BZR_REPOSITORY_6.title
192@@ -497,14 +501,16 @@ class PullerWorker:
193 elif repository_format.__class__ is RepositoryFormat4:
194 repository_string = RepositoryFormat.BZR_REPOSITORY_4.title
195 else:
196- repository_string = repository_format.get_format_string()
197+ repository_string = (
198+ repository_format.get_format_string().decode()
199+ )
200 self.protocol.branchChanged(
201 stacked_on_url,
202 revid_before,
203 revid_after,
204- six.ensure_str(control_string),
205- six.ensure_str(branch_string),
206- six.ensure_str(repository_string),
207+ control_string,
208+ branch_string,
209+ repository_string,
210 )
211
212 def __eq__(self, other):
213diff --git a/lib/lp/codehosting/vfs/tests/test_branchfs.py b/lib/lp/codehosting/vfs/tests/test_branchfs.py
214index 5d9c713..bc9b414 100644
215--- a/lib/lp/codehosting/vfs/tests/test_branchfs.py
216+++ b/lib/lp/codehosting/vfs/tests/test_branchfs.py
217@@ -9,7 +9,6 @@ import re
218 import sys
219 import xmlrpc.client
220
221-import six
222 from breezy import errors
223 from breezy.bzr.bzrdir import BzrDir
224 from breezy.controldir import format_registry
225@@ -268,9 +267,7 @@ class TestLaunchpadServer(MixinBaseLaunchpadServerTests, BzrTestCase):
226 % (branch.owner.name, branch.product.name)
227 )
228 self.assertEqual(
229- six.ensure_binary(
230- "default_stack_on = %s\n" % branch_id_alias(branch)
231- ),
232+ ("default_stack_on = %s\n" % branch_id_alias(branch)).encode(),
233 transport.get_bytes(path),
234 )
235
236@@ -1087,12 +1084,10 @@ class TestBranchChangedNotification(TestCaseWithTransport):
237
238 def assertFormatStringsPassed(self, branch):
239 self.assertEqual(1, len(self._branch_changed_log))
240- control_string = six.ensure_str(
241- branch.controldir._format.get_format_string()
242- )
243- branch_string = six.ensure_str(branch._format.get_format_string())
244- repository_string = six.ensure_str(
245- branch.repository._format.get_format_string()
246+ control_string = branch.controldir._format.get_format_string().decode()
247+ branch_string = branch._format.get_format_string().decode()
248+ repository_string = (
249+ branch.repository._format.get_format_string().decode()
250 )
251 self.assertEqual(
252 (control_string, branch_string, repository_string),

Subscribers

People subscribed via source and target branches

to status/vote changes: