Merge lp:~gocept/landscape-client/py3-cleanup into lp:~landscape/landscape-client/trunk

Proposed by Steffen Allner
Status: Merged
Approved by: Eric Snow
Approved revision: 1000
Merged at revision: 1003
Proposed branch: lp:~gocept/landscape-client/py3-cleanup
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 205 lines (+9/-46)
9 files modified
landscape/compat.py (+0/-26)
landscape/lib/tests/test_fetch.py (+1/-1)
landscape/manager/customgraph.py (+1/-2)
landscape/manager/tests/test_aptsources.py (+0/-1)
landscape/manager/tests/test_scriptexecution.py (+0/-3)
landscape/package/facade.py (+5/-2)
landscape/tests/clock.py (+0/-7)
landscape/tests/test_deployment.py (+2/-2)
landscape/user/tests/test_provider.py (+0/-2)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-cleanup
Reviewer Review Type Date Requested Status
Eric Snow (community) Approve
🤖 Landscape Builder test results Approve
Daniel Havlik (community) Approve
Review via email: mp+321976@code.launchpad.net

Commit message

Cleanups related to landscape.compat (and lint).

This MP cleans up small residues from the port to Python 2/3 compatibility. It removes the unwanted coerce_unicode() helper method, which was replaced by individual solutions at the respective place of use. Furthermore unused imports have been removed and the usage (c)StringIO has been investigated, whether it could be replaced by a common io.{String,Bytes}IO() call in Python 2 and 3. This was often not the case, as this was also connected with the logging setup in the tests, which should not be addressed here.

Description of the change

This MP cleans up small residues from the port to Python 2/3 compatibility. It emoves the unwanted coerce_unicode() helper method, which was replaced by individual solutions at the respective place of use. Furthermore unused imports have been removed and the usage (c)StringIO has been investigated, whether it could be replaced by a common io.{String,Bytes}IO() call in Python 2 and 3. This was often not the case, as this was also connected with the logging setup in the tests, which should not be addressed here.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
Daniel Havlik (nilo) wrote :

+1

review: Approve
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-check
Result: Success
Revno: 1000
Branch: lp:~gocept/landscape-client/py3-cleanup
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3837/

review: Approve (test results)
Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

LGTM

Thanks for the lint cleanups too. :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/compat.py'
2--- landscape/compat.py 2017-03-27 13:05:52 +0000
3+++ landscape/compat.py 2017-04-05 11:33:19 +0000
4@@ -22,29 +22,3 @@
5 stringio = StringIO
6 from cStringIO import StringIO as cstringio
7 input = raw_input
8-
9-
10-def coerce_unicode(s, encoding='ascii', errors='strict'):
11- """
12- Coerce byte strings into unicode for Python 2.
13-
14- In Python 2, decodes a byte string L{s} into unicode using the L{encoding},
15- returns unmodified if any other type. In Python 3, raises a L{TypeError}
16- when passed a byte string in L{s}, returns unmodified otherwise.
17-
18- @param s: The string to be converted to unicode.
19- @type s: L{bytes} or L{unicode}
20- @raise UnicodeError: The input L{bytes} is not decodable
21- with given encoding.
22- @raise TypeError: The input is L{bytes} on Python 3.
23- """
24- # In Python 2 C{unicode(b'bytes')} returns a unicode string C{'bytes'}. In
25- # Python 3, the equivalent C{str(b'bytes')} will return C{"b'bytes'"}
26- # instead.
27- if isinstance(s, bytes):
28- if _PY3:
29- raise TypeError("Expected str not %r (bytes)" % (s,))
30- else:
31- return s.decode(encoding, errors)
32- else:
33- return s
34
35=== modified file 'landscape/lib/tests/test_fetch.py'
36--- landscape/lib/tests/test_fetch.py 2017-03-08 14:01:11 +0000
37+++ landscape/lib/tests/test_fetch.py 2017-04-05 11:33:19 +0000
38@@ -4,7 +4,7 @@
39 import pycurl
40
41 from twisted.internet.defer import FirstError
42-from twisted.python.compat import itervalues, unicode
43+from twisted.python.compat import unicode
44
45 from landscape.lib.fetch import (
46 fetch, fetch_async, fetch_many_async, fetch_to_files,
47
48=== modified file 'landscape/manager/customgraph.py'
49--- landscape/manager/customgraph.py 2017-03-28 09:40:46 +0000
50+++ landscape/manager/customgraph.py 2017-04-05 11:33:19 +0000
51@@ -5,7 +5,6 @@
52 from twisted.internet.defer import fail, DeferredList, succeed
53 from twisted.python.compat import iteritems
54
55-from landscape.compat import coerce_unicode
56 from landscape.lib.scriptcontent import generate_script_hash
57 from landscape.accumulate import Accumulator
58 from landscape.manager.plugin import ManagerPlugin
59@@ -189,7 +188,7 @@
60 if graph_id not in self._data:
61 return
62 if failure.check(ProcessFailedError):
63- failure_value = coerce_unicode(failure.value.data, "utf-8")
64+ failure_value = failure.value.data
65 if failure.value.exit_code:
66 failure_value = ("%s (process exited with code %d)" %
67 (failure_value, failure.value.exit_code))
68
69=== modified file 'landscape/manager/tests/test_aptsources.py'
70--- landscape/manager/tests/test_aptsources.py 2017-03-29 11:38:02 +0000
71+++ landscape/manager/tests/test_aptsources.py 2017-04-05 11:33:19 +0000
72@@ -3,7 +3,6 @@
73 import mock
74
75 from twisted.internet.defer import Deferred, succeed
76-from twisted.python.compat import _PY3
77
78 from landscape.manager.aptsources import AptSources
79 from landscape.manager.plugin import SUCCEEDED, FAILED
80
81=== modified file 'landscape/manager/tests/test_scriptexecution.py'
82--- landscape/manager/tests/test_scriptexecution.py 2017-03-27 11:52:09 +0000
83+++ landscape/manager/tests/test_scriptexecution.py 2017-04-05 11:33:19 +0000
84@@ -6,12 +6,9 @@
85
86 import mock
87
88-from unittest import skipIf
89-
90 from twisted.internet.defer import gatherResults, succeed, fail
91 from twisted.internet.error import ProcessDone
92 from twisted.python.failure import Failure
93-from twisted.python.compat import _PY3
94
95 from landscape import VERSION
96 from landscape.lib.fetch import HTTPCodeError
97
98=== modified file 'landscape/package/facade.py'
99--- landscape/package/facade.py 2017-03-21 18:03:57 +0000
100+++ landscape/package/facade.py 2017-04-05 11:33:19 +0000
101@@ -1,10 +1,10 @@
102-import time
103+import hashlib
104 import logging
105-import hashlib
106 import os
107 import subprocess
108 import sys
109 import tempfile
110+import time
111
112 from operator import attrgetter
113
114@@ -636,6 +636,9 @@
115 Commit cached APT operations and give feedback on the results as a
116 string.
117 """
118+ # XXX we cannot use io.StringIO() here with Python 2 as there is a
119+ # string literal written in apt.progress.text.TextProgress._write()
120+ # which is not recognized as unicode by io.StringIO() with Python 2.
121 fetch_output = StringIO()
122 # Redirect stdout and stderr to a file. We need to work with the
123 # file descriptors, rather than sys.stdout/stderr, since dpkg is
124
125=== modified file 'landscape/tests/clock.py'
126--- landscape/tests/clock.py 2017-01-10 13:07:51 +0000
127+++ landscape/tests/clock.py 2017-04-05 11:33:19 +0000
128@@ -30,9 +30,6 @@
129 * L{twisted.internet.base.DelayedCall}, which didn't grow its
130 C{seconds} argument until after Twisted 2.2.
131 """
132-
133-import functools
134-
135 from twisted.internet import error
136 from twisted.python.runtime import seconds as runtimeSeconds
137 from twisted.python import reflect
138@@ -63,7 +60,6 @@
139 """
140 return self.rightNow
141
142-
143 def callLater(self, when, what, *a, **kw):
144 """
145 See L{twisted.internet.interfaces.IReactorTime.callLater}.
146@@ -77,7 +73,6 @@
147 self.calls.sort(key=lambda a: a.getTime())
148 return self.calls[-1]
149
150-
151 def advance(self, amount):
152 """
153 Move time on this clock forward by the given amount and run whatever
154@@ -93,7 +88,6 @@
155 call.called = 1
156 call.func(*call.args, **call.kw)
157
158-
159 def pump(self, timings):
160 """
161 Advance incrementally by the given set of times.
162@@ -104,7 +98,6 @@
163 self.advance(amount)
164
165
166-
167 class DelayedCall:
168
169 # enable .debug to record creator call stack, and it will be logged if
170
171=== modified file 'landscape/tests/test_deployment.py'
172--- landscape/tests/test_deployment.py 2017-03-13 15:38:09 +0000
173+++ landscape/tests/test_deployment.py 2017-04-05 11:33:19 +0000
174@@ -1,9 +1,9 @@
175 from optparse import OptionParser
176 from textwrap import dedent
177+import io
178 import mock
179 import os
180
181-from landscape.compat import StringIO
182 from landscape.lib.fs import read_text_file, create_text_file
183
184 from landscape.deployment import (
185@@ -96,7 +96,7 @@
186 L{get_config_filename}.
187 """
188 config_obj = self.config._get_config_object(
189- alternative_config=StringIO("[client]\nlog_level = error\n"))
190+ alternative_config=io.StringIO(u"[client]\nlog_level = error\n"))
191 self.assertEqual(None, config_obj.filename)
192
193 def write_config_file(self, **kwargs):
194
195=== modified file 'landscape/user/tests/test_provider.py'
196--- landscape/user/tests/test_provider.py 2017-03-22 14:11:50 +0000
197+++ landscape/user/tests/test_provider.py 2017-04-05 11:33:19 +0000
198@@ -1,8 +1,6 @@
199 import pwd
200 import grp
201
202-from twisted.python.compat import _PY3
203-
204 from landscape.user.provider import (
205 UserProvider, UserNotFoundError, GroupNotFoundError)
206

Subscribers

People subscribed via source and target branches

to all changes: