summaryrefslogtreecommitdiff
path: root/setuptools/command
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-08-12 03:59:23 +0100
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2022-08-12 03:59:23 +0100
commit048633afd7d6e4f852766d06c975ad602a035193 (patch)
tree8ace21cd0774b554e1a3eff11701addf0ec449ff /setuptools/command
parent37278c3dfdc5427b267c4a4979a6e374dd33b228 (diff)
downloadpython-setuptools-git-048633afd7d6e4f852766d06c975ad602a035193.tar.gz
Safeguard editable installs against build_py errors
Diffstat (limited to 'setuptools/command')
-rw-r--r--setuptools/command/build.py4
-rw-r--r--setuptools/command/editable_wheel.py45
2 files changed, 46 insertions, 3 deletions
diff --git a/setuptools/command/build.py b/setuptools/command/build.py
index 283999da..c0676d8e 100644
--- a/setuptools/command/build.py
+++ b/setuptools/command/build.py
@@ -20,7 +20,7 @@ class build(_build):
# copy to avoid sharing the object with parent class
sub_commands = _build.sub_commands[:]
- def run(self):
+ def get_sub_commands(self):
subcommands = {cmd[0] for cmd in _build.sub_commands}
if subcommands - _ORIGINAL_SUBCOMMANDS:
msg = """
@@ -30,7 +30,7 @@ class build(_build):
"""
warnings.warn(msg, SetuptoolsDeprecationWarning)
self.sub_commands = _build.sub_commands
- super().run()
+ return super().get_sub_commands()
class SubCommand(Protocol):
diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py
index 1bb7ddfb..2c98983f 100644
--- a/setuptools/command/editable_wheel.py
+++ b/setuptools/command/editable_wheel.py
@@ -37,6 +37,7 @@ from typing import (
)
from setuptools import Command, SetuptoolsDeprecationWarning, errors, namespaces
+from setuptools.command.build_py import build_py as build_py_cls
from setuptools.discovery import find_package_path
from setuptools.dist import Distribution
@@ -254,13 +255,55 @@ class editable_wheel(Command):
self, dist_name: str, unpacked_wheel: _Path, build_lib: _Path, tmp_dir: _Path
) -> Tuple[List[str], Dict[str, str]]:
self._configure_build(dist_name, unpacked_wheel, build_lib, tmp_dir)
- self.run_command("build")
+ self._run_build_subcommands()
files, mapping = self._collect_build_outputs()
self._run_install("headers")
self._run_install("scripts")
self._run_install("data")
return files, mapping
+ def _run_build_subcommands(self):
+ """
+ Issue #3501 indicates that some plugins/customizations might rely on:
+
+ 1. ``build_py`` not running
+ 2. ``build_py`` always copying files to ``build_lib``
+
+ However both these assumptions may be false in editable_wheel.
+ This method implements a temporary workaround to support the ecosystem
+ while the implementations catch up.
+ """
+ # TODO: Once plugins/customisations had the chance to catch up, replace
+ # `self._run_build_subcommands()` with `self.run_command("build")`.
+ # Also remove _safely_run, TestCustomBuildPy. Suggested date: Aug/2023.
+ build: Command = self.get_finalized_command("build")
+ for name in build.get_sub_commands():
+ cmd = self.distribution.get_command_obj(name)
+ if name == "build_py" and type(cmd) != build_py_cls:
+ self._safely_run(name)
+ else:
+ self.run_command(name)
+
+ def _safely_run(self, cmd_name: str):
+ try:
+ return self.run_command(cmd_name)
+ except Exception:
+ msg = f"""{traceback.format_exc()}\n
+ If you are seeing this warning it is very likely that a setuptools
+ plugin or customization overrides the `build_py` command, without
+ tacking into consideration how editable installs run build steps
+ starting from v64.0.0.
+
+ Plugin authors and developers relying on custom build steps are encouraged
+ to update their `build_py` implementation considering the information in
+ https://setuptools.pypa.io/en/latest/userguide/extension.html
+ about editable installs.
+
+ For the time being `setuptools` will silence this error and ignore
+ the faulty command, but this behaviour will change in future versions.\n
+ """
+ warnings.warn(msg, SetuptoolsDeprecationWarning, stacklevel=2)
+
def _create_wheel_file(self, bdist_wheel):
from wheel.wheelfile import WheelFile