Repository navigation
Support debugging python modules, add flask, uvicorn debugging support, add DCP logging util - #12456
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12456Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12456" |
| "env": { | ||
| "ASPIRE_CLI_STOP_ON_ENTRY": "true" | ||
| }, | ||
| "cwd": "${workspaceFolder}/extension" |
There was a problem hiding this comment.
I added a bunch of configurations to make debugging the apphost & cli easier, which was used in testing this branch
| |----------------|--------|-------| | ||
| | `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 | |
There was a problem hiding this comment.
We need to use the python associated with the venv.
| debugAdapter: string; | ||
| extensionId: string | null; | ||
| displayName: string; | ||
| getDisplayName: (launchConfig: ExecutableLaunchConfiguration) => string; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
| 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); |
There was a problem hiding this comment.
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", | |||
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
| resourceBuilder.WithEnvironment("FLASK_ENV", "development"); | ||
| } | ||
|
|
||
| return resourceBuilder; |
There was a problem hiding this comment.
FLASK_ENV and FLASK_APP come from: https://code.visualstudio.com/docs/python/debugging#_flask-debugging
|
|
||
| // VS Code debug support - only applicable for Script and Module types | ||
| if (entrypointType is EntrypointType.Script or EntrypointType.Module) | ||
| if (supportDebugging) |
There was a problem hiding this comment.
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.
| // 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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
AddGunicornAppmethod 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) |
There was a problem hiding this comment.
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)
| 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Maybe we reverse it and require .WithDebugging to enable debug support for an executable?
| .WithEnvironment("FLASK_APP", app) | ||
| .WithEnvironment("FLASK_ENV", "development") |
There was a problem hiding this comment.
What if they aren't using Flask, but instead using Django?
There was a problem hiding this comment.
Officially unsupported right now
|
/test-scenario smoke-test-python |
|
don’t merge yet |
Mitch Denny (mitchdenny)
left a comment
There was a problem hiding this comment.
Approved pending bug fix to interpreterPath logic.
…n but without python extension installed
|
verified windows |
Description
AddGunicornAppwhich uses the flask dev server in development modeAspireWithPythonin favor of only the python playground appinterpreter_pathandmodule- so that the IDE knows what to run and how to run itflaskanduvicorn(including FastAPI`) web servers in VS codeFixes #12062
Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplate