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
| 1 | 1 | #!/usr/bin/env python | |
| 2 | 2 | from __future__ import with_statement | |
| 3 | + | ||
| 3 | 4 | import logging | |
| 4 | 5 | import optparse | |
| 5 | 6 | import os | |
| ⋯ | |||
| 259 | 260 | ||
| 260 | 261 | ||
| 261 | 262 | 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: | |
| 264 | 266 | lines = f.readlines() | |
| 267 | + | ||
| 265 | 268 | has_change = False | |
| 269 | + | ||
| 266 | 270 | 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 | + | ||
| 268 | 273 | if not line or line.startswith('#') or line.startswith('import '): | |
| 269 | 274 | continue | |
| 270 | 275 | elif _dirmatch(line, old_dir): | |
| 271 | 276 | lines[num] = line.replace(old_dir, new_dir, 1) | |
| 272 | 277 | has_change = True | |
| 278 | + | ||
| 273 | 279 | 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) | |
| 276 | 283 | ||
| 277 | 284 | ||
| 278 | 285 | def fixup_egglink_file(filename, old_dir, new_dir): | |
The check that tells the two apart
fail→pass·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.