Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7408ed7
Detect apps that provide a uv.lock
dominikmuellerdmde Sep 28, 2026
fef0e3d
Install dependencies from uv.lock
dominikmuellerdmde Sep 28, 2026
0fadfde
Use .python-version to select the Python version of uv apps
dominikmuellerdmde Sep 28, 2026
563dcaf
Pass package indexes from uv.lock to pip
dominikmuellerdmde Sep 28, 2026
13c9b0e
Add integration tests for uv apps
dominikmuellerdmde Sep 28, 2026
eb04932
Document uv support in README
dominikmuellerdmde Sep 28, 2026
2494acf
Match package names in requirements case-insensitively
dominikmuellerdmde Sep 28, 2026
9afebfa
Run collectstatic for apps with a generated requirements.txt
dominikmuellerdmde Sep 28, 2026
7837d67
Install uv apps with uv sync
dominikmuellerdmde Sep 28, 2026
93dd19c
Install vendored uv apps offline with hash verification
dominikmuellerdmde Sep 28, 2026
7397cdf
Extend integration tests for uv sync
dominikmuellerdmde Sep 28, 2026
926c4aa
Update README for uv sync
dominikmuellerdmde Sep 28, 2026
33e68ff
Install uv from the wheel shipped in the manifest
dominikmuellerdmde Oct 26, 2026
cab5799
Address review feedback on uv support
dominikmuellerdmde Oct 28, 2026
708baa2
Fail staging for unsupported versions in .python-version
dominikmuellerdmde Nov 4, 2026
1090b72
Install uv into a unique temporary directory
dominikmuellerdmde Nov 4, 2026
4a74f72
Share the package selection of uv export and uv sync
dominikmuellerdmde Nov 4, 2026
49ff37b
Match package names with dots and extras in requirements
dominikmuellerdmde Nov 4, 2026
533b656
Require pyproject.toml for uv apps in all supply steps
dominikmuellerdmde Nov 4, 2026
93e795f
Fail early for uv apps with an empty vendor directory
dominikmuellerdmde Nov 4, 2026
4db398c
Regenerate the uv_django lockfile with uv 0.13.5
dominikmuellerdmde Nov 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ This buildpack supports running Django and Flask apps.

Official buildpack documentation can be found at [python buildpack docs](http://docs.cloudfoundry.org/buildpacks/python/index.html).

### uv

Apps managed with [uv](https://docs.astral.sh/uv/) are supported by pushing the `pyproject.toml` together with a `uv.lock`:

* During staging the buildpack runs `uv sync --frozen` to install the locked packages into the buildpack's Python installation. Every package is verified against the hashes in `uv.lock`, and staging fails on a mismatch. Keep `uv.lock` up to date (`uv lock`) before pushing, as it is used as is.
* Only the default dependencies are installed, dependency groups such as `dev` are skipped. If the project defines a `[build-system]`, the project itself is installed as well (non-editable).
* The Python version is taken from `.python-version` (e.g. `3.12`, as written by `uv python pin`), unless a `runtime.txt` exists. Only CPython versions like `3.12` or `3.12.4` are supported; staging fails for other values (e.g. `pypy@3.10` or `>=3.11`). uv never downloads its own Python; staging fails if the version does not satisfy `requires-python`.
* Package indexes configured via `[[tool.uv.index]]` are used as configured. Credentials are not part of `uv.lock`; provide them as environment variables, e.g. `cf set-env <app> UV_INDEX_<NAME>_USERNAME ...` and `UV_INDEX_<NAME>_PASSWORD`. uv trusts the system certificate store, like pip does.
* Django's `collectstatic`, as well as the installation of libffi and libmemcached, work as for pip apps. They are detected from the packages exported from `uv.lock` with the same selection as `uv sync`. Packages restricted by environment markers (e.g. `sys_platform == 'win32'`) are taken into account for detection even if their markers do not match, but are only installed if they do.
* If the app also contains a `requirements.txt`, the `uv.lock` and `.python-version` are ignored and pip is used. Both `pyproject.toml` and `uv.lock` are required for the app to be treated as a uv app.
* For vendored (offline) installs, download the wheels for the target platform into the `vendor` directory. They are installed with `uv pip install --offline` from the packages exported from `uv.lock`, which are the same packages as installed by `uv sync`, and are verified against the hashes in `uv.lock` as well. Staging fails if the `vendor` directory is empty. Write the exported file outside the app, so that it does not take precedence over `uv.lock`:

```bash
uv export --frozen --no-dev --no-hashes --no-emit-project -o /tmp/requirements.txt
pip download -r /tmp/requirements.txt -d vendor --only-binary=:all: --platform manylinux2014_x86_64 --python-version 3.12
```

If the project defines a `[build-system]`, its build backend (e.g. `hatchling`) must be vendored as well.

## Adding new dependencies

If you want to add a new dependency to the buildpack, please add it to the [config.yml](https://github.com/cloudfoundry/buildpacks-ci/blob/5a63d13df09f83d5dff7c71d0a12c3e2dc798d39/pipelines/dependency-builds/config.yml#L272) file. For example, if you want to add a new version of Python, add an entry like the following:
Expand Down
2 changes: 1 addition & 1 deletion bin/detect
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BUILD_DIR=$1
BP=$(dirname $(dirname $0))

# Exit early if app is clearly not Python.
if [ ! -f $BUILD_DIR/requirements.txt ] && [ ! -f $BUILD_DIR/setup.py ] && [ ! -f $BUILD_DIR/environment.yml ] && [ ! -f $BUILD_DIR/Pipfile ]; then
if [ ! -f $BUILD_DIR/requirements.txt ] && [ ! -f $BUILD_DIR/setup.py ] && [ ! -f $BUILD_DIR/environment.yml ] && [ ! -f $BUILD_DIR/Pipfile ] && { [ ! -f $BUILD_DIR/uv.lock ] || [ ! -f $BUILD_DIR/pyproject.toml ]; }; then
exit 1
fi

Expand Down
2 changes: 2 additions & 0 deletions fixtures/uv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
.venv
1 change: 1 addition & 0 deletions fixtures/uv/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
1 change: 1 addition & 0 deletions fixtures/uv/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn server:app
14 changes: 14 additions & 0 deletions fixtures/uv/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "uv-app"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
"flask",
"gunicorn",
"colorama; sys_platform == 'win32'",
]

[dependency-groups]
dev = [
"pytest",
]
18 changes: 18 additions & 0 deletions fixtures/uv/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

from flask import Flask

app = Flask(__name__)

port = int(os.getenv('VCAP_APP_PORT', 8080))


@app.route("/")
def hello():
return "Hello, World!"


app.debug = True

if __name__ == '__main__':
app.run(host='0.0.0.0', port=port)
328 changes: 328 additions & 0 deletions fixtures/uv/uv.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions fixtures/uv_django/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
.venv
static_root
1 change: 1 addition & 0 deletions fixtures/uv_django/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: waitress-serve --port=$PORT django_web_app.wsgi:application
Empty file.
16 changes: 16 additions & 0 deletions fixtures/uv_django/django_web_app/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for django_web_app project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_web_app.settings')

application = get_asgi_application()
119 changes: 119 additions & 0 deletions fixtures/uv_django/django_web_app/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"""
Django settings for django_web_app project.

Generated by 'django-admin startproject' using Django 4.1.5.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-1&02gvsqhx5gvh44@)x%k03&79r*vkievzv0%yl*+vq5m)unm_'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'django_web_app.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'django_web_app.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = 'static_root'

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
21 changes: 21 additions & 0 deletions fixtures/uv_django/django_web_app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""django_web_app URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
path('admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions fixtures/uv_django/django_web_app/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for django_web_app project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_web_app.settings')

application = get_wsgi_application()
22 changes: 22 additions & 0 deletions fixtures/uv_django/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_web_app.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions fixtures/uv_django/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
name = "uv-django-app"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
"dj-database-url==1.2.0",
"Django==4.1.5",
"gunicorn==20.1.0",
"waitress==2.1.2",
"whitenoise==6.3.0",
]
Loading
Loading