Skip to content

Support debugging python modules, add flask, uvicorn debugging support, add DCP logging util - #12456

Merged
Adam Ratzman (adamint) merged 23 commits into
microsoft:mainfrom
adamint:dev/adamint/support-python-modules
Oct 29, 2025
Merged

Adam Ratzman (adamint) merged 23 commits into
microsoft:mainfrom
adamint:dev/adamint/support-python-modules

Conversation

@adamint

@adamint Adam Ratzman (adamint) commented Oct 28, 2025 •

Copy link
Copy Markdown
Member

Description

  • Adds additional DCP logging setting so that DCP logs can be sent when things go wrong, fixes cert issue
  • Adds AddGunicornApp which uses the flask dev server in development mode
  • Updates the python sample to add a uvicorn and flask app to test running modules
  • Removes AspireWithPython in favor of only the python playground app
  • Adds two fields to the IDE spec - interpreter_path and module - so that the IDE knows what to run and how to run it
  • Support flask and uvicorn (including FastAPI`) web servers in VS code
  • Support running arbitrary modules

Fixes #12062

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions

github-actions Bot commented Oct 28, 2025 •

Copy link
Copy Markdown
Contributor

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

Or

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

Comment thread .vscode/launch.json
"env": {
"ASPIRE_CLI_STOP_ON_ENTRY": "true"
},
"cwd": "${workspaceFolder}/extension"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added a bunch of configurations to make debugging the apphost & cli easier, which was used in testing this branch

Comment thread docs/specs/IDE-execution.md Outdated
|----------------|--------|-------|
| `type` | Launch configuration type indicator; must be `python`. | Required |
| `program_path` | Path to the python startup file. | Required |
| `interpreter_path` | Path to the python interpreter to use. | Optional |

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We need to use the python associated with the venv.

debugAdapter: string;
extensionId: string | null;
displayName: string;
getDisplayName: (launchConfig: ExecutableLaunchConfiguration) => string;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This will allow us to use additional launch configuration context in calculating a display name, ie we could note that the configuration is a module

}

// By default, activate support for Jinja debugging
debugConfiguration.jinja = true;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

env.ASPIRE_EXTENSION_CAPABILITIES = getSupportedCapabilities().join(',');

// if DCP debug logging is enabled, set DCP-specific logging environment variables
const dcpDebugLoggingEnabled = vscode.workspace.getConfiguration('aspire').get<boolean>('enableAspireDcpDebugLogging', false);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

DCP logs for a session will be put in ${workspaceRoot}/.aspire/dcp/logs-{session}. DCP's default logging is not sufficient to actually find issues most of the tim

@@ -1,30 +0,0 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",

@adamint Adam Ratzman (adamint) Oct 28, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We already have the python playground project, so let's remove this one

{
[JsonPropertyName("program_path")]
public string? ProgramPath { get; set; }
public string ProgramPath { get; set; } = string.Empty;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The convention for DCP-related types seems to be to avoid nullability.

c.Args.Add(endpoint.Property(EndpointProperty.TargetPort));

// Add hot reload in non-publish mode
if (!builder.ExecutionContext.IsPublishMode)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

resourceBuilder.WithEnvironment("FLASK_ENV", "development");
}

return resourceBuilder;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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


// VS Code debug support - only applicable for Script and Module types
if (entrypointType is EntrypointType.Script or EntrypointType.Module)
if (supportDebugging)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Executables can be run if they support being debugged as modules. AFAIK, this is most executables but I don't think we should make the assumption otherwise that all executables are by default debuggable.

@adamint Adam Ratzman (adamint) changed the title Support debugging python modules, add flask, uvicorn debugging support Support debugging python modules, add flask, uvicorn debugging support, add DCP logging util Oct 28, 2025
// Generate a positive serial number as a hexadecimal string
// X.509 RFC 5280 requires serial numbers to be positive integers up to 20 octets
// Prefix with '00' to ensure non-negative
cert.serialNumber = '00' + randomBytes(19).toString('hex');

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Noticed that every so often, serial numbers that were being generated were negative. DCP considers this fatal and will not use the IDE to launch if so. Ensures positive by prefixing with 00

@adamint
Adam Ratzman (adamint) marked this pull request as ready for review October 28, 2025 20:05
Copilot AI review requested due to automatic review settings October 28, 2025 20:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for Gunicorn-based WSGI applications (Flask) to Aspire's Python hosting, enhances Python debugging capabilities in the VS Code extension, and includes infrastructure improvements like DCP debug logging.

Key changes:

  • Added AddGunicornApp method that uses Gunicorn in production and Flask dev server in development
  • Enhanced Python debugger with interpreter path and module support
  • Added DCP debug logging configuration option
  • Improved certificate serial number generation for security

Reviewed Changes

Copilot reviewed 40 out of 44 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs Added AddGunicornApp method and new supportDebugging parameter to AddPythonExecutable
src/Aspire.Hosting.Python/PythonAppLaunchConfiguration.cs Added InterpreterPath property and changed nullable properties to non-nullable
src/Aspire.Hosting.Python/VirtualEnvironment.cs Added public VirtualEnvironmentPath property
tests/Aspire.Hosting.Python.Tests/AddGunicornAppTests.cs New test file for Gunicorn functionality
extension/src/debugger/languages/python.ts Enhanced Python debugger configuration with interpreter and module support
extension/src/utils/security.ts Improved certificate serial number generation
extension/src/utils/AspireTerminalProvider.ts Added DCP debug logging configuration
playground/python/flask_app/* New Flask playground application
playground/python/uvicorn_app/* New uvicorn playground application with telemetry

if (builder.ExecutionContext.IsPublishMode)
{
// Production: Use Gunicorn
resourceBuilder = builder.AddPythonExecutable(name, appDirectory, "gunicorn", true)

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

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

The hardcoded true for supportDebugging parameter is inconsistent with the development vs production branching logic. In production mode (IsPublishMode), debugging support should likely be false since Gunicorn is intended for production use. Consider: builder.AddPythonExecutable(name, appDirectory, \"gunicorn\", !builder.ExecutionContext.IsPublishMode)

Copilot uses AI. Check for mistakes.
Comment thread extension/src/utils/security.ts Resolved
public static IResourceBuilder<PythonAppResource> AddPythonExecutable(
this IDistributedApplicationBuilder builder, [ResourceName] string name, string appDirectory, string executableName)
=> AddPythonAppCore(builder, name, appDirectory, EntrypointType.Executable, executableName, DefaultVirtualEnvFolder);
this IDistributedApplicationBuilder builder, [ResourceName] string name, string appDirectory, string executableName, bool supportDebugging)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This new parameter feels wrong in the main AddPythonExecutable method. Would it be better if we just assumed it supports debugging, and then provide another method .WithoutDebugging or similar to remove it? That way everyone wouldn't need to think about this when using AddPythonExecutable

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe we reverse it and require .WithDebugging to enable debug support for an executable?

Comment on lines +351 to +352
.WithEnvironment("FLASK_APP", app)
.WithEnvironment("FLASK_ENV", "development")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if they aren't using Flask, but instead using Django?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Officially unsupported right now

@davidfowl

Copy link
Copy Markdown
Collaborator

/test-scenario smoke-test-python

@adamint

Copy link
Copy Markdown
Member Author

don’t merge yet

@mitchdenny Mitch Denny (mitchdenny) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved pending bug fix to interpreterPath logic.

@adamint

Copy link
Copy Markdown
Member Author

verified windows

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support python modules in VS code extension + formalize in ide spec

5 participants