From e0b4cebf6de9b896a5ee1f75d1708c14b6ed13a8 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 24 Jun 2022 18:31:55 +0100 Subject: [PATCH] Allow custom-command to "install" itself The comment in https://github.com/pypa/setuptools/issues/2591#issuecomment-791628028 reports that users wanting to use the custom-command plugin need to explicitly add it using `setup.py`. This commit tried to demonstrate how that can be done without requiring the user to change their `setup.py`. The "installation" of the new sub-command is done via the `finalize_distribution_options` hook. --- custom/build.py | 6 ++++++ setup.cfg | 2 ++ 2 files changed, 8 insertions(+) diff --git a/custom/build.py b/custom/build.py index 2302f22..f7e388f 100644 --- a/custom/build.py +++ b/custom/build.py @@ -11,3 +11,9 @@ def finalize_options(self): def run(self): log.info("brrrrrrrrr") + + +def install(dist): + # This could be protected by a opt-in condition... + build = dist.get_command_obj("build") + build.sub_commands = [*build.sub_commands, ("custom-build", None)] diff --git a/setup.cfg b/setup.cfg index 2a9d93f..581323b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,3 +7,5 @@ packages = find_namespace: [options.entry_points] distutils.commands = custom-build = custom.build:Command +setuptools.finalize_distribution_options = + custom-build = custom.build:install