From 048633afd7d6e4f852766d06c975ad602a035193 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 12 Aug 2022 03:59:23 +0100 Subject: Safeguard editable installs against build_py errors --- setuptools/command/build.py | 4 ++-- setuptools/command/editable_wheel.py | 45 +++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) (limited to 'setuptools/command') 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 -- cgit v1.2.1 From 66994535aceb1d4865957ab7ec70762d15716c25 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 12 Aug 2022 04:22:31 +0100 Subject: Parametrise command name --- setuptools/command/editable_wheel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index 2c98983f..8a53de65 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -290,12 +290,12 @@ class editable_wheel(Command): 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 + plugin or customization overrides the `{cmd_name}` 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 + to update their `{cmd_name}` implementation considering the information in https://setuptools.pypa.io/en/latest/userguide/extension.html about editable installs. -- cgit v1.2.1