Skip to content

fix(python): force Poetry buildpack via GOOGLE_PYTHON_PACKAGE_MANAGER#464

Merged
davideme merged 6 commits intomainfrom
python-force-poetry-buildpack
Mar 21, 2026
Merged

fix(python): force Poetry buildpack via GOOGLE_PYTHON_PACKAGE_MANAGER#464
davideme merged 6 commits intomainfrom
python-force-poetry-buildpack

Conversation

@davideme
Copy link
Copy Markdown
Owner

Summary

  • Despite poetry.lock and [tool.poetry] being present, the google-24 buildpack was falling back to the pip layer and auto-detecting gunicorn — leaving fastapi and all other dependencies uninstalled at runtime
  • Adds --env=GOOGLE_PYTHON_PACKAGE_MANAGER=poetry to the pack build step to explicitly activate the Poetry buildpack
  • With Poetry active, poetry.lock is used to install all dependencies and [tool.poetry.scripts] start becomes the container entrypoint (poetry run startopenapi_server.cli:main)

Root cause

The Google Cloud buildpack documentation states the Poetry buildpack activates automatically when poetry.lock + pyproject.toml or [tool.poetry] is present — but in practice the google-24 builder was ignoring these signals and falling back to pip framework auto-detection.

Test plan

  • Cloud Build log shows Poetry buildpack layer (/layers/google.python.poetry/) instead of pip layer
  • All dependencies including fastapi and opentelemetry-* are installed
  • Container starts with poetry run start and uvicorn (not gunicorn)
  • GET /health returns 200

🤖 Generated with Claude Code

… env var

Despite poetry.lock and [tool.poetry] being present, the google-24 buildpack
was falling back to the pip layer and auto-detecting gunicorn, leaving fastapi
and all other dependencies uninstalled.

Setting GOOGLE_PYTHON_PACKAGE_MANAGER=poetry in the pack build step explicitly
activates the Poetry buildpack, which installs all dependencies from poetry.lock
and uses the [tool.poetry.scripts] start entry as the container entrypoint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 21, 2026 09:17
Copy link
Copy Markdown
Contributor

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 PR updates the Python Cloud Build configuration to explicitly force Google’s buildpacks builder to use the Poetry package manager during pack build, preventing fallback to pip-based framework auto-detection and missing runtime dependencies.

Changes:

  • Adds --env=GOOGLE_PYTHON_PACKAGE_MANAGER=poetry to the pack build invocation for the Python service.

davideme and others added 5 commits March 21, 2026 11:55
…bility

The Poetry buildpack (google.python.poetry@0.1.0) fails to activate in
Cloud Run's builder, falling back to pip framework auto-detection which
only installs gunicorn without project dependencies. Restoring
requirements.txt ensures the pip buildpack installs all dependencies,
including OpenTelemetry packages added in #458.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…yaml

Reverting the Poetry buildpack override since we're restoring requirements.txt
to let the pip buildpack handle dependencies as before.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…entation

httpx was in the dev group but is required at runtime by
opentelemetry-instrumentation-httpx. Moved to main dependencies and
regenerated requirements.txt and poetry.lock.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a note in src/python/README.md (Cloud Run section) and AGENTS.md
explaining that requirements.txt must be regenerated with:
  poetry export --without-hashes --without dev -f requirements.txt -o requirements.txt
after any dependency change, and committed alongside pyproject.toml/poetry.lock.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Starlette raises "Cannot add middleware after an application has started"
when instrument_app() is called inside the lifespan handler. Middleware
must be registered before the app starts, so moved the call to module
level immediately after the FastAPI app is created.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@davideme davideme merged commit 4b0a734 into main Mar 21, 2026
4 checks passed
@davideme davideme deleted the python-force-poetry-buildpack branch March 21, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants