From 2549604f2fce880f26fd4e0bd3c58b809ccd8a30 Mon Sep 17 00:00:00 2001 From: Richard Si Date: Thu, 1 May 2025 20:33:36 -0400 Subject: [PATCH 1/2] Short-circuit get_requires hooks when there are no extra build dependencies The PEP 517 get_requires_for_build_(wheel|sdist) hooks function by running the egg_info command with a patched Distribution that raises a special exception when build dependencies (from setup_requires) are about to be installed. This works great at minimizing the overhead of the requires hooks... except when there are no dynamic build dependencies. In such a situation, the injected install_build_eggs() shim that raises SetupRequirementsError is never invoked, thus the entire egg_info command will execute. This often results in substantial overhead for modern projects that use [build-system].requires and not setup_requires. --- newsfragments/4973.feature.rst | 2 ++ setuptools/__init__.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 newsfragments/4973.feature.rst diff --git a/newsfragments/4973.feature.rst b/newsfragments/4973.feature.rst new file mode 100644 index 0000000000..e88c7db29f --- /dev/null +++ b/newsfragments/4973.feature.rst @@ -0,0 +1,2 @@ +PEP 517 ``get_requires_for_build_sdist`` and ``get_requires_for_build_wheel`` hooks +now terminate as soon as it is determined there are no extra build dependencies. diff --git a/setuptools/__init__.py b/setuptools/__init__.py index f1b9bfe9b8..f75a78f5bb 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -83,8 +83,11 @@ def finalize_options(self): # Honor setup.cfg's options. dist.parse_config_files(ignore_option_errors=True) - if dist.setup_requires: - _fetch_build_eggs(dist) + # NOTE: fetch_build_eggs is called so even if there are no build + # requirements, get_requires_for_build_(sdist/wheel) will still + # short-circuit once build dependencies are known (avoiding the + # costly full execution of setup.py). + _fetch_build_eggs(dist) def _fetch_build_eggs(dist: Distribution): From bdfb0a7d0e23385f2011a0bc29910ed14e99958d Mon Sep 17 00:00:00 2001 From: Richard Si Date: Mon, 19 May 2025 16:38:36 -0400 Subject: [PATCH 2/2] Ensure dist-info command can be bootstrapped --- bootstrap.egg-info/entry_points.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/bootstrap.egg-info/entry_points.txt b/bootstrap.egg-info/entry_points.txt index a21ca22709..c84c0e8ab9 100644 --- a/bootstrap.egg-info/entry_points.txt +++ b/bootstrap.egg-info/entry_points.txt @@ -1,5 +1,6 @@ [distutils.commands] egg_info = setuptools.command.egg_info:egg_info +dist_info = setuptools.command.dist_info:dist_info build_py = setuptools.command.build_py:build_py sdist = setuptools.command.sdist:sdist editable_wheel = setuptools.command.editable_wheel:editable_wheel