From c8f70dda92c66adeba5d95d6a5884c8b044603b8 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Mon, 10 Jul 2023 20:12:50 +0800 Subject: [PATCH] fix: remove duplicate files when building wheel Signed-off-by: Frost Ming --- src/pdm/backend/editable.py | 3 +-- src/pdm/backend/wheel.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/pdm/backend/editable.py b/src/pdm/backend/editable.py index 0a5ba0c..2814c6f 100644 --- a/src/pdm/backend/editable.py +++ b/src/pdm/backend/editable.py @@ -35,8 +35,7 @@ def pdm_build_initialize(self, context: Context) -> None: def pdm_build_update_files(self, context: Context, files: dict[str, Path]) -> None: packages: list[str] = context.config.convert_package_paths()["packages"] - package_dir = context.config.build_config.package_dir - proxied = {os.path.join(package_dir, p.replace(".", "/")) for p in packages} + proxied = {p.replace(".", "/") for p in packages} for relpath in list(files): if os.path.splitext(relpath)[1] in (".py", ".pyc", ".pyo"): # All .py[cod] files are proxied diff --git a/src/pdm/backend/wheel.py b/src/pdm/backend/wheel.py index b094a1a..aafb9db 100644 --- a/src/pdm/backend/wheel.py +++ b/src/pdm/backend/wheel.py @@ -20,6 +20,7 @@ from pdm.backend.base import Builder from pdm.backend.hooks import Context from pdm.backend.hooks.setuptools import SetuptoolsBuildHook +from pdm.backend.structures import FileMap from pdm.backend.utils import ( expand_vars, get_abi_tag, @@ -122,13 +123,23 @@ def prepare_metadata(self, metadata_directory: str) -> Path: self.initialize(context) return self._write_dist_info(Path(metadata_directory)) - def get_files(self, context: Context) -> Iterable[tuple[str, Path]]: + def _collect_files(self, context: Context) -> FileMap: package_dir = self.config.build_config.package_dir - for relpath, path in super().get_files(context): + result = FileMap() + + def clean_prefix(relpath: str) -> str: # remove the package-dir part from the relative paths if package_dir and relpath.startswith(package_dir + "/"): relpath = relpath[len(package_dir) + 1 :] - yield relpath, path + return relpath + + result.update( + (clean_prefix(k), v) for k, v in super()._collect_files(context).items() + ) + return result + + def get_files(self, context: Context) -> Iterable[tuple[str, Path]]: + yield from super().get_files(context) yield from self._get_metadata_files(context) yield from self._get_wheel_data(context)