Skip to content

feat: uv support for Flask, Django and FastAPI extensions - #1308

Draft
Thanhphan1147 wants to merge 6 commits into
canonical:mainfrom
Thanhphan1147:feature/uv-support
Draft

feat: uv support for Flask, Django and FastAPI extensions#1308
Thanhphan1147 wants to merge 6 commits into
canonical:mainfrom
Thanhphan1147:feature/uv-support

Conversation

@Thanhphan1147

Copy link
Copy Markdown
Contributor

Summary

Adds uv build support to the Flask, Django and FastAPI framework extensions. When a project ships both uv.lock and pyproject.toml, the extension builds the dependencies part with the uv plugin (uv sync) instead of the python plugin, and injects the server dependency (gunicorn~=23.0 / uvicorn) via a post-build override-build step since the lockfile is the source of truth.

Behavior

  • uv.lock + pyproject.toml → build with uv plugin.
  • pyproject.toml only → fall back to the python (pip) plugin (unchanged).
  • uv.lock without pyproject.toml → pack fails: "the plugin requires both uv.lock and pyproject.toml to be present".
  • Django/FastAPI no longer require requirements.txt for uv projects.

Testing

  • Unit tests for detection, part generation and validation across all three extensions.
  • make lint passes; extension unit tests pass.
  • Manual e2e on a Canonical k8s cluster: built a Flask uv rock, pushed to an in-cluster registry, ran it as a pod, and confirmed HTTP 200 served by gunicorn 23.0.0.

Copilot AI review requested due to automatic review settings July 20, 2026 16:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds uv-based build support to the Flask, Django, and FastAPI framework extensions so that projects with both uv.lock and pyproject.toml use the uv plugin for dependency installation, while preserving existing pip/python plugin behavior when uv.lock is absent.

Changes:

  • Add uv project detection + validation helpers (uses_uv, validate_uv_lockfile) and wire them into Flask/Django/FastAPI extension validation/part generation.
  • Switch dependency parts to use the uv plugin when appropriate, injecting gunicorn/uvicorn via override-build for locked (uv) projects.
  • Add unit tests and documentation sections describing uv behavior for all three extensions.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/extensions/test_python_utils.py New unit tests for uv detection/validation helpers.
tests/unit/extensions/test_gunicorn.py Adds Flask/Django uv-project tests and error-case coverage.
tests/unit/extensions/test_fastapi.py Adds FastAPI uv-project tests and error-case coverage.
rockcraft/extensions/gunicorn.py Uses uv plugin for deps when uv.lock+pyproject.toml are present; validates lockfile pairing.
rockcraft/extensions/fastapi.py Uses uv plugin for deps when uv.lock+pyproject.toml are present; skips requirements.txt checks for uv projects.
rockcraft/extensions/_python_utils.py Introduces uses_uv() and validate_uv_lockfile() helpers.
docs/reference/extensions/flask-framework.rst Documents uv project behavior for Flask extension.
docs/reference/extensions/django-framework.rst Documents uv project behavior for Django extension.
docs/reference/extensions/fastapi-framework.rst Documents uv project behavior for FastAPI extension.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +202 to +204
return (project_root / "uv.lock").exists() and (
project_root / "pyproject.toml"
).exists()
Comment on lines +213 to +215
if (project_root / "uv.lock").exists() and not (
project_root / "pyproject.toml"
).exists():
Signed-off-by: Phan Trung Thanh <trung.thanh.phan@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants