Whole file

edwardgeorge/virtualenv-clone

The author described this change as Fix fixup_pth_file with files written in UNICODE rather than UTF-8.. It counts as a record because the check below fails on the code as it stood at b9f4dd518 and passes on b318cbb38, with nothing else changed between the two runs.

Fix saved2017-10-06
Sharing licenceMIT · LICENSE
Change size+12 5

What the code was meant to do, written into the code itself as a save note

Fix fixup_pth_file with files written in UNICODE rather than UTF-8.

The change

11 #!/usr/bin/env python
22 from __future__ import with_statement
3+
34 import logging
45 import optparse
56 import os
259260
260261
261262 def fixup_pth_file(filename, old_dir, new_dir):
262- logger.debug('fixing %s' % filename)
263- with open(filename, 'rb') as f:
263+ logger.debug('fixup_pth_file %s' % filename)
264+
265+ with open(filename, 'r') as f:
264266 lines = f.readlines()
267+
265268 has_change = False
269+
266270 for num, line in enumerate(lines):
267- line = line.decode('utf-8').strip()
271+ line = (line.decode('utf-8') if hasattr(line, 'decode') else line).strip()
272+
268273 if not line or line.startswith('#') or line.startswith('import '):
269274 continue
270275 elif _dirmatch(line, old_dir):
271276 lines[num] = line.replace(old_dir, new_dir, 1)
272277 has_change = True
278+
273279 if has_change:
274- with open(filename, 'wb') as f:
275- f.writelines(lines)
280+ with open(filename, 'w') as f:
281+ payload = os.linesep.join([l.strip() for l in lines]) + os.linesep
282+ f.write(payload)
276283
277284
278285 def fixup_egglink_file(filename, old_dir, new_dir):

The check that tells the two apart

failpass·tests/test_fixup_scripts.py::TestFixupScripts::test_fixup_pth_file

Check file tests/test_fixup_scripts.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itb9f4dd518297d4a9e0a64ceb0e5aa7a376162b3c
Broken version dated2017-10-06
Moduleclonevirtualenv
Units changedfixup_pth_file
Fingerprintbd44ead29f227287
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.