Skip to content

Refactor Python application entrypoint handling and add support for s… - #12043

Merged
David Fowler (davidfowl) merged 13 commits into
mainfrom
davidfowl/python-entrypoints
Oct 15, 2025
Merged

David Fowler (davidfowl) merged 13 commits into
mainfrom
davidfowl/python-entrypoints

Conversation

@davidfowl

@davidfowl David Fowler (davidfowl) commented Oct 15, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Big changes to how python application manage their entrypoints. There are 3 core scenarios:

  • Scripts - python app.py - AddPythonScript - We launch python in the venv and pass the script as the first argument.
  • Modules - python -m modulename - AddPythonModule - We launch a python module. Args are specified using WithArgs.
  • Executables - uvicorn app:main - AddPythonExecutable - We launch a custom executable from the virtual environment.

Fixes #6244

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions

github-actions Bot commented Oct 15, 2025 •

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12043

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12043"

@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Oct 15, 2025
@davidfowl
David Fowler (davidfowl) marked this pull request as ready for review October 15, 2025 06:10
Copilot AI review requested due to automatic review settings October 15, 2025 06:10

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 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this write a warning to logging?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.
@dotnet-policy-service dotnet-policy-service Bot added this to the 13.0 milestone Oct 15, 2025
{
[JsonPropertyName("program_path")]
public string ProgramPath { get; set; } = string.Empty;
public string? ProgramPath { get; set; }

@adamint Adam Ratzman (adamint) Oct 15, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These should be empty, not null, by default

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add first class support for running python apps with specified modules

6 participants