Skip to content

feat: uv builder #5652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 13, 2025
Merged

feat: uv builder #5652

merged 22 commits into from
Apr 13, 2025

Conversation

caarlos0
Copy link
Member

@caarlos0 caarlos0 commented Mar 15, 2025

Initial impl of the UV support.

Questions/commentary

  • Do we need the sdist build as well, specially considering we already have the source archive feature - which I suspect we can setup to add dir.egg-info and setup.cfg and it would be basically the same thing?
  • The default binary comes from the build pipe, and is set to the project name - should we use that, or require the user to inform the py3-none-any.whl part in the config? (current impl mandates that binary from config is ignored)
  • https://github.com/goreleaser/example-uv/releases/tag/v0.1.0 - example release
  • Assuming I want to run it in a Docker container, I know I need to pip install file.whl, but how do I run it afterwards? Might be skill issue, but things like python -m mymod gives me module not found errors...
  • Where inside a deb or rpm package does the .whl and sdist files usually go? Can't find any references for that anywhere - is that even a thing?
  • Is the the sdist file at all useful inside a docker image if you already have the wheel?
  • This is not a common implementation of a builder in GoReleaser. GoReleaser builders usually build binaries, whereas .wheel and sdist are more like packages. Maybe we should actually move them out of the build api restraints?

TODOs

  • docs
  • tests for docker
  • tests for checksums
  • tests for nfpms

@caarlos0 caarlos0 self-assigned this Mar 15, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 15, 2025
@caarlos0 caarlos0 added enhancement New feature or request and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 15, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 15, 2025
Copy link

cloudflare-workers-and-pages bot commented Mar 15, 2025

Deploying goreleaser with  Cloudflare Pages  Cloudflare Pages

Latest commit: b7b71d7
Status: ✅  Deploy successful!
Preview URL: https://31bbd634.goreleaser.pages.dev
Branch Preview URL: https://uv.goreleaser.pages.dev

View logs

@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 15, 2025
Comment on lines +186 to +187
artifact.ByType(artifact.PyWheel),
artifact.ByType(artifact.PySdist),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add tests for this

@ryancurrah
Copy link
Contributor

If it helps, some time this weekend I can take look at your open questions and add feedback.

@caarlos0
Copy link
Member Author

If it helps, some time this weekend I can take look at your open questions and add feedback.

yes it would help a lot!

Thank you @ryancurrah 🙏🏻

@JenspederM
Copy link

FWIW, it seems that tests are currently failing because setup-uv is missing in the workflow.

In regards to running in docker, you'd probably do uv pip install my-module and then invoke it with uv run python -m my-module.

@ryancurrah
Copy link
Contributor

ryancurrah commented Mar 23, 2025

  • Do we need the sdist build as well, specially considering we already have the source archive feature - which I suspect we can setup to add dir.egg-info and setup.cfg and it would be basically the same thing?
    • Yes, generating and uploading source distributions (sdists) to both PyPI and GitHub Releases is recommended. Sdists allow users to build the package on their own systems when a compatible wheel isn't available, ensuring broader compatibility. Unlike generic source archives, sdists integrate directly with Python's packaging tools.
  • The default binary comes from the build pipe, and is set to the project name - should we use that, or require the user to inform the py3-none-any.whl part in the config? (current impl mandates that binary from config is ignored)
    • Seems ok to use project name or define the name in the builds section. A note this change only targets only pure Python packages. Wheel filename structure is {distribution}-{version}-{python tag}-{abi tag}-{platform tag}.whl. In the future it may nice to handle compiled Python project wheel names.
  • Assuming I want to run it in a Docker container, I know I need to pip install file.whl, but how do I run it afterwards? Might be skill issue, but things like python -m mymod gives me module not found errors...
    • You need to rename __main__.py to example_uv.py then python -m example_uv works. If you want to use __main__.py you have to put in a sub-folder named example_uv.
  • Where inside a deb or rpm package does the .whl and sdist files usually go? Can't find any references for that anywhere - is that even a thing?
  • Is the the sdist file at all useful inside a docker image if you already have the wheel?
    • I don't think so unless they want to use that to install package.
  • This is not a common implementation of a builder in GoReleaser. GoReleaser builders usually build binaries, whereas .wheel and sdist are more like packages. Maybe we should actually move them out of the build api restraints?
    • Yeah if build imposes a lot of constraints on configuration you may be right, how will creating python packages work without a build section?

@caarlos0
Copy link
Member Author

caarlos0 commented Apr 1, 2025

thanks for all the good feedback @ryancurrah

