Add UvicornAppResource deriving from PythonAppResource#12502
Conversation
Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
Make methods generic to support the derived type.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12502Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12502" |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new UvicornAppResource class to explicitly represent Uvicorn-based Python applications in the Aspire hosting model. The change refactors AddUvicornApp to return the specialized resource type instead of the generic PythonAppResource, and updates several extension methods to be generic to support derived resource types.
Key changes:
- Added
UvicornAppResourceclass that inherits fromPythonAppResourcewith comprehensive XML documentation for a public API - Made
WithVirtualEnvironment,WithDebugging, andWithEntrypointextension methods generic to support derived types - Updated
AddUvicornAppreturn type fromIResourceBuilder<PythonAppResource>toIResourceBuilder<UvicornAppResource> - Fixed XML documentation references to use generic type parameters
- Added test coverage for the new
UvicornAppResourcetype
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Aspire.Hosting.Python/UvicornAppResource.cs | Introduces new UvicornAppResource class with comprehensive XML documentation |
| src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs | Refactors extension methods to be generic, updates AddUvicornApp to return UvicornAppResource, and fixes XML doc references |
| tests/Aspire.Hosting.Python.Tests/AddUvicornAppTests.cs | Adds test to verify AddUvicornApp creates the correct resource type |
| /// </para> | ||
| /// <para> | ||
| /// By default, the virtual environment folder is expected to be named <c>.venv</c> and located in the app directory. | ||
| /// Use <see cref="WithVirtualEnvironment"/> to specify a different virtual environment path. |
There was a problem hiding this comment.
The <see cref> tag is missing the generic type parameter. It should be <see cref=\"WithVirtualEnvironment{T}(IResourceBuilder{T}, string)\"/> to properly reference the generic method signature, ensuring accurate IntelliSense and documentation generation.
| /// Use <see cref="WithVirtualEnvironment"/> to specify a different virtual environment path. | |
| /// Use <see cref="WithVirtualEnvironment{T}(IResourceBuilder{T}, string)"/> to specify a different virtual environment path. |
| // Arrange | ||
| using var builder = TestDistributedApplicationBuilder.Create(); | ||
| var appDirectory = Path.Combine(Path.GetTempPath(), "test-app"); | ||
|
|
||
| // Act | ||
| var uvicornApp = builder.AddUvicornApp("uvicorn-app", appDirectory, "main:app"); | ||
|
|
||
| // Assert |
There was a problem hiding this comment.
According to the custom coding guidelines, test methods should not include "Act", "Arrange" or "Assert" comments. Remove these comments to match the coding style used elsewhere in the codebase.
| // Arrange | |
| using var builder = TestDistributedApplicationBuilder.Create(); | |
| var appDirectory = Path.Combine(Path.GetTempPath(), "test-app"); | |
| // Act | |
| var uvicornApp = builder.AddUvicornApp("uvicorn-app", appDirectory, "main:app"); | |
| // Assert | |
| using var builder = TestDistributedApplicationBuilder.Create(); | |
| var appDirectory = Path.Combine(Path.GetTempPath(), "test-app"); | |
| var uvicornApp = builder.AddUvicornApp("uvicorn-app", appDirectory, "main:app"); |
Implements decision from #12265 to create a specialized
UvicornAppResourcethat derives fromPythonAppResource, following the pattern established byViteAppResource:NodeAppResource.Changes
Added
UvicornAppResourceclass inAspire.Hosting.PythonnamespacePythonAppResourceUpdated
AddUvicornAppsignature to returnIResourceBuilder<UvicornAppResource>UvicornAppResourceinstancesCreateResourceBuilderto maintain proper type after base class extension methodsAdded test verifying
AddUvicornAppproduces correct resource typeExample
All existing usages in templates and playground continue to work due to inheritance.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.