From 8310f31a1caaca81cf82cdadcb889b40f4901521 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Sun, 8 Oct 2023 20:52:00 +0800 Subject: [PATCH] fix: normalize the dist info name in the wheel So that it doesn't reuse the dirname from the path pased in. This keeps the dist info name consistent. Refer to issue: https://github.com/pdm-project/pdm/discussions/2208 Signed-off-by: Frost Ming --- src/pdm/backend/wheel.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/pdm/backend/wheel.py b/src/pdm/backend/wheel.py index ea9eafe..952e0d2 100644 --- a/src/pdm/backend/wheel.py +++ b/src/pdm/backend/wheel.py @@ -4,6 +4,7 @@ import hashlib import io import os +import posixpath import shutil import stat import sys @@ -293,13 +294,19 @@ def _write_entry_points( def _get_metadata_files(self, context: Context) -> Iterable[tuple[str, Path]]: """Generate the metadata files for the wheel.""" if context.kwargs.get("metadata_directory"): - return self._iter_files_in_directory(context.kwargs["metadata_directory"]) + return self._iter_metadata_files(context.kwargs["metadata_directory"]) else: dist_info = self._write_dist_info(context.ensure_build_dir()) - return self._iter_files_in_directory(str(dist_info)) + return self._iter_metadata_files(str(dist_info)) - def _iter_files_in_directory(self, path: str) -> Iterable[tuple[str, Path]]: + def _iter_metadata_files(self, path: str) -> Iterable[tuple[str, Path]]: + dist_info_name = self.dist_info_name for root, _, files in os.walk(path): - relroot = os.path.relpath(root, os.path.dirname(path)) for file in files: - yield (Path(relroot, file).as_posix(), Path(root) / file) + # the relative path is concated with the dist-info name + # so that the dist info name is always consistent with the current build + # e.g. /METADATA -> -.dist-info/METADATA + relpath = posixpath.join( + dist_info_name, Path(root, file).relative_to(path).as_posix() + ) + yield relpath, Path(root, file)