Skip to content

How to build a project wheel with pinned dependencies? #310

Closed

Description

@diogobaeder

Hi!

I'm using polylith in a system together with uv and hatchling. One thing I'm struggling with is that, while in development I end up with a uv lock file for development (at the root), I haven't figured out a way to have a lock file for each project so that I can get wheel distributions with pinned dependencies. The reason why this is a problem for me is that I end up with a non-deterministic build process, and yesterday I had issues with this because my local environment was working fine but not my staging environment because of diverging dependency versions.

So how can I lock each project with its own lock file, to ensure deterministic builds, while not having to forcefully pin each dependency in pyproject.toml?

Thanks!

Activity

  1. DavidVujic commented on Dec 8, 2024

    @DavidVujic
    Owner

    Hi @diogobaeder! I think that one way to accomplish this is to opt-out of the uv workspaces feature (if you use that) and have separate uv.lock files that are updated individually.

    Another option is to export the project-specific deps before building the wheel. I think that you can do something like this:

    # running from the folder of a project.
    
    # export the dependecies
    uv export --no-emit-project --output-file requirements.txt
    
    #build the distribution (wheel/sdist)
    uv build --out-dir ./dist

    When installing the wheel (example from a Dockerfile):

    # Install with no deps. Removed other useful standard pip install flags in this example
    RUN pip install --no-deps the-built-wheel-from-before.whl
    
    # install the third-party deps separately
    RUN pip install -r requirements.txt

    I am not yet using uv myself that much, so I might have missed out on something. Please let me know if you find anything missing, and if this suggestion works 😄

  2. diogobaeder commented on Dec 9, 2024

    @diogobaeder
    Author

    Awesome, thanks man! I'll give those a try. I'm using Tilt locally, to develop multiple services together, so what you explained above is very helpful. Cheers!

  3. DavidVujic commented on Dec 9, 2024

    @DavidVujic
    Owner

    (I will move this to Discussions and the Q&A section, to have it available for other users)

  4. Repository owner locked and limited conversation to collaborators on Dec 9, 2024
  5. converted this issue into a discussion #312 on Dec 9, 2024
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions