Fix dependency patching when run across multiple PEP 517 hooks.
Review Request #15028 — Created May 7, 2026 and submitted
Since switching to the buildthings backend, running
toxin djblets was
crashing with an assertion "Attempted to patch dependencies too late!"The cause here is that
pyproject_apiinvokes build hooks multiple times
in a single worker process, so the earlierget_requires_for_build_*
hooks instantiate a_ConfigExpander(viaDistribution) before
prepare_metadata_for_build_wheelcalls
patch_setuptools_package_deps(). The "already initialized" assertion
fired in that case, even though the next_ConfigExpanderinstance (the
one we actually want to patch) has not been built yet.This change gets rid of the assertion, and clears the post-funcs list
before appending so deps don't stack across hook calls in the same
worker.
- Built a package and put it in my
$PIP_FIND_LINKS. Was able to run
toxsuccessfully. - Ran unit tests.
| Summary | ID |
|---|---|
| qmzolnttkkvuotwruqlkmqtmzusrqymw |
| Description | From | Last Updated |
|---|---|---|
|
Typo: "Unfortanetly" |
|
|
|
This is where I started deep-diving a couple days ago and got distracted. I looked at all the tools in … |
|
|
|
This is mostly a duplicate of the docs. We can probably simplify this. |
|
|
|
Typo: "OTHrewise" |
|
|
|
If we global this, we can just assign to a new list. |
|
|
|
Going to bump to 1.1 for the dependency fixes. Same below. |
|
-
-
This is where I started deep-diving a couple days ago and got distracted.
I looked at all the tools in this space that I could find, including
uv, and every one of them with the exception of tox's ownpyproject_apiinvokes each hook in a separate subprocess. Most usepyproject_hooks, which is the official Python module for this work, and the rest roll their own using the same one-process-per-hook approach.tox is the odd one out. Let's document that for now, so we can track that.
-
-
-
-
- Description:
-
Since switching to the buildthings backend, running
toxin djblets wascrashing with an assertion "Attempted to patch dependencies too late!" ~ The cause here is that PEP 517 frontends like pyproject_api keep one
~ worker process across hooks, so the earlier get_requires_for_build_*~ The cause here is that
pyproject_apiinvokes build hooks multiple times~ in a single worker process, so the earlier get_requires_for_build_*hooks instantiate a _ConfigExpander(viaDistribution) beforeprepare_metadata_for_build_wheelcallspatch_setuptools_package_deps(). The "already initialized" assertionfired in that case, even though the next _ConfigExpanderinstance (theone we actually want to patch) has not been built yet. This change gets rid of the assertion, and clears the post-funcs list
before appending so deps don't stack across hook calls in the same worker. - Commits:
-
Summary ID qmzolnttkkvuotwruqlkmqtmzusrqymw qmzolnttkkvuotwruqlkmqtmzusrqymw