Repository navigation
Refactor Python application entrypoint handling and add support for s… - #12043
Conversation
…cript, module, and executable types
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12043Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12043" |
…t resolution and improve virtual environment integration
…honScript and update related assertions; add Dockerfile generation test for UV environment.
…cript and module entrypoints
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors Python application entrypoint handling in Aspire to provide more explicit control over how Python applications are executed. The change introduces three specific methods for different execution types while maintaining backward compatibility through obsolete methods.
- Adds new entrypoint-specific methods (
AddPythonScript,AddPythonModule,AddPythonExecutable) - Introduces entrypoint type system with annotations and flexible configuration
- Enhances Docker containerization support and VS Code debugging for different entrypoint types
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting.Python/EntrypointType.cs | Defines enum for Python execution types (Script, Module, Executable) |
| src/Aspire.Hosting.Python/PythonEntrypointAnnotation.cs | Internal annotation to store entrypoint configuration |
| src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs | Refactored extension methods with new specific entry methods and obsoleted old ones |
| src/Aspire.Hosting.Python/PythonAppLaunchConfiguration.cs | Enhanced VS Code launch config to support module execution |
| tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs | Comprehensive test updates covering all entrypoint types and scenarios |
| tests/Aspire.Hosting.Python.Tests/Aspire.Hosting.Python.Tests.csproj | Added verification testing dependencies |
| tests/Aspire.Hosting.Python.Tests/Snapshots/*.verified.txt | Snapshot tests for Docker generation with different entrypoint types |
| playground/AspireWithPython/AspireWithPython.AppHost/AppHost.cs | Updated to use new AddPythonScript method |
|
|
||
| if (!context.Resource.TryGetLastAnnotation<PythonEntrypointAnnotation>(out var entrypointAnnotation)) | ||
| { | ||
| // No entrypoint annotation found, cannot generate Dockerfile |
There was a problem hiding this comment.
Should this write a warning to logging?
There was a problem hiding this comment.
I don't think so, maybe it should throw because it's really edge case.
…he default virtual environment folder and improve entrypoint argument handling; remove obsolete Dockerfile snapshot test.
- Changed method names from AddPythonApp to AddPythonScript for clarity. - Introduced AddPythonModule for the FastAPI application with specified arguments and HTTP endpoint. - Added a separate Python executable setup for running the FastAPI app on a different port. - Created .python-version file to specify Python version 3.13. - Added README.md file for module documentation. - Implemented api.py with basic FastAPI routes for greeting. - Established pyproject.toml for project metadata and dependencies. - Generated uv.lock file to manage package versions and dependencies.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… pass arguments as a single array
| { | ||
| [JsonPropertyName("program_path")] | ||
| public string ProgramPath { get; set; } = string.Empty; | ||
| public string? ProgramPath { get; set; } |
There was a problem hiding this comment.
These should be empty, not null, by default
Description
Big changes to how python application manage their entrypoints. There are 3 core scenarios:
python app.py-AddPythonScript- We launch python in the venv and pass the script as the first argument.python -m modulename-AddPythonModule- We launch a python module. Args are specified using WithArgs.uvicorn app:main-AddPythonExecutable- We launch a custom executable from the virtual environment.Fixes #6244
Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplate