Conversation
Adds support for the package manager uv: https://docs.astral.sh/uv/ This specifically adds support for uv's project mode (`uv sync`), which uses a lockfile rather then a `requirements.txt` file: https://docs.astral.sh/uv/guides/projects/ (While uv does have a pip compatible mode that supports requirements files, using a lockfile is a best practice for deploying an app, and not using one means losing most of the benefits of using uv.) Apps must have a `pyproject.toml`, `uv.lock` and `.python-version` file (all of which are created by default by `uv init` followed by either `uv lock` or any of the other commands that sync/update the lockfile). We don't support omitting the `.python-version` file when using uv, since otherwise it leads to a much worse UX in several cases. (For example, when the buildpack default version differs from `requires-python` in the `pyproject.toml` file, particularly when `requires-python` happens to also match the distro Python in the underlying base image.) The buildpack installs dependencies using `uv sync --locked --no-default-groups`, to ensure development/test dependencies are not installed. We don't use `--no-dev` instead, since that only excludes the `dev` group, and some apps may be using other group names and have added them to uv's `default-groups` in `pyproject.toml` so that local development workflows work with a plain `uv sync` with no additional args. (PEP 735 doesn't actually prescribe recommended group names, and in fact uses `test` in its example rather than `dev`, so non-standard names may be common.) For more on uv's dependency group behaviour, see: https://docs.astral.sh/uv/concepts/projects/dependencies/#dependency-groups uv is installed into a build-only layer, so is not available at run-time (since it's not typically needed at run-time and doing so reduces the image size). Both Python and the entrypoints of installed dependencies are available on `PATH`, so use of `uv run` is not required at run-time to use dependencies in the environment. I've marked this `semver: major` since in the (probably unlikely) event there are projects using this CNB that have both a `uv.lock` and also either a `requirements.txt` or `poetry.lock`, then this change will cause their builds to error (until one of the files is deleted). Closes #248. GUS-W-17141085.
Malax
approved these changes
May 13, 2025
Merged
heroku-linguist bot
added a commit
to heroku/cnb-builder-images
that referenced
this pull request
May 13, 2025
## heroku/python ### Added - Added support for the package manager uv. ([#362](heroku/buildpacks-python#362))
Member
Author
|
Dev Center updates: Changelog announcement: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(This is the CNB equivalent of heroku/heroku-buildpack-python#1791)
Adds support for the package manager uv:
https://docs.astral.sh/uv/
...which has (very justifiably!) become extremely popular in the last year:
This specifically adds support for uv's project mode (
uv sync), which uses a lockfile rather then arequirements.txtfile: https://docs.astral.sh/uv/guides/projects/(While uv does have a pip compatible mode that supports requirements files, using a lockfile is a best practice for deploying an app, and not using one means losing most of the benefits of using uv.)
Apps must have a
pyproject.toml,uv.lockand.python-versionfile (all of which are created by default byuv initfollowed by eitheruv lockor any of the other commands that sync/update the lockfile).We don't support omitting the
.python-versionfile when using uv, since otherwise it leads to a much worse UX in several cases. (For example, when the buildpack default version differs fromrequires-pythonin thepyproject.tomlfile, particularly whenrequires-pythonhappens to also match the distro Python in the underlying base image.)The buildpack installs dependencies using
uv sync --locked --no-default-groups, to ensure development/test dependencies are not installed.We don't use
--no-devinstead, since that only excludes thedevgroup, and some apps may be using other group names and have added them to uv'sdefault-groupsinpyproject.tomlso that local development workflows work with a plainuv syncwith no additional args. (PEP 735 doesn't actually prescribe recommended group names, and in fact usestestin its example rather thandev, so non-standard names may be common.)For more on uv's dependency group behaviour, see:
https://docs.astral.sh/uv/concepts/projects/dependencies/#dependency-groups
uv is installed into a build-only layer, so is not available at run-time (since it's not typically needed at run-time and doing so reduces the image size). Both Python and the entrypoints of installed dependencies are available on
PATH, so use ofuv runis not required at run-time to use dependencies in the environment.I've marked this
semver: majorsince in the (probably unlikely) event there are projects using this CNB that have both auv.lockand also either arequirements.txtorpoetry.lock, then this change will cause their builds to error (until one of the files is deleted).Closes #248.
GUS-W-17141085.
Note: This repository is for the Python CNB (Cloud Native Buildpack) used by Fir-generation apps on Heroku. For uv support for Cedar-Generation apps, see the classic Python buildpack's PR instead.