Skip to content

Commit 2549604

Browse files
committed
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.
1 parent ae480ff commit 2549604

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

newsfragments/4973.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PEP 517 ``get_requires_for_build_sdist`` and ``get_requires_for_build_wheel`` hooks
2+
now terminate as soon as it is determined there are no extra build dependencies.

setuptools/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ def finalize_options(self):
8383

8484
# Honor setup.cfg's options.
8585
dist.parse_config_files(ignore_option_errors=True)
86-
if dist.setup_requires:
87-
_fetch_build_eggs(dist)
86+
# NOTE: fetch_build_eggs is called so even if there are no build
87+
# requirements, get_requires_for_build_(sdist/wheel) will still
88+
# short-circuit once build dependencies are known (avoiding the
89+
# costly full execution of setup.py).
90+
_fetch_build_eggs(dist)
8891

8992

9093
def _fetch_build_eggs(dist: Distribution):

0 commit comments

Comments
 (0)