Skip to content

Locking of build dependencies #5190

Open

Description

@sbidoul

Coming from #3611 (comment) and following comments.

Caveat: this is certainly not a complete proposal, and I reckon I have not investigated the capabilities of uv lock/sync in any detail, so consider this as thoughts to start the conversation on the usefulness of such features.

What

The uv.lock format supports locking source distributions (from sdists, git source trees, ...). This is great!

I would find it useful that

  • commands that install from a lock file fail (by default?) if they need to install build dependencies that are not locked
  • the lock command grows a mean to lock the build system requirements of the source dependencies declared in the lock file it produces

Why

When installing from a lock file I expect that everything that the installation downloads (or obtains from cache) is checked against the hashes (or immutable VCS commit hashes) that are present in the lock file, for repeatability and security.

If, during installation, other artifacts are downloaded (or obtained from cache) without my knowledge (to build source distributions), the security and repeatability of the process is weakened.

Some thoughts

  • this may have performance implications for the lock command if sdists have to be downloaded to know the build requirements (universal-lock: clean up lock file format #3611 (comment))
  • some build dependencies are dynamic (get_requires_for_build_{wheel,editable}), further complicating the locking operation
  • different locked source distributions may require different versions of the same build dependency
  • a first valuable step could be to lock build dependencies for which no wheel is available, and warn when an artifact that is not locked is downloaded when syncing

Activity

  1. paveldikov commented on Jul 21, 2024

    @paveldikov
    Contributor

    I was going to raise this same issue as well. Currently build-system.requires is completely unconstrained/unconstrainable and this is causing problems with build reproducibility.

    This is causing real-life inconveniences in our organisation as, for example, new versions of setuptools appear but are not yet given the all-clear by our scanning suite. Versions that are not cleared yield a HTTP 403 upon download. The end result is a de-facto intractable state where no one can build (or even editably install) packages. (unless the developer decides to hard-constrain @ pyproject.toml, which is terrible UX and also doesn't help with the dependency-on-sdist problem.)

    (I will probably also raise a separate issue w.r.t the handling of 403 codes -- this is a pain point with pip and it would be awesome if uv could do better)

  2. charliermarsh commented on Jul 28, 2024

    @charliermarsh
    Member

    Definitely agree that we should do this.

  3. charliermarsh commented on Sep 10, 2024

    @charliermarsh
    Member

    I really want to do this (lock the build requirements).

  4. vlad-ivanov-name commented on Nov 15, 2024

    @vlad-ivanov-name

    This is becoming more relevant with newer python versions that don't ship setuptools by default anymore

  5. charliermarsh commented on Nov 15, 2024

    @charliermarsh
    Member

    I really want to do this and would like to spend time on it personally, but I'm worried about how it will intersect with PEP 751.

  6. vlad-ivanov-name commented on Nov 15, 2024

    @vlad-ivanov-name

    Hmm but that's more about lockfiles in general, not specific to build-time deps?

    Correct me if I'm wrong but to me this PEP looks to be in early stages, and uv.lock looks way more mature as it is now. I would expect the introduction of this PEP to be orthogonal to the goal of being able to lock build dependencies - in the end if uv does decide to adopt the format, the build dependency group will probably be locked in a similar way to other dependency groups regardless of the final lock file format

  7. notatallshaw commented on Nov 15, 2024

    @notatallshaw
    Collaborator

    I really want to do this and would like to spend time on it personally, but I'm worried about how it will intersect with PEP 751.

    Last I saw build time dependencies were dropped from PEP 751: https://discuss.python.org/t/pep-751-lock-files-again/59173/222 (end of that post).

    I don't think anything changed: https://peps.python.org/pep-0751/#locking-build-requirements-for-sdists (FYI I really hope the "it confused enough people " isn't directed at me, I had some clarifying questions, and was mostly happy with the answers).

  8. charliermarsh commented on Nov 15, 2024

    @charliermarsh
    Member

    @notatallshaw -- No, I agree with you, it's just that: if we add support for it here, what happens if PEP 751 comes out and we can't translate that support to the PEP?

  9. bluss commented on Nov 15, 2024

    @bluss
    Contributor

    Could you use the space for tool specific data in the PEP 751 lock file? Or even using one of the main fields like groups using some kind of convention that makes it possible for locked build deps to co-exist with other named things stored there.

  10. notatallshaw commented on Nov 15, 2024

    @notatallshaw
    Collaborator

    Yeah, makes sense to see the finalized version of PEP 751 first.

  11. vlad-ivanov-name commented on Nov 16, 2024

    @vlad-ivanov-name

    what happens if PEP 751 comes out and we can't translate that support to the PEP?

    I mean, this wouldn't be the first feature that uv supports that vanilla python tooling doesn't. This is important enough to implement regardless of what python itself does; after all, even locking of regular dependencies is not really supported out of the box, doesn't mean that uv should be restricted by that

  12. dimbleby commented on Nov 19, 2024

    @dimbleby

    similar proposals in poetry, pdm: python-poetry/poetry#8261 (and several duplicates), pdm-project/pdm#2465

    I mostly think that people who care about reproducible builds would be better served by avoiding sdists altogether with --only-binary or similar.

  13. 2 remaining items

  14. purepani commented on Apr 1, 2025

    @purepani

    Since PEP 751 is now accepted, and the resulting lock file isn't immediately usable for uv as a project lock file, perhaps it makes sense to add this as a uv.lock feature.

  15. charliermarsh commented on Apr 1, 2025

    @charliermarsh
    Member

    We're hoping to start working on this soon.

  16. jiridanek commented on Aug 6, 2025

    @jiridanek

    Build contraints help but they'd need to be managed manually, won't work if there are conflicting build constraints in the project, and it's easy to forget a build constraint, which you only realize months or years later when a build fails.

    Building with --require-hashes seems to be a decent check for a forgotten build constraint. With

    ❯ uv --version
    uv 0.8.5
    

    I get, when I use --build-constraints=./requirements.txt --no-binary=:all:

    ❯ uv pip install --strict --no-deps --no-cache --no-config --no-progress --require-hashes --index-strategy=unsafe-best-match --requirements=./requirements.txt --build-constraints=./requirements.txt --no-binary=:all:
    Using Python 3.12.11 environment at: pepa
    Resolved 71 packages in 268ms
       Building nbclient==0.10.2
       Building ptyprocess==0.7.0
       Building typing-extensions==4.14.1
       Building jupyter-core==5.7.2
       Building tinycss2==1.4.0
      × Failed to download and build `nbclient==0.10.2`
      ├─▶ Failed to resolve requirements from `build-system.requires`
      ├─▶ No solution found when resolving: `hatchling>=1.10.0`
      ╰─▶ In `--require-hashes` mode, all requirements must be pinned upfront with `==`, but found: `hatchling`
    

    The above is actually a great inconvenience to me, but I see some may benefit from this behavior.

  17. bruno-fs commented on Aug 8, 2025

    @bruno-fs

    I find it a bit sad that new "universal lockfile format" from PEP 751 won't support locking build requirements for sdists, but I'm glad to hear uv is interested in solving this problem.

  18. added a commit that references this issue on Dec 29, 2025
  19. tleonhardt commented on Mar 4, 2026

    @tleonhardt

    My organization needs this capability to support offline build environments.

  20. jiridanek commented on Apr 15, 2026

    @jiridanek

    I'm having a Chief Architect asking me questions because we could not pin our transitive build-dependencies and meson 1.11 release yesterday broke the pandas 2.3 build

  21. DetachHead commented on Oct 14, 2026

    @DetachHead
    Contributor

    looks like this is now supported with build-constraint-dependencies, but i can't seem to figure out how to actually generate those hashes like you can with uv lock. seems like you need to manually determine the hashes for each build dependency, or am i missing something?

  22. zanieb commented on Oct 14, 2026

    @zanieb
    Member

    It's "supported" in the sense that you can manually achieve locking behavior, but yes, you need to enumerate the hashes by hand (which we're just doing with an agent) — it's an interim solution at best. We're still interested in building this as a first-class feature, it's just hard :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement to existing functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址