Repository navigation
Add Python and uv installation validation with user notifications - #12787
Conversation
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
…move venv check and logging Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
Copilot Don't make RequiredCommandValidator and CoalescingAsyncOperation. Keep it internal and treat it as shared source code. |
…as internal, parameterize message strings Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Done. Moved both classes to |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12787Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12787" |
1 similar comment
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12787Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12787" |
|
Copilot /Users/runner/work/aspire/aspire/tests/Aspire.Hosting.DevTunnels.Tests/DevTunnelCliInstallationManagerTests.cs(32,58): error CS0122: 'DevTunnelCliInstallationManager.OnResolvedAsync(string, CancellationToken)' is inaccessible due to its protection level [/Users/runner/work/aspire/aspire/tests/Aspire.Hosting.DevTunnels.Tests/Aspire.Hosting.DevTunnels.Tests.csproj] Time Elapsed 00:01:11.55 |
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Fixed. Made |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the RequiredCommandValidator and CoalescingAsyncOperation classes from the Aspire.Hosting.DevTunnels namespace to the more general Aspire.Hosting.Utils namespace, making them reusable across the codebase. The refactoring introduces virtual methods for customizing error messages and adds Python environment validation support.
Key Changes
- Moved
RequiredCommandValidatorandCoalescingAsyncOperationfromAspire.Hosting.DevTunnelstoAspire.Hosting.Utilsnamespace for broader reuse - Replaced hardcoded resource string references with virtual methods (
GetCommandNotFoundMessage,GetCommandNotFoundWithLinkMessage,GetValidationFailedMessage) to enable customization - Added
PythonInstallationManagerandUvInstallationManagerclasses to validate Python and uv command availability before running Python applications
Reviewed Changes
Copilot reviewed 39 out of 41 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/RequiredCommandValidator.cs | Moved to Utils namespace, added virtual methods for error messages, changed ResolveCommand to protected internal |
| src/Shared/CoalescingAsyncOperation.cs | Moved to Utils namespace, added XML documentation for Dispose method |
| src/Aspire.Hosting.Python/PythonInstallationManager.cs | New class to validate Python installation with platform-specific command resolution |
| src/Aspire.Hosting.Python/UvInstallationManager.cs | New class to validate uv command availability |
| src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs | Integrated Python/uv validation before resource startup |
| src/Aspire.Hosting/Resources/MessageStrings.* | Added unused resource strings (should be removed) |
| src/Aspire.Hosting.Python/Resources/MessageStrings.* | Added unused resource strings (should be removed) |
| src/Aspire.Hosting.DevTunnels/*.cs | Updated using directives to reference new Utils namespace |
| src/Aspire.Hosting/Aspire.Hosting.csproj | Added shared file links for new Utils classes |
| src/Aspire.Hosting.Python/Aspire.Hosting.Python.csproj | Added shared file links and resource file configuration |
| src/Aspire.Hosting.DevTunnels/Aspire.Hosting.DevTunnels.csproj | Added shared file links for new Utils classes |
Files not reviewed (2)
- src/Aspire.Hosting.Python/Resources/MessageStrings.Designer.cs: Language not supported
- src/Aspire.Hosting/Resources/MessageStrings.Designer.cs: Language not supported
Comments suppressed due to low confidence (4)
src/Shared/CoalescingAsyncOperation.cs:11
- The XML documentation for this internal class is too verbose. According to the coding guidelines, internal APIs should have brief
<summary>tags only. The detailed explanation in lines 6-11 should be simplified to a concise description.
src/Shared/RequiredCommandValidator.cs:21 - The XML documentation for this internal class is too verbose. According to the coding guidelines, internal APIs should have brief
<summary>tags only and avoid verbose<remarks>sections. The<remarks>section should be removed, and the<summary>should be simplified to a concise description of what the class does.
src/Shared/RequiredCommandValidator.cs:62 - The XML documentation for these internal methods is too verbose. According to the coding guidelines, internal APIs should have brief
<summary>tags only. The detailed explanations in lines 38-40, 46-49, and 55-58 are excessive for internal methods. Consider simplifying to concise one-line summaries.
src/Shared/RequiredCommandValidator.cs:71 - The XML documentation for this internal method includes a
<remarks>section. According to the coding guidelines, internal APIs should have brief<summary>tags only and avoid<remarks>. The<remarks>section should be removed.
| <data name="RequiredCommandNotification" xml:space="preserve"> | ||
| <value>Required command '{0}' was not found on PATH or at a specified location.</value> | ||
| </data> | ||
| <data name="RequiredCommandNotificationWithLink" xml:space="preserve"> | ||
| <value>Required command '{0}' was not found. See installation instructions for more details.</value> | ||
| </data> | ||
| <data name="RequiredCommandNotificationWithValidation" xml:space="preserve"> | ||
| <value>{0} See installation instructions for more details.</value> | ||
| </data> |
There was a problem hiding this comment.
These resource strings appear to be unused. The RequiredCommandValidator class was refactored to use virtual methods (GetCommandNotFoundMessage, GetCommandNotFoundWithLinkMessage, GetValidationFailedMessage) instead of these resource strings. Since no code references these resource strings, they should be removed from the resx files to avoid maintaining dead code.
| <data name="RequiredCommandNotification" xml:space="preserve"> | |
| <value>Required command '{0}' was not found on PATH or at a specified location.</value> | |
| </data> | |
| <data name="RequiredCommandNotificationWithLink" xml:space="preserve"> | |
| <value>Required command '{0}' was not found. See installation instructions for more details.</value> | |
| </data> | |
| <data name="RequiredCommandNotificationWithValidation" xml:space="preserve"> | |
| <value>{0} See installation instructions for more details.</value> | |
| </data> |
| <trans-unit id="RequiredCommandNotification"> | ||
| <source>Required command '{0}' was not found on PATH or at a specified location.</source> | ||
| <target state="new">Required command '{0}' was not found on PATH or at a specified location.</target> | ||
| <note /> | ||
| </trans-unit> | ||
| <trans-unit id="RequiredCommandNotificationWithLink"> | ||
| <source>Required command '{0}' was not found. See installation instructions for more details.</source> | ||
| <target state="new">Required command '{0}' was not found. See installation instructions for more details.</target> | ||
| <note /> | ||
| </trans-unit> | ||
| <trans-unit id="RequiredCommandNotificationWithValidation"> | ||
| <source>{0} See installation instructions for more details.</source> | ||
| <target state="new">{0} See installation instructions for more details.</target> | ||
| <note /> | ||
| </trans-unit> |
There was a problem hiding this comment.
These resource strings appear to be unused. The RequiredCommandValidator class was refactored to use virtual methods instead of resource strings. Since no code references these resource strings, they should be removed from all localization files to avoid maintaining dead code.
| <trans-unit id="RequiredCommandNotification"> | |
| <source>Required command '{0}' was not found on PATH or at a specified location.</source> | |
| <target state="new">Required command '{0}' was not found on PATH or at a specified location.</target> | |
| <note /> | |
| </trans-unit> | |
| <trans-unit id="RequiredCommandNotificationWithLink"> | |
| <source>Required command '{0}' was not found. See installation instructions for more details.</source> | |
| <target state="new">Required command '{0}' was not found. See installation instructions for more details.</target> | |
| <note /> | |
| </trans-unit> | |
| <trans-unit id="RequiredCommandNotificationWithValidation"> | |
| <source>{0} See installation instructions for more details.</source> | |
| <target state="new">{0} See installation instructions for more details.</target> | |
| <note /> | |
| </trans-unit> |
| /// <summary> | ||
| /// Looks up a localized string similar to Required command '{0}' was not found on PATH or at a specified location.. | ||
| /// </summary> | ||
| internal static string RequiredCommandNotification { | ||
| get { | ||
| return ResourceManager.GetString("RequiredCommandNotification", resourceCulture); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Looks up a localized string similar to Required command '{0}' was not found. See installation instructions for more details.. | ||
| /// </summary> | ||
| internal static string RequiredCommandNotificationWithLink { | ||
| get { | ||
| return ResourceManager.GetString("RequiredCommandNotificationWithLink", resourceCulture); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Looks up a localized string similar to {0} See installation instructions for more details.. | ||
| /// </summary> | ||
| internal static string RequiredCommandNotificationWithValidation { | ||
| get { | ||
| return ResourceManager.GetString("RequiredCommandNotificationWithValidation", resourceCulture); | ||
| } | ||
| } |
There was a problem hiding this comment.
These generated properties for resource strings appear to be unused. The RequiredCommandValidator class was refactored to use virtual methods instead of these resource strings. These properties should be removed by removing the corresponding entries from MessageStrings.resx.
| /// <summary> | |
| /// Looks up a localized string similar to Required command '{0}' was not found on PATH or at a specified location.. | |
| /// </summary> | |
| internal static string RequiredCommandNotification { | |
| get { | |
| return ResourceManager.GetString("RequiredCommandNotification", resourceCulture); | |
| } | |
| } | |
| /// <summary> | |
| /// Looks up a localized string similar to Required command '{0}' was not found. See installation instructions for more details.. | |
| /// </summary> | |
| internal static string RequiredCommandNotificationWithLink { | |
| get { | |
| return ResourceManager.GetString("RequiredCommandNotificationWithLink", resourceCulture); | |
| } | |
| } | |
| /// <summary> | |
| /// Looks up a localized string similar to {0} See installation instructions for more details.. | |
| /// </summary> | |
| internal static string RequiredCommandNotificationWithValidation { | |
| get { | |
| return ResourceManager.GetString("RequiredCommandNotificationWithValidation", resourceCulture); | |
| } | |
| } | |
| <data name="UvNotFoundWhenRequired" xml:space="preserve"> | ||
| <value>The 'uv' command was not found, but is required for this Python application. Install uv by following the instructions at https://docs.astral.sh/uv/getting-started/installation/</value> | ||
| </data> |
There was a problem hiding this comment.
This resource string appears to be unused. The UvInstallationManager relies on the base RequiredCommandValidator class's virtual methods for error messages. Since no code references this resource string, it should be removed from the resx file to avoid maintaining dead code.
| <data name="UvNotFoundWhenRequired" xml:space="preserve"> | |
| <value>The 'uv' command was not found, but is required for this Python application. Install uv by following the instructions at https://docs.astral.sh/uv/getting-started/installation/</value> | |
| </data> |
| <trans-unit id="UvNotFoundWhenRequired"> | ||
| <source>The 'uv' command was not found, but is required for this Python application. Install uv by following the instructions at https://docs.astral.sh/uv/getting-started/installation/</source> | ||
| <target state="new">The 'uv' command was not found, but is required for this Python application. Install uv by following the instructions at https://docs.astral.sh/uv/getting-started/installation/</target> | ||
| <note /> | ||
| </trans-unit> |
There was a problem hiding this comment.
This resource string appears to be unused. The UvInstallationManager relies on the base RequiredCommandValidator class's virtual methods for error messages. Since no code references this resource string, it should be removed from all localization files to avoid maintaining dead code.
| <trans-unit id="UvNotFoundWhenRequired"> | |
| <source>The 'uv' command was not found, but is required for this Python application. Install uv by following the instructions at https://docs.astral.sh/uv/getting-started/installation/</source> | |
| <target state="new">The 'uv' command was not found, but is required for this Python application. Install uv by following the instructions at https://docs.astral.sh/uv/getting-started/installation/</target> | |
| <note /> | |
| </trans-unit> |
|
Copilot Delete the unused resource strings. |
…ource validation Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Done. Added
Commit: 7b2115d |
|
Copilot Add UvInstallationManager in the UseUv method |
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
I tested this out on Ubuntu 24.04 - works well. |
|
Copilot Undo the changes under Aspire.Hosting/Resources. These are not being used anywhere |
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Removed all unused resource strings from |
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19195175938 |

Description
This PR adds a notification system that guides developers when Python or uv are not installed before Python resources start. The validation shows helpful notifications with installation instructions but allows the application to fail naturally, preserving the original error behavior.
Shared Infrastructure (Internal Shared Source)
CoalescingAsyncOperationandRequiredCommandValidatortosrc/Shared/as internal shared source code<Compile Include="$(SharedDir)...">referencesRequiredCommandValidatorprovides base pattern for validating executable presence on PATH with configurable exception behaviorCoalescingAsyncOperationensures single concurrent execution while coalescing multiple callersOnResolvedAsyncisprotected internal virtualto allow test accessthrowOnFailureparameter to control exception throwing behaviorInternalsVisibleToattributes neededPython Environment Validation
PythonInstallationManagerandUvInstallationManagerclasses extendingRequiredCommandValidatorPythonInstallationManagervalidates Python forPythonVenvCreatorResource(before venv creation)UvInstallationManagervalidates uv forPythonInstallerResource(when using uv package manager)UvInstallationManageris also registered explicitly in theWithUvextension method for consistencyOnBeforeResourceStartedhooks on child resourcesExcludeFromManifestensuring they only exist in RunModethrowOnFailure: falseto show helpful notifications without preventing natural failure behaviorIInteractionServiceto show notifications when commands are not foundDevTunnels Updates
src/Shared/directoryOnResolvedAsyncisprotected internal overrideto maintain testabilityKey Implementation Details
PythonVenvCreatorResourceandPythonInstallerResource), not the parentPythonVenvCreatorResourcePythonInstallerResourceUvInstallationManageris also explicitly registered in theWithUvmethod for clarityEnsureInstalledAsync(bool throwOnFailure = true)overloadtrue(throws on failure) for backward compatibilityfalsefor Python and uv validation to allow natural app failure while showing notificationsExcludeFromManifest(implicit RunMode-only behavior)Testing Results
InternalsVisibleToneeded - using shared source code patternChecklist
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.