Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 16, 2025

Summary

Adds a non-blocking error notification when a Python resource attempts to start without a virtual environment being created. This helps developers quickly identify and resolve configuration issues with Python applications in Aspire.

Changes

Virtual Environment Detection

  • Added Location property to VirtualEnvironment class to expose the virtual environment path without requiring recalculation
  • Added OnBeforeResourceStarted event handler in PythonAppResourceBuilderExtensions to check for virtual environment existence before Python resources start
  • The check only runs when IInteractionService.IsAvailable is true (i.e., when the dashboard is enabled)
  • The check is automatically skipped when using WithUvEnvironment() since UV creates the virtual environment automatically

User Notification

When a missing virtual environment is detected, an error notification is displayed with:

  • Title: "Python virtual environment not found"
  • Message: Includes the resource name and expected virtual environment path
  • Intent: Error (red notification)
  • Link: Points to https://aka.ms/aspire/python for documentation on configuring Python apps in Aspire

The notification is non-blocking (fire-and-forget) to avoid preventing the resource from starting, allowing developers to see the error and take corrective action.

Example

When running a Python resource without creating the virtual environment:

var builder = DistributedApplication.CreateBuilder(args);

// This will show a notification if .venv doesn't exist
builder.AddPythonScript("api", "../python-api", "main.py");

builder.Build().Run();

The dashboard will display an error notification pointing to the missing virtual environment location, helping developers quickly understand what needs to be fixed.

Testing

Added comprehensive test coverage:

  • Verifies notification is sent when virtual environment doesn't exist
  • Confirms notification is skipped when interaction service is unavailable
  • Confirms notification is skipped when using UV environment (which creates venv automatically)
  • All existing Python hosting tests continue to pass (65/65)

Fixes #issue_number

Original prompt

Use the interaction service to show an error notification when the virtual environment has not been created before running the python resource. This notification should not be blocking but we should do a check before any python resource starts using OnBeforeResourceStarted. The notification should point to an aka.ms link that explains how to configure python apps in aspire.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 16, 2025 08:19
- Add Location property to VirtualEnvironment class to expose venv path
- Add OnBeforeResourceStarted callback to check if virtual environment exists
- Show error notification when venv is missing using IInteractionService
- Skip check when IInteractionService is not available
- Skip check when using UV environment (WithUvEnvironment)
- Add comprehensive tests for notification scenarios
- Link to https://aka.ms/aspire/python for documentation

Co-authored-by: davidfowl <[email protected]>
Copilot AI changed the title [WIP] Add error notification for missing virtual environment Add virtual environment validation notification for Python resources Oct 16, 2025
Copilot AI requested a review from davidfowl October 16, 2025 08:47
Copilot finished work on behalf of davidfowl October 16, 2025 08:47
@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 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 -- 12086

Or

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

};

// Show notification without blocking (fire and forget)
_ = interactionService.PromptNotificationAsync(title, message, options, ct);
Copy link
Member

Choose a reason for hiding this comment

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

@davidfowl This will create a new prompt every time the resource is started even if a prompt is already visible. If there are multiple Python resources in this state, you'll get a separate prompt for each. It seems we really want this coalescing notification capability in the core so all these integrations don't need to keep implementing it?

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.

4 participants