• 
      

    Fix dependency patching when run across multiple PEP 517 hooks.

    Review Request #15028 — Created May 7, 2026 and submitted

    Information

    buildthings
    master

    Reviewers

    Since switching to the buildthings backend, running tox in djblets was
    crashing with an assertion "Attempted to patch dependencies too late!"

    The cause here is that pyproject_api invokes build hooks multiple times
    in a single worker process, so the earlier get_requires_for_build_*
    hooks instantiate a _ConfigExpander (via Distribution) before
    prepare_metadata_for_build_wheel calls
    patch_setuptools_package_deps(). The "already initialized" assertion
    fired in that case, even though the next _ConfigExpander instance (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
      tox successfully.
    • Ran unit tests.
    Summary ID
    Fix dependency patching when run across multiple PEP 517 hooks.
    Since switching to the buildthings backend, running `tox` in djblets was crashing 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_*` hooks instantiate a `_ConfigExpander` (via `Distribution`) before `prepare_metadata_for_build_wheel` calls `patch_setuptools_package_deps()`. The "already initialized" assertion fired in that case, even though the next `_ConfigExpander` instance (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. Testing Done: - Built a package and put it in my `$PIP_FIND_LINKS`. Was able to run `tox` successfully. - Ran unit tests.
    qmzolnttkkvuotwruqlkmqtmzusrqymw
    Description From Last Updated

    Typo: "Unfortanetly"

    chipx86 chipx86

    This is where I started deep-diving a couple days ago and got distracted. I looked at all the tools in …

    chipx86 chipx86

    This is mostly a duplicate of the docs. We can probably simplify this.

    chipx86 chipx86

    Typo: "OTHrewise"

    chipx86 chipx86

    If we global this, we can just assign to a new list.

    chipx86 chipx86

    Going to bump to 1.1 for the dependency fixes. Same below.

    chipx86 chipx86
    chipx86
    1. 
        
    2. buildthings/setuptools_patches.py (Diff revision 1)
       
       
       
      Show all issues

      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 own pyproject_api invokes each hook in a separate subprocess. Most use pyproject_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.

    3. buildthings/setuptools_patches.py (Diff revision 1)
       
       
       
       
       
       
       
       
       
       
       
       
      Show all issues

      This is mostly a duplicate of the docs. We can probably simplify this.

    4. buildthings/setuptools_patches.py (Diff revision 1)
       
       
      Show all issues

      Typo: "OTHrewise"

    5. buildthings/setuptools_patches.py (Diff revision 1)
       
       
       
      Show all issues

      If we global this, we can just assign to a new list.

    6. tests/test_setuptools_patches.py (Diff revision 1)
       
       
       
      Show all issues

      Going to bump to 1.1 for the dependency fixes.

      Same below.

    7. 
        
    david
    chipx86
    1. 
        
    2. buildthings/setuptools_patches.py (Diff revisions 1 - 2)
       
       
      Show all issues

      Typo: "Unfortanetly"

      1. Wow, that's quite a typo. Wonder how I did that.

    3. 
        
    david
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to master (2125935)