feat(cli): add --python_version option to adk deploy commands#4792
feat(cli): add --python_version option to adk deploy commands#4792JesserHamdaoui wants to merge 5 commits intogoogle:mainfrom
Conversation
Adds a --python_version CLI flag to both `adk deploy cloud_run` and `adk deploy gke` commands. Previously the Dockerfile base image was hardcoded to `python:3.11-slim`, making it impossible to deploy agents that require a newer Python version. Defaults to "3.11" to preserve existing behaviour. Fixes google#4784
…ython_version assertions Adds test coverage for the new --python_version option in both to_cloud_run and to_gke deploy functions, as well as the CLI wiring. - Asserts correct rendering of the python_version in the Dockerfile template - Verifies CLI passthrough for --python_version on both cloud_run and gke commands - Ensures default and custom values are handled as expected Related to google#4784
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a --python_version option to the adk deploy commands to allow specifying the Python version for the Docker base image. My review focuses on improving code maintainability and test coverage. I've identified an unused parameter, an opportunity to refactor duplicated code, and a missing unit test. Please see the specific comments for details.
| @click.option( | ||
| "--python_version", | ||
| type=str, | ||
| default="3.11", | ||
| show_default=True, | ||
| help=( | ||
| "Optional. The Python version used in the Docker base image." | ||
| " (default: 3.11)" | ||
| ), | ||
| ) |
There was a problem hiding this comment.
This @click.option for --python_version is duplicated for the cli_deploy_gke command as well. To improve maintainability and avoid duplication, consider creating a reusable decorator for this option, similar to how adk_services_options is implemented.
For example:
def python_version_option():
return click.option(
"--python_version",
type=str,
default="3.11",
show_default=True,
help=(
"Optional. The Python version used in the Docker base image."
" (default: 3.11)"
),
)
@deploy.command(...)
@python_version_option()
def cli_deploy_cloud_run(...):
...
@deploy.command(...)
@python_version_option()
def cli_deploy_gke(...):
...This change would make the code more DRY (Don't Repeat Yourself).
There was a problem hiding this comment.
I'm not sure if I should implement this or stick to the existing pattern used for the other flag parameters
19eb7f2 to
637a611
Compare
Summary
1. Link to an existing issue:
Problem:
The Dockerfile template used in
adk deploy cloud_runandadk deploy gkehardcodedpython:3.11-slimas the base image. This made it impossible to deploy agents that require a newer Python runtime (e.g., 3.12, 3.13) without manually patching the generated Dockerfile.Solution:
Parameterize the Dockerfile base image by adding a
--python_versionCLI option to bothadk deploy cloud_runandadk deploy gke. The option defaults to"3.11"to preserve existing behavior._DOCKERFILE_TEMPLATEincli_deploy.py: replacedpython:3.11-slimwithpython:{python_version}-slim.to_cloud_run()andto_gke(): addedpython_version: str = "3.11"parameter, forwarded to the template.format()call.cli_deploy_cloud_runandcli_deploy_gkeincli_tools_click.py: added@click.option("--python_version", ...)withdefault="3.11", forwarded to the deploy functions.Usage:
Testing Plan
Unit Tests:
Updated 3 existing test files:
test_cli_deploy_to_cloud_run.py: updated happy path to passpython_version="3.12"and assertFROM python:3.12-slimin the Dockerfile; addedtest_to_cloud_run_default_python_versionto verify the3.11default.test_cli_deploy.py: updated GKE happy path to passpython_version="3.12"and assertFROM python:3.12-slim.test_cli_tools_click.py: addedtest_cli_deploy_cloud_run_python_versionandtest_cli_deploy_gke_python_versionto verify--python_versionis forwarded correctly.