diff --git a/src/installer/records.py b/src/installer/records.py index 9bb45c7..a2ea560 100644 --- a/src/installer/records.py +++ b/src/installer/records.py @@ -6,7 +6,7 @@ import os from collections.abc import Iterable, Iterator from dataclasses import dataclass -from pathlib import Path +from pathlib import Path, PureWindowsPath from typing import BinaryIO, cast from installer.utils import copyfileobj_with_hashing, get_stream_length @@ -106,8 +106,7 @@ def to_row(self, path_prefix: str | None = None) -> tuple[str, str, str]: path = self.path # Convert Windows paths to use / for consistency - if os.sep == "\\": - path = path.replace("\\", "/") # pragma: no cover + path = PureWindowsPath(path).as_posix() return ( path, diff --git a/tests/test_records.py b/tests/test_records.py index a681608..2de2a65 100644 --- a/tests/test_records.py +++ b/tests/test_records.py @@ -3,6 +3,7 @@ import pytest +import installer.records from installer.records import Hash, InvalidRecordEntry, RecordEntry, parse_record_file @@ -176,6 +177,34 @@ def test_string_representation_with_prefix( ) assert record.to_row("prefix/") == expected_row + def test_string_representation_with_backslash_path(self, monkeypatch): + monkeypatch.setattr(installer.records.os, "sep", "/") + record = RecordEntry.from_elements( + r"distribution-1.0.dist-info\RECORD", + "", + "", + ) + + assert record.to_row() == ( + "distribution-1.0.dist-info/RECORD", + "", + "", + ) + + def test_string_representation_with_backslash_path_and_prefix(self, monkeypatch): + monkeypatch.setattr(installer.records.os, "sep", "/") + record = RecordEntry.from_elements( + r"bin\script.py", + "", + "", + ) + + assert record.to_row("prefix/") == ( + "prefix/bin/script.py", + "", + "", + ) + def test_equality(self): record = RecordEntry.from_elements( "file.py",