diff options
author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-04-06 17:09:12 +0100 |
---|---|---|
committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-06-15 16:43:47 +0100 |
commit | 7b402eb104681ca0cfbe36ac8e10bafa2030a9d8 (patch) | |
tree | 8a9eeb6e2060db61052b48750d2962c25e106bee /setuptools/command/editable_wheel.py | |
parent | 06fbc3688726c224c6f8ddc6ad434ce36f8c1ed7 (diff) | |
download | python-setuptools-git-7b402eb104681ca0cfbe36ac8e10bafa2030a9d8.tar.gz |
Temporarily support deprecated namespace packages
Diffstat (limited to 'setuptools/command/editable_wheel.py')
-rw-r--r-- | setuptools/command/editable_wheel.py | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index 7aa73c52..e03eb671 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -7,10 +7,12 @@ Create a wheel that, when installed, will make the source package 'editable' import os import shutil import sys -from distutils.core import Command from pathlib import Path from tempfile import TemporaryDirectory +from setuptools import Command +from setuptools import namespaces + class editable_wheel(Command): """Build 'editable' wheel for development""" @@ -39,7 +41,7 @@ class editable_wheel(Command): @property def target(self): package_dir = self.distribution.package_dir or {} - return package_dir.get("") or self.project_dir + return _normalize_path(package_dir.get("") or self.project_dir) def run(self): self._ensure_dist_info() @@ -65,6 +67,15 @@ class editable_wheel(Command): assert str(self.dist_info_dir).endswith(".dist-info") assert Path(self.dist_info_dir, "METADATA").exists() + def _install_namespaces(self, installation_dir, pth_prefix): + # XXX: Only required to support the deprecated namespace practice + dist = self.distribution + if not dist.namespace_packages: + return + + installer = _NamespaceInstaller(dist, installation_dir, pth_prefix, self.target) + installer.install_namespaces() + def _create_wheel_file(self, bdist_wheel): from wheel.wheelfile import WheelFile @@ -82,13 +93,13 @@ class editable_wheel(Command): with TemporaryDirectory(suffix=archive_name) as tmp: tmp_dist_info = Path(tmp, Path(self.dist_info_dir).name) shutil.copytree(self.dist_info_dir, tmp_dist_info) + self._install_namespaces(tmp, editable_name) self._populate_wheel(editable_name, tmp) with WheelFile(wheel_path, "w") as wf: wf.write_files(tmp) return wheel_path - def _best_strategy(self): if self.strict: return self._link_tree @@ -107,8 +118,25 @@ class editable_wheel(Command): # >>> self.dist.packages def _populate_wheel(self, dist_id, unpacked_wheel_dir): - pth = Path(unpacked_wheel_dir, f"_editable.{dist_id}.pth") - pth.write_text(f"{_normalize_path(self.target)}\n", encoding="utf-8") + pth = Path(unpacked_wheel_dir, f"__editable__.{dist_id}.pth") + pth.write_text(f"{self.target}\n", encoding="utf-8") + + +class _NamespaceInstaller(namespaces.Installer): + def __init__(self, distribution, installation_dir, editable_name, src_root): + self.distribution = distribution + self.src_root = src_root + self.installation_dir = installation_dir + self.editable_name = editable_name + self.outputs = [] + + def _get_target(self): + """Installation target.""" + return os.path.join(self.installation_dir, self.editable_name) + + def _get_root(self): + """Where the modules/packages should be loaded from.""" + return repr(str(self.src_root)) def _normalize_path(filename): |