From 39245fc7503a82d7ba7f1706b2e599c5aecb1cdf Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 5 Sep 2023 18:57:45 +0100 Subject: [PATCH] Customise *-nspkg.pth files for unique names in editable_wheel --- setuptools/command/editable_wheel.py | 6 +++--- setuptools/namespaces.py | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index 7f66f7e3e9..f0d6f4575a 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -341,7 +341,7 @@ def _create_wheel_file(self, bdist_wheel): with unpacked_wheel as unpacked, build_lib as lib, build_tmp as tmp: unpacked_dist_info = Path(unpacked, Path(self.dist_info_dir).name) shutil.copytree(self.dist_info_dir, unpacked_dist_info) - self._install_namespaces(unpacked, dist_info.name) + self._install_namespaces(unpacked, dist_name) files, mapping = self._run_build_commands(dist_name, unpacked, lib, tmp) strategy = self._select_strategy(dist_name, tag, lib) with strategy, WheelFile(wheel_path, "w") as wheel_obj: @@ -752,9 +752,9 @@ def __init__(self, distribution, installation_dir, editable_name, src_root): self.outputs = [] self.dry_run = False - def _get_target(self): + def _get_nspkg_file(self): """Installation target.""" - return os.path.join(self.installation_dir, self.editable_name) + return os.path.join(self.installation_dir, self.editable_name + self.nspkg_ext) def _get_root(self): """Where the modules/packages should be loaded from.""" diff --git a/setuptools/namespaces.py b/setuptools/namespaces.py index 8774432a7e..3332f864ae 100644 --- a/setuptools/namespaces.py +++ b/setuptools/namespaces.py @@ -13,8 +13,7 @@ def install_namespaces(self): nsp = self._get_all_ns_packages() if not nsp: return - filename, ext = os.path.splitext(self._get_target()) - filename += self.nspkg_ext + filename = self._get_nspkg_file() self.outputs.append(filename) log.info("Installing %s", filename) lines = map(self._gen_nspkg_line, nsp) @@ -28,13 +27,16 @@ def install_namespaces(self): f.writelines(lines) def uninstall_namespaces(self): - filename, ext = os.path.splitext(self._get_target()) - filename += self.nspkg_ext + filename = self._get_nspkg_file() if not os.path.exists(filename): return log.info("Removing %s", filename) os.remove(filename) + def _get_nspkg_file(self): + filename, _ = os.path.splitext(self._get_target()) + return filename + self.nspkg_ext + def _get_target(self): return self.target