Merge lp:~vorlon/germinate/lp.1025818 into lp:~cjwatson/germinate/trunk
| Status: | Merged |
|---|---|
| Merged at revision: | 523 |
| Proposed branch: | lp:~vorlon/germinate/lp.1025818 |
| Merge into: | lp:~cjwatson/germinate/trunk |
| Diff against target: |
59 lines (+16/-3) 3 files modified
debian/changelog (+7/-0) germinate/archive.py (+6/-1) germinate/tests/test_archive.py (+3/-2) |
| To merge this branch: | bzr merge lp:~vorlon/germinate/lp.1025818 |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Colin Watson | 2012-07-17 | Approve on 2012-07-23 | |
|
Review via email:
|
|||
Description of the Change
Fix for germinate crashing on quantal livefs buildds, where LANG == C.
| Colin Watson (cjwatson) wrote : | # |
| Steve Langasek (vorlon) wrote : | # |
The code in germinate/seeds.py includes this comment:
# io.open is available from Python 2.6, but we only use it with
# Python 3 because it raises exceptions when passed bytes.
So where would bytes be passed from that this would happen? Would this actually be a problem for the case of Packages/Sources files?
Though it looks like we can use open() for python3 but not for python2, which would seem to be preferred if we can get away with it, so it's probably not really worth consolidating this into a single call and avoid the python2 special casing.
Will work up a test case and re-push.
| Colin Watson (cjwatson) wrote : | # |
On Wed, Jul 18, 2012 at 04:37:29PM -0000, Steve Langasek wrote:
> The code in germinate/seeds.py includes this comment:
>
> # io.open is available from Python 2.6, but we only use it with
> # Python 3 because it raises exceptions when passed bytes.
>
> So where would bytes be passed from that this would happen?
Example test failure if I remove that:
Traceback (most recent call last):
File "/home/
test.
TypeError: must be unicode, not str
str == bytes in Python 2, so using io.open would effectively be an API
change, requiring that everything be done using unicode objects. I want
to keep the Python 2 API compatible.
> Would this actually be a problem for the case of Packages/Sources files?
On reflection, this case is a bit different from that of
germinate.seeds, because the file objects here are entirely internal to
germinate; so that argument for not using io.open in Python 2 isn't
valid. That said, germinate still intends to be compatible with Python
2.6 for the sake of Launchpad, and io.open was apparently rather slow in
2.6, so I think it would still be better to avoid that.
- 524. By Steve Langasek on 2012-07-18
-
use 'replace' for handling non-UTF-8 data on input, and prefer open() to
codecs.open() for python3 - 525. By Steve Langasek on 2012-07-21
-
Update test to verify correct handling of UTF-8 data in Packages files.
| Steve Langasek (vorlon) wrote : | # |
test case and io.open handling pushed. How's that look, Colin?
| Colin Watson (cjwatson) wrote : | # |
Thanks, this looks good. The bytes.decode.encode business in the test case is unfortunate but I can see why you had to do it. There's just one problem, which is that using plain open in the Python 3 case causes pychecker to fail, as shown by 'python setup.py test' (you might not have seen this because pychecker is only run if it's installed):
Processing module archive (germinate/
germinate/
germinate/
This is really a pychecker bug in that it doesn't understand Python 3, but it's easy to work around by using the otherwise-

Thanks for this fix.
Could we use io.open instead in Python 3 (or just plain open; either
way, it takes an encoding parameter now), and also use "replace" error
handling rather than falling over any non-UTF-8 data that happens to be
there since text in Packages that isn't ASCII-only is mostly
informational anyway?
See germinate/ seeds.py: AtomicFile for an example of handling the Python
2/3 differences here. It's a bit verbose, but I figure it can go away
soon enough anyway once I'm ready to drop Python 2 support from
germinate.
Any chance of a test case to make sure this doesn't regress in future? tests/test_ archive. py exists already, and perhaps you could test.test_ support (as in
Such a test case would also make it a lot easier to ensure that this
still works with both Python 2 and Python 3. It should be possible to
unit-test this rather than needing to run the full germinate script;
germinate/
use EnvironmentVarGuard from test.support/
ubiquity's tests) to temporarily force LC_ALL=C.