From 884d5551ff02451612056f3387b1741855ac8392 Mon Sep 17 00:00:00 2001 From: Bartosz Sokorski Date: Thu, 3 Apr 2025 13:37:53 +0200 Subject: [PATCH 1/4] Fix potential relpath bug on Windows platform --- src/installer/destinations.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/installer/destinations.py b/src/installer/destinations.py index 2de7437..812d1ae 100644 --- a/src/installer/destinations.py +++ b/src/installer/destinations.py @@ -15,6 +15,7 @@ from installer.records import Hash, RecordEntry from installer.scripts import Script from installer.utils import ( + _WINDOWS, Scheme, construct_record_file, copyfileobj_with_hashing, @@ -267,10 +268,13 @@ def finalize_installation( def prefix_for_scheme(file_scheme: str) -> Optional[str]: if file_scheme == scheme: return None - path = os.path.relpath( - self.scheme_dict[file_scheme], - start=self.scheme_dict[scheme], - ) + if _WINDOWS: # pragma: no cover + path = os.path.abspath(self.scheme_dict[file_scheme]) # noqa: PTH100 + else: + path = os.path.relpath( + self.scheme_dict[file_scheme], + start=self.scheme_dict[scheme], + ) return path + "/" record_list = list(records) From e84952f0089025a74ff1ac87d0b159235a5cb422 Mon Sep 17 00:00:00 2001 From: Aleksandr Sergeev <22302418+pseusys@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:27:40 +0200 Subject: [PATCH 2/4] Relative test fix --- tests/test_destinations.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/test_destinations.py b/tests/test_destinations.py index 480d238..c80e3d6 100644 --- a/tests/test_destinations.py +++ b/tests/test_destinations.py @@ -177,13 +177,16 @@ def test_finalize_write_record(self, destination): destination.finalize_installation("purelib", "RECORD", records) file_path = Path(destination.scheme_dict["purelib"]) / "RECORD" - data = file_path.read_bytes() - assert data == ( + expected_data = ( b"RECORD,,\n" - b"../data/my_data1.bin,sha256=NV0A-M4OPuqTsHjeD6Wth_-UqrpAAAdyplcustFZ8s4,9\n" - b"../data/my_data2.bin,sha256=lP7V8oWLqgyXCbdASNiPdsUogzPUZhht_7F8T5bC3eQ,9\n" - b'"../data/my_data3,my_data4.bin",sha256=18krruu1gr01x-WM_9ChSASoHv0mfRAV6-B2bd9sxpo,9\n' - b"../scripts/my_entrypoint,sha256=_p_9nwmeIeoMBfQ0akhr1KbKn3laDydg0J7cy0Fs6JI,216\n" - b"../scripts/my_script,sha256=M60fWvUSMJkPtw2apUvjWWwOcnRPcVy_zO4-4lpH08o,9\n" - b"../scripts/my_script2,sha256=k9_997kTbTYQm7EXFLclVZL1m2N98rU90QX46XeMvjY,22\n" + b"data/my_data1.bin,sha256=NV0A-M4OPuqTsHjeD6Wth_-UqrpAAAdyplcustFZ8s4,9\n" + b"data/my_data2.bin,sha256=lP7V8oWLqgyXCbdASNiPdsUogzPUZhht_7F8T5bC3eQ,9\n" + b'data/my_data3,my_data4.bin",sha256=18krruu1gr01x-WM_9ChSASoHv0mfRAV6-B2bd9sxpo,9\n' + b"scripts/my_entrypoint,sha256=_p_9nwmeIeoMBfQ0akhr1KbKn3laDydg0J7cy0Fs6JI,216\n" + b"scripts/my_script,sha256=M60fWvUSMJkPtw2apUvjWWwOcnRPcVy_zO4-4lpH08o,9\n" + b"scripts/my_script2,sha256=k9_997kTbTYQm7EXFLclVZL1m2N98rU90QX46XeMvjY,22\n" + ) + assert all( + real.endswith(expected) + for real, expected in zip(data.split(b"\n"), expected_data.split(b"\n")) ) From 02da2d70646f35319c76d29c28f11b85706914ff Mon Sep 17 00:00:00 2001 From: Aleksandr Sergeev <22302418+pseusys@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:33:13 +0200 Subject: [PATCH 3/4] Update test_destinations.py Weird merging error fixed --- tests/test_destinations.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_destinations.py b/tests/test_destinations.py index c80e3d6..ad71f8c 100644 --- a/tests/test_destinations.py +++ b/tests/test_destinations.py @@ -177,6 +177,7 @@ def test_finalize_write_record(self, destination): destination.finalize_installation("purelib", "RECORD", records) file_path = Path(destination.scheme_dict["purelib"]) / "RECORD" + data = file_path.read_bytes() expected_data = ( b"RECORD,,\n" b"data/my_data1.bin,sha256=NV0A-M4OPuqTsHjeD6Wth_-UqrpAAAdyplcustFZ8s4,9\n" From 2648a97701f689240e7317e3cac9ba04dcafbc80 Mon Sep 17 00:00:00 2001 From: Aleksandr Sergeev <22302418+pseusys@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:39:41 +0200 Subject: [PATCH 4/4] Coverage disabled for all OSes --- src/installer/destinations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/destinations.py b/src/installer/destinations.py index 812d1ae..7eb26ca 100644 --- a/src/installer/destinations.py +++ b/src/installer/destinations.py @@ -270,7 +270,7 @@ def prefix_for_scheme(file_scheme: str) -> Optional[str]: return None if _WINDOWS: # pragma: no cover path = os.path.abspath(self.scheme_dict[file_scheme]) # noqa: PTH100 - else: + else: # pragma: no cover path = os.path.relpath( self.scheme_dict[file_scheme], start=self.scheme_dict[scheme],