|
55 | 55 | from pip._internal.cache import WheelCache # noqa: F401
|
56 | 56 | from pip._internal.pep425tags import Pep425Tag # noqa: F401
|
57 | 57 |
|
58 |
| - InstalledCSVRow = Tuple[str, Union[str, Text], str] |
| 58 | + InstalledCSVRow = Tuple[str, ...] |
59 | 59 |
|
60 | 60 |
|
61 | 61 | VERSION_COMPATIBLE = (1, 0)
|
|
64 | 64 | logger = logging.getLogger(__name__)
|
65 | 65 |
|
66 | 66 |
|
| 67 | +def normpath(src, p): |
| 68 | + return os.path.relpath(src, p).replace(os.path.sep, '/') |
| 69 | + |
| 70 | + |
67 | 71 | def rehash(path, blocksize=1 << 20):
|
68 | 72 | # type: (str, int) -> Tuple[str, str]
|
69 | 73 | """Return (hash, length) for path using hashlib.sha256()"""
|
@@ -255,6 +259,28 @@ def sorted_outrows(outrows):
|
255 | 259 | return sorted(outrows, key=lambda row: tuple(str(x) for x in row))
|
256 | 260 |
|
257 | 261 |
|
| 262 | +def get_csv_rows_for_installed( |
| 263 | + old_csv_rows, # type: Iterable[List[str]] |
| 264 | + installed, # type: Dict[str, str] |
| 265 | + changed, # set |
| 266 | + generated, # type: List[str] |
| 267 | + lib_dir, |
| 268 | +): |
| 269 | + # type: (...) -> List[InstalledCSVRow] |
| 270 | + installed_rows = [] # type: List[InstalledCSVRow] |
| 271 | + for fpath, digest, length in old_csv_rows: |
| 272 | + fpath = installed.pop(fpath, fpath) |
| 273 | + if fpath in changed: |
| 274 | + digest, length = rehash(fpath) |
| 275 | + installed_rows.append((fpath, digest, str(length))) |
| 276 | + for f in generated: |
| 277 | + digest, length = rehash(f) |
| 278 | + installed_rows.append((normpath(f, lib_dir), digest, str(length))) |
| 279 | + for f in installed: |
| 280 | + installed_rows.append((installed[f], '', '')) |
| 281 | + return installed_rows |
| 282 | + |
| 283 | + |
258 | 284 | def move_wheel_files(
|
259 | 285 | name, # type: str
|
260 | 286 | req, # type: Requirement
|
@@ -305,9 +331,6 @@ def move_wheel_files(
|
305 | 331 | compileall.compile_dir(source, force=True, quiet=True)
|
306 | 332 | logger.debug(stdout.getvalue())
|
307 | 333 |
|
308 |
| - def normpath(src, p): |
309 |
| - return os.path.relpath(src, p).replace(os.path.sep, '/') |
310 |
| - |
311 | 334 | def record_installed(srcfile, destfile, modified=False):
|
312 | 335 | """Map archive RECORD paths to installation RECORD paths."""
|
313 | 336 | oldpath = normpath(srcfile, wheeldir)
|
@@ -559,28 +582,16 @@ def _get_script_text(entry):
|
559 | 582 | shutil.move(temp_installer, installer)
|
560 | 583 | generated.append(installer)
|
561 | 584 |
|
562 |
| - def get_csv_rows_for_installed(old_csv_rows): |
563 |
| - # type: (Iterable[List[str]]) -> List[InstalledCSVRow] |
564 |
| - installed_rows = [] # type: List[InstalledCSVRow] |
565 |
| - for fpath, digest, length in old_csv_rows: |
566 |
| - fpath = installed.pop(fpath, fpath) |
567 |
| - if fpath in changed: |
568 |
| - digest, length = rehash(fpath) |
569 |
| - installed_rows.append((fpath, digest, str(length))) |
570 |
| - for f in generated: |
571 |
| - digest, length = rehash(f) |
572 |
| - installed_rows.append((normpath(f, lib_dir), digest, str(length))) |
573 |
| - for f in installed: |
574 |
| - installed_rows.append((installed[f], '', '')) |
575 |
| - return installed_rows |
576 |
| - |
577 | 585 | # Record details of all files installed
|
578 | 586 | record = os.path.join(info_dir[0], 'RECORD')
|
579 | 587 | temp_record = os.path.join(info_dir[0], 'RECORD.pip')
|
580 | 588 | with open_for_csv(record, 'r') as record_in:
|
581 | 589 | with open_for_csv(temp_record, 'w+') as record_out:
|
582 | 590 | reader = csv.reader(record_in)
|
583 |
| - outrows = get_csv_rows_for_installed(reader) |
| 591 | + outrows = get_csv_rows_for_installed( |
| 592 | + reader, installed=installed, changed=changed, |
| 593 | + generated=generated, lib_dir=lib_dir, |
| 594 | + ) |
584 | 595 | writer = csv.writer(record_out)
|
585 | 596 | # Sort to simplify testing.
|
586 | 597 | for row in sorted_outrows(outrows):
|
|
0 commit comments