do you think its too bad to have to do something like this if you need to build both wheel and sdist?

builds:
  - id: wheel
    builder: uv
    buildmode: wheel
  - id: sdist
    builder: uv
    buildmode: sdist

if you only need wheel, it'll be simply:

builds:
  - builder: uv

gonna also look into compiled wheels as well

@caarlos0 caarlos0 requested a review from Copilot April 1, 2025 03:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request implements initial support for UV builder to produce Python wheel and source distribution (sdist) packages using GoReleaser. Key changes include:

  • Documentation updates for the new UV builder and nfpm configuration.
  • Schema and config changes to support new build modes “wheel” and “sdist”.
  • Implementation and tests for the UV builder, including adjustments in release, docker, and checksum pipelines.

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
www/docs/customization/nfpm.md Added documentation for Python wheel and sdist default paths
www/docs/customization/builds/uv.md Introduced UV builder documentation and usage samples
pkg/config/config.go Updated BuildDetails enum to include “wheel” and “sdist” modes
internal/static/config.uv.yaml Provided example configuration for the UV builder
internal/static/config.go Added UV example config embedding for goreleaser init
internal/pyproject/* Added support for parsing pyproject.toml files and related tests
internal/pipe/release/release.go Included new artifact types (PyWheel and PySdist) for releases
internal/pipe/docker/docker.go Adjusted artifact filtering to include PyWheel in Docker builds
internal/pipe/checksums/checksums.go Included new artifact types for checksum generation
internal/pipe/build/build.go Updated defaults to set internal binary flag for UV builds
internal/builders/uv/* Complete implementation and tests for the new UV builder
internal/builders/common/common.go Updated config validation to allow buildmode for non-Go builders
internal/artifact/artifact.go Added artifact types and String representations for Python packages
cmd/init.go Added support for UV configuration in the initialization command
Files not reviewed (1)
  • internal/builders/uv/testdata/.gitignore: Language not supported

@caarlos0 caarlos0 requested a review from Copilot April 10, 2025 12:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • internal/builders/uv/testdata/.gitignore: Language not supported
Comments suppressed due to low confidence (1)

internal/pipe/docker/docker.go:145

  • Consider reviewing the docker artifact filter: other pipelines include both PyWheel and PySdist, so clarify whether PySdist should be added here as well for consistency.
artifact.ByType(artifact.PyWheel),

var buildFlags []string
var art *artifact.Artifact
switch build.Buildmode {
case "wheel", "":
Copy link
Preview

Copilot AI Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider explicitly setting the default build mode to "wheel" in WithDefaults instead of relying on an empty string value, to remove ambiguity in build mode determination.

Copilot uses AI. Check for mistakes.

Copy link

codecov bot commented Apr 11, 2025

Codecov Report

Attention: Patch coverage is 79.66102% with 36 lines in your changes missing coverage. Please review.

Project coverage is 82.98%. Comparing base (1cecd11) to head (b7b71d7).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
internal/builders/uv/build.go 76.51% 23 Missing and 8 partials ⚠️
cmd/init.go 25.00% 3 Missing ⚠️
internal/artifact/artifact.go 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5652      +/-   ##
==========================================
- Coverage   83.01%   82.98%   -0.03%     
==========================================
  Files         158      160       +2     
  Lines       15564    15753     +189     
==========================================
+ Hits        12920    13073     +153     
- Misses       2088     2116      +28     
- Partials      556      564       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JenspederM
Copy link

Hey @caarlos0,

Love what you are doing here. After using goreleaser (for a go project) for the first time a a few weeks ago I've been completely smitten with your work.

I work as a staff engineer at Halfspace.ai and do a lot of python projects, so this feature would be highly useful for me.

Let me know if I can do anything to help - code, docs, or just some sparring. 😊

@caarlos0
Copy link
Member Author

hey @JenspederM! thanks for the kind words!

in general, please feel free to comment if on anything you feel you have something to add

always good to have more opinions, especially in the Python stuff - which is a tech I don't work with daily

cheers! 🙏🏻

@caarlos0 caarlos0 merged commit 206725a into main Apr 13, 2025
16 of 19 checks passed
@caarlos0 caarlos0 deleted the uv branch April 13, 2025 17:30
@caarlos0 caarlos0 mentioned this pull request Apr 30, 2025
24 tasks
caarlos0 pushed a commit that referenced this pull request Aug 14, 2025
I was about to prepare and send you PRs for Python support… then I
noticed you already added it:
- #5652
- #5734

This PR updates your docs | site
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants