Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Nov 5, 2025

Backport of #12667 to release/13.0

/cc @davidfowl @copilot

Customer Impact

Big API changes to align the python patterns with the JavaScript patterns. Also made python work without uv.

Testing

Automated and manual.

Risk

Medium

Regression?

No

Copilot AI and others added 24 commits November 5, 2025 17:05
- Created PythonPipInstallerResource for pip package installation
- Added WithPip extension method following WithNpm/WithYarn pattern
- Renamed WithUvEnvironment to WithUv (with obsolete redirect)
- Auto-detect requirements.txt and call WithPip in run mode
- Pip executable is resolved from virtual environment
- Updated all usages in tests, playground, and templates
- Fixed test failures by filtering for PythonAppResource specifically

Co-authored-by: davidfowl <[email protected]>
- WithUv now defaults to ["sync", "--python"] to bootstrap Python automatically
- Added optional args parameter to allow customization of uv sync arguments
- Updated documentation to reflect the new --python flag
- Updated tests to verify the new default arguments
- All tests passing

Co-authored-by: davidfowl <[email protected]>
- Created PythonPackageManagerAnnotation, PythonInstallCommandAnnotation, and PythonPackageInstallerAnnotation
- Created unified PythonInstallerResource to replace separate pip and uv resources
- Refactored WithPip and WithUv to use shared AddInstaller helper method
- Package manager methods now replace each other (WithPip after WithUv replaces uv with pip, and vice versa)
- Added tests to verify replacement behavior
- All 77 tests passing

Co-authored-by: davidfowl <[email protected]>
…ironmentResource)

These have been replaced by the unified PythonInstallerResource

Co-authored-by: davidfowl <[email protected]>
- Auto-detect pyproject.toml and add WithUv (takes precedence over requirements.txt)
- Auto-detect requirements.txt and add WithPip (fallback if no pyproject.toml)
- Added 4 tests to verify auto-detection behavior
- All 81 tests passing

Co-authored-by: davidfowl <[email protected]>
- WithPip now detects which file exists and uses the appropriate install command
- pyproject.toml: uses 'pip install .'
- requirements.txt: uses 'pip install -r requirements.txt'
- Auto-detection now uses pip for both pyproject.toml and requirements.txt
- Updated tests to verify pip is used for both file types
- All 81 tests passing

Co-authored-by: davidfowl <[email protected]>
- Created PythonVenvCreatorResource to create virtual environment if it doesn't exist
- Venv creator runs before the installer (pip/uv) when using pip
- Only creates venv if not using uv and venv doesn't exist
- Installer waits for venv creator to complete before running
- All 81 tests passing

Co-authored-by: davidfowl <[email protected]>
- Removed WithUvEnvironment (obsolete method)
- Removed env.Uv property from PythonEnvironmentAnnotation
- Infer UV usage from PythonPackageManagerAnnotation instead
- Don't fail if there's no package manager configured (just don't run installer)
- Create venv only when package manager needs it (checked via pyvenv.cfg)
- Support both python and python3 commands for venv creation
- On Windows: try py launcher first, fallback to python
- On Unix: try python3 first, fallback to python
- Updated all documentation references from WithUvEnvironment to WithUv
- All 81 tests passing

Co-authored-by: davidfowl <[email protected]>
- Added optional bool parameter createIfNotExists (defaults to true)
- When false, disables automatic venv creation
- Added CreateVenvIfNotExists property to PythonEnvironmentAnnotation
- AddVenvCreator now checks this flag before creating venv
- Added 3 tests to verify the behavior
- All 84 tests passing

Co-authored-by: davidfowl <[email protected]>
- Moved venv creator management to BeforeStartEvent in AddPythonAppCore
- Venv creators are now keyed by directory path, not resource name
- Multiple resources sharing same venv directory use single venv creator
- WithPip creates default .venv if no virtual environment configured
- WithUv disables venv creation (uv handles it)
- WithVirtualEnvironment createIfNotExists parameter controls venv creation
- All venv creation logic runs at BeforeStart to respect final annotation state
- Installer waits for venv creator if it exists

Co-authored-by: davidfowl <[email protected]>
- Removed directory-based venv creator sharing approach
- Created one venv creator per resource as a child resource (simpler, clearer)
- Use TryCreateResourceBuilder to check for existing venv creator
- WithVirtualEnvironment(createIfNotExists: false) removes venv creator
- WithPip creates venv creator after adding package manager annotation
- WithUv disables venv creation (uv handles it)
- Installer waits for venv creator when it exists
- All 92 tests passing

Co-authored-by: davidfowl <[email protected]>
- Venv is now created even when there's no package manager configured
- If no pyproject.toml or requirements.txt exists, venv creator is still added
- WithVirtualEnvironment(createIfNotExists: false) removes venv creator regardless of package manager
- Fixed linting issues with null checks
- 85/92 tests passing (7 tests failing, need investigation)

Co-authored-by: davidfowl <[email protected]>
- Moved wait dependency setup to BeforeStartEvent as suggested
- This allows methods to add/remove resources dynamically
- Wait relationships are established based on final resource state
- Currently 10/92 tests failing - issue is BeforeStartEvent fires after Build() in tests
- Need different approach or tests need adjustment to use app.StartAsync() to trigger event

Co-authored-by: davidfowl <[email protected]>
… use FindFullPathFromPath pattern

- Renamed SetupWaitDependencies to SetupDependencies
- SetupDependencies now only runs in run mode (BeforeStartEvent subscription only in run mode)
- Make venv and installer resources children with WithParentRelationship
- Updated IsPythonCommandAvailable to use FindFullPathFromPath pattern like BicepCompiler
- Added PublishBeforeStartEventAsync helper for tests (not yet used)
- Build passing, ready to add test calls to publish event

Co-authored-by: davidfowl <[email protected]>
- Updated tests to filter for PythonAppResource when checking single executable resource
- Made tests that check WaitAnnotation async and call PublishBeforeStartEventAsync
- Removed unnecessary annotation clearing from SetupDependencies (AddInstaller never sets them)
- All 92 Python hosting tests passing

Co-authored-by: davidfowl <[email protected]>
- Replaced manual search with TryCreateResourceBuilder pattern
- Follows the same pattern used in Node.js hosting extensions
- More idiomatic and cleaner code
- All 92 tests passing

Co-authored-by: davidfowl <[email protected]>
- Renamed AddPythonScript to AddPythonApp (main entry point method)
- Added [OverloadResolutionPriority(1)] attribute to AddPythonApp
- Made obsolete AddPythonApp (old) into AddPythonScript (obsolete)
- Updated XML doc comments to reference new method names
- All 92 tests passing

Co-authored-by: davidfowl <[email protected]>
…rectly

- Removed obsolete AddPythonScript method (was previously AddPythonApp)
- Renamed AddPythonScript (main entry point) to AddPythonApp
- Added [OverloadResolutionPriority(1)] to AddPythonApp
- Updated all test usages from AddPythonScript to AddPythonApp
- Updated all XML documentation references
- Build passing, all tests updated

Co-authored-by: davidfowl <[email protected]>
- Changed default args from ["sync", "--python"] to ["sync"]
- The --python flag requires a value, causing "error: a value is required for '--python'"
- uv sync alone will auto-detect Python from pyproject.toml or system
- Users can still pass custom args like ["sync", "--python", "3.11"] if needed
- All 92 tests passing

Co-authored-by: eerhardt <[email protected]>
@github-actions
Copy link
Contributor Author

github-actions bot commented Nov 5, 2025

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

Or

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

@davidfowl davidfowl merged commit ebecfaf into release/13.0 Nov 5, 2025
296 checks passed
@davidfowl davidfowl deleted the backport/pr-12667-to-release/13.0 branch November 5, 2025 17:36
@davidfowl
Copy link
Member

@joperezr why don't these PRs have a milestone? Is the policy bot broken for these PRs?

@davidfowl davidfowl added this to the 13.0 milestone Nov 6, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants