Skip to content

PythonAppHost Code Generator#13947

Merged
sebastienros merged 69 commits into
mainfrom
pythonapphost
Mar 26, 2026
Merged

PythonAppHost Code Generator#13947
sebastienros merged 69 commits into
mainfrom
pythonapphost

Conversation

@annatisch
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 15, 2026

🚀 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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13947

Or

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

@annatisch
Copy link
Copy Markdown
Member Author

@dotnet-policy-service agree company="Microsoft"

@annatisch annatisch marked this pull request as ready for review January 22, 2026 22:09
Copilot AI review requested due to automatic review settings January 22, 2026 22:09
@annatisch annatisch changed the title [WIP] PythonAppHost Code Generator PythonAppHost Code Generator Jan 22, 2026
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 is a work-in-progress PR that adds Python language support to Aspire's AppHost code generation system. It introduces a complete Python code generator with transport layer, base classes, and scaffolding support, along with necessary infrastructure changes to the CLI and type scanning system.

Changes:

  • Added Python language support infrastructure (PythonLanguageSupport, PythonModuleBuilder) with scaffolding, detection, and runtime configuration for Python AppHosts
  • Enhanced ATS capability scanner to track complete type hierarchies including implemented interfaces and base types, improving code generation accuracy
  • Removed async callback exports (withEnvironmentCallbackAsync, withArgsCallbackAsync, withUrlsCallbackAsync) from ResourceBuilderExtensions to simplify the API surface
  • Updated CLI to support Python with custom generated folder name ("aspyre") and pass-through of debug flags and additional command-line arguments
  • Added comprehensive Python transport layer (_transport.py) and base classes (_base.py) with 1,300+ lines of implementation
  • Updated test snapshots to reflect new type hierarchy information in generated TypeScript code

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/*.verified.txt Updated test snapshots with ImplementedInterfaces and BaseType hierarchy information
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts Removed async callback methods from generated TypeScript
tests/Aspire.Cli.Tests/Projects/DefaultLanguageDiscoveryTests.cs Changed test case from "apphost.py" to "script.py" since apphost.py is now valid
src/Aspire.Hosting/ResourceBuilderExtensions.cs Removed [AspireExport] attributes for async callback overloads
src/Aspire.Hosting/Ats/AtsCapabilityScanner.cs Added CreateHandleTypeRef helper and enhanced type hierarchy collection
src/Aspire.Hosting/Ats/AtsCapabilityInfo.cs Added ImplementedInterfaces and BaseType properties to AtsTypeRef
src/Aspire.Hosting/Aspire.Hosting.csproj Added InternalsVisibleTo for Python code generation assemblies
src/Aspire.Hosting.RemoteHost/CodeGeneration/CodeGenerationService.cs Removed blank line (whitespace cleanup)
src/Aspire.Hosting.CodeGeneration.Python/* Added complete Python code generator implementation (3 new files)
src/Aspire.Cli/Projects/* Updated CLI infrastructure to support Python with custom folder names and argument passing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Aspire.Cli/Projects/GuestRuntime.cs Outdated
Comment thread src/Aspire.Cli/Projects/ILanguageDiscovery.cs Outdated
Comment thread src/Aspire.Cli/Projects/KnownLanguageId.cs Outdated
Comment thread tests/Aspire.Cli.Tests/Projects/DefaultLanguageDiscoveryTests.cs Outdated
Comment thread src/Aspire.Hosting.CodeGeneration.Python/PythonLanguageSupport.cs
Comment thread src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs
Comment thread src/Aspire.TypeSystem/AtsCapabilityInfo.cs
@sebastienros sebastienros requested a review from eerhardt as a code owner March 24, 2026 17:14
sebastienros and others added 3 commits March 24, 2026 13:43
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Exclude Azure.Sql, Foundry, and Maui from Python polyglot playground validation until Python code generation supports their current API surface.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sanitize Python identifiers derived from capability parameters and derive generic Python type names without leaking CLR assembly metadata so the Python playground validation can cover Azure.Sql, Foundry, and Maui again.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread playground/polyglot/Python/Aspire.Hosting.Valkey/ValidationAppHost/apphost.py Outdated
sebastienros and others added 4 commits March 25, 2026 07:03
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the stale .modules sys.path bootstrap from the generated Python playground ValidationAppHosts so they match the shared Python scaffold, and add a regression test to keep new scaffolds importing aspire_app directly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drop the implementation-shaped Python scaffold test and rely on the existing generated-output verification for this area.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Create a Python AppHost playground that orchestrates a Redis cache, a Uvicorn-hosted Python app, and a Vite frontend that references the Python service.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

  • Tests / Azure.AI.OpenAI / Azure.AI.OpenAI (windows-latest) - Post-test cleanup steps 'Upload logs, and test results | Copy CLI E2E recordings for upload | Upload CLI E2E recordings | Generate test results summary | Post Checkout code' matched the Windows process initialization failure override allowlist.

sebastienros and others added 4 commits March 25, 2026 14:24
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 2 jobs were identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit fd23cdc)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23569697285

@sebastienros sebastienros merged commit a6c0b94 into main Mar 26, 2026
500 of 504 checks passed
@sebastienros sebastienros deleted the pythonapphost branch March 26, 2026 03:51
adamint pushed a commit to adamint/aspire that referenced this pull request Mar 28, 2026
* Start porting over Python API

* Merged latest changes

* Update to module builder

* Support recursive interface collection

* Fix interfaces

* Support sync and async variants

* More merging

* Fixed merge

* Updates

* Updates

* Fixed generic interface

* Update AspireList

* Cached properties

* Added resource constructors with kwargs

* Fixed ABCs and list/dict registration

* Fix handles and logging

* Fix some tests

* More test fixes

* Update python lookup

* Fix Python CodeGeneration build errors and update tests

- Add XML documentation to AtsPythonCodeGenerator class
- Remove unused 'using System.Text;' and 'using Aspire.Hosting.ApplicationModel;' directives
- Update test file key from 'aspire.py' to '__init__.py' to match generator output
- Update test assertions to use actual generated method names (with_env instead of with_environment)
- Update verified snapshots to match new generator output

* Patch files

* Fix Python polyglot validation test to match scaffold output

The scaffold generates 'builder.run()' but the validation test was looking
for 'builder.build().run()'. Updated the grep/sed pattern to match the
actual scaffold output.

* Update Go, Java, and Rust CodeGeneration test snapshots

Updated verified snapshots to match current scanner output after main merge.

* Fix Python validation test indentation

The inserted Redis code needs proper 4-space indentation to be valid
inside the Python 'with' block.

* Improvements to errors + rename

* Regenerate snapshots

* Revert fallback cast error handling

* Add missing XML documentation to PythonModuleBuilder public members (microsoft#14743)

* Initial plan

* Add missing XML documentation to MethodParameters property and DistributedApplicationBuilder constant

Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>

* Add comprehensive XML documentation to PythonLanguageSupport public API (microsoft#14744)

* Initial plan

* Add comprehensive XML documentation to PythonLanguageSupport public members

Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>

* Add descriptive XML documentation for AtsTypeRef.ImplementedInterfaces and AtsTypeRef.BaseType (microsoft#14746)

* Initial plan

* Improve XML documentation for ImplementedInterfaces and BaseType on AtsTypeRef

Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: annatisch <8689453+annatisch@users.noreply.github.com>

* Re-record tests

* Remove extra project reference

* Re-record tests

* Re-record tests

* Restructure packaging

* Refactored aspire module to single file

* Generate to .modules

* Generate modules before installing

* Support conditional ref expr

* Remove additionalArgs

* Tests

* Renames to prevent naming conflicts

* Group similar overloads

* Support param defaults

* Update Python codegen snapshots

Accept regenerated Python snapshots after the cancellation token and process timeout fixes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix polyglot and CLI template validation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Add Python polyglot playground validation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Skip unsupported Python SDK playgrounds

Exclude Azure.Sql, Foundry, and Maui from Python polyglot playground validation until Python code generation supports their current API surface.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix Python codegen naming conflicts

Sanitize Python identifiers derived from capability parameters and derive generic Python type names without leaking CLR assembly metadata so the Python playground validation can cover Azure.Sql, Foundry, and Maui again.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address PR review feedback

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Refresh Python playground apphosts

Remove the stale .modules sys.path bootstrap from the generated Python playground ValidationAppHosts so they match the shared Python scaffold, and add a regression test to keep new scaffolds importing aspire_app directly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Remove Python scaffold assertion test

Drop the implementation-shaped Python scaffold test and rely on the existing generated-output verification for this area.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Add PythonAppHost playground

Create a Python AppHost playground that orchestrates a Redis cache, a Uvicorn-hosted Python app, and a Vite frontend that references the Python service.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Update Python codegen snapshot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix Java validation selection

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix describe replica test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Sebastien Ros <sebastienros@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joperezr joperezr added this to the 13.3 milestone Apr 14, 2026
@aspire-repo-bot
Copy link
Copy Markdown
Contributor


Warning

The create_pull_request operation failed: E003: Cannot create pull request with more than 100 files (received 122). The code changes were not applied.

Documentation updates have been drafted for this PR. 📝

A draft docs PR has been opened against release/13.3 on microsoft/aspire.dev (branch docs/python-apphost-13947), targeting the release/13.3 branch based on this PR's milestone.

What was documented

  • New page: app-host/python-apphost.mdx — Python AppHost project structure reference, covering:
    • Scaffolded files: apphost.py, aspire.config.json, .modules/, pylock.apphost.toml, apphost_requirements.txt
    • aspire.config.json schema with "language": "python"
    • apphost.py entry-point patterns and create_builder usage
    • Python toolchain detection: uv (recommended, uses pylock.apphost.toml) vs standard venv/pip fallback (uses apphost_requirements.txt)
    • Step-by-step "Running the AppHost" walkthrough
  • Updated: languages-and-runtimes/index.mdx — Added Python row to the AppHost languages table
  • Updated: docs.topics.ts — Added Python entry to the sidebar "Project structure" section

The draft PR needs human review before merging. Please verify the code examples and toolchain detection details match the final implementation.

Generated by PR Documentation Check · ● 4.8M ·

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.

6 participants