From fd81e555da354231a1b8bec557b180280033d9e8 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 26 Mar 2018 12:01:24 -0700 Subject: [PATCH 1/3] :sparkles: django and flask debugging --- package.json | 36 ++++++++++++++++--- src/client/debugger/Common/Contracts.ts | 4 +-- .../debugger/DebugClients/LocalDebugClient.ts | 11 ++++-- src/client/debugger/Main.ts | 2 +- .../configProviders/pythonV2Provider.ts | 6 +++- .../debugger/configProvider/provider.test.ts | 16 +++++++++ 6 files changed, 63 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 62ca582bcf96..132ce0adfcc5 100644 --- a/package.json +++ b/package.json @@ -363,7 +363,7 @@ ], "debugOptions": [ "RedirectOutput", - "DjangoDebugging" + "Django" ] } }, @@ -515,7 +515,7 @@ "RedirectOutput", "DebugStdLib", "BreakOnSystemExitZero", - "DjangoDebugging", + "Django", "Sudo", "IgnoreDjangoTemplateWarnings", "Pyramid" @@ -663,7 +663,7 @@ ], "debugOptions": [ "RedirectOutput", - "DjangoDebugging" + "Django" ] }, { @@ -781,9 +781,35 @@ "runserver", "--noreload", "--nothreading" + ], + "debugOptions": [ + "RedirectOutput", + "Django" ] } }, + { + "label": "Python Experimental: Flask", + "description": "%python.snippet.launch.flask.description%", + "body": { + "name": "Flask", + "type": "python", + "request": "launch", + "module": "flask", + "env": { + "FLASK_APP": "^\"\\${workspaceFolder}/app.py\"" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "debugOptions": [ + "RedirectOutput", + "Flask" + ] + } + }, { "label": "Python Experimental: PySpark", "description": "%python.snippet.launch.pyspark.description%", @@ -903,8 +929,8 @@ "enum": [ "RedirectOutput", "DebugStdLib", - "DjangoDebugging", - "FlaskDebugging", + "Django", + "Flask", "Sudo", "Pyramid" ] diff --git a/src/client/debugger/Common/Contracts.ts b/src/client/debugger/Common/Contracts.ts index 0d82722dc6ca..4aa5540c9784 100644 --- a/src/client/debugger/Common/Contracts.ts +++ b/src/client/debugger/Common/Contracts.ts @@ -33,8 +33,8 @@ export enum DebugOptions { WaitOnAbnormalExit = 'WaitOnAbnormalExit', WaitOnNormalExit = 'WaitOnNormalExit', RedirectOutput = 'RedirectOutput', - DjangoDebugging = 'DjangoDebugging', - FlaskDebugging = 'FlaskDebugging', + Django = 'Django', + Flask = 'Flask', DebugStdLib = 'DebugStdLib', BreakOnSystemExitZero = 'BreakOnSystemExitZero', Sudo = 'Sudo', diff --git a/src/client/debugger/DebugClients/LocalDebugClient.ts b/src/client/debugger/DebugClients/LocalDebugClient.ts index fd366af2412f..5697c3978a59 100644 --- a/src/client/debugger/DebugClients/LocalDebugClient.ts +++ b/src/client/debugger/DebugClients/LocalDebugClient.ts @@ -21,7 +21,8 @@ const VALID_DEBUG_OPTIONS = [ 'RedirectOutput', 'DebugStdLib', 'BreakOnSystemExitZero', - 'DjangoDebugging']; + 'DjangoDebugging', + 'Django']; enum DebugServerStatus { Unknown = 1, @@ -163,12 +164,16 @@ export class LocalDebugClient extends DebugClient { } // tslint:disable-next-line:member-ordering protected buildLauncherArguments(): string[] { - const vsDebugOptions = [DebugOptions.RedirectOutput]; + const vsDebugOptions: string[] = [DebugOptions.RedirectOutput]; if (Array.isArray(this.args.debugOptions)) { this.args.debugOptions.filter(opt => VALID_DEBUG_OPTIONS.indexOf(opt) >= 0) .forEach(item => vsDebugOptions.push(item)); } - + const djangoIndex = vsDebugOptions.indexOf(DebugOptions.Django); + // PTVSD expects the string `DjangoDebugging` + if (djangoIndex >= 0) { + vsDebugOptions[djangoIndex] = 'DjangoDebugging'; + } const programArgs = Array.isArray(this.args.args) && this.args.args.length > 0 ? this.args.args : []; if (typeof this.args.module === 'string' && this.args.module.length > 0) { return [vsDebugOptions.join(','), '-m', this.args.module].concat(programArgs); diff --git a/src/client/debugger/Main.ts b/src/client/debugger/Main.ts index 69f46e3f0326..190330501a52 100644 --- a/src/client/debugger/Main.ts +++ b/src/client/debugger/Main.ts @@ -332,7 +332,7 @@ export class PythonDebugger extends LoggingDebugSession { let isDjangoFile = false; if (this.launchArgs && Array.isArray(this.launchArgs.debugOptions) && - this.launchArgs.debugOptions.indexOf(DebugOptions.DjangoDebugging) >= 0) { + this.launchArgs.debugOptions.indexOf(DebugOptions.Django) >= 0) { isDjangoFile = filePath.toUpperCase().endsWith(".HTML"); } diff --git a/src/client/debugger/configProviders/pythonV2Provider.ts b/src/client/debugger/configProviders/pythonV2Provider.ts index f9d124d95e0e..36d91ba73a01 100644 --- a/src/client/debugger/configProviders/pythonV2Provider.ts +++ b/src/client/debugger/configProviders/pythonV2Provider.ts @@ -19,11 +19,15 @@ export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvide super.provideDefaults(workspaceFolder, debugConfiguration); debugConfiguration.stopOnEntry = false; + debugConfiguration.debugOptions = Array.isArray(debugConfiguration.debugOptions) ? debugConfiguration.debugOptions : []; // Add PTVSD specific flags. if (this.serviceContainer.get(IPlatformService).isWindows) { - debugConfiguration.debugOptions = Array.isArray(debugConfiguration.debugOptions) ? debugConfiguration.debugOptions : []; debugConfiguration.debugOptions.push(DebugOptions.FixFilePathCase); } + if (debugConfiguration.module && debugConfiguration.module.toUpperCase() === 'FLASK' + && debugConfiguration.debugOptions.indexOf(DebugOptions.Flask) === -1) { + debugConfiguration.debugOptions.push(DebugOptions.Flask); + } } } diff --git a/src/test/debugger/configProvider/provider.test.ts b/src/test/debugger/configProvider/provider.test.ts index ebe4a0ffbdfe..628eba9676da 100644 --- a/src/test/debugger/configProvider/provider.test.ts +++ b/src/test/debugger/configProvider/provider.test.ts @@ -342,5 +342,21 @@ import { IServiceContainer } from '../../../client/ioc/types'; test('Program is set to executable name for Pyramid when python exec does not exist (Mac)', async () => { await testPyramidConfiguration(false, false, true, true, false, true); }); + test('Auto detect flask debugging', async () => { + if (provider.debugType === 'python') { + return; + } + const pythonPath = `PythonPath_${new Date().toString()}`; + const workspaceFolder = createMoqWorkspaceFolder(__dirname); + const pythonFile = 'xyz.py'; + setupIoc(pythonPath); + setupActiveEditor(pythonFile, PythonLanguage.language); + + const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { module: 'flask' } as any as DebugConfiguration); + + expect(debugConfig).to.have.property('debugOptions'); + expect((debugConfig as any).debugOptions).contains(DebugOptions.RedirectOutput); + expect((debugConfig as any).debugOptions).contains(DebugOptions.Flask); + }); }); }); From d1569d61d481d6dfd93293629b009eb093b3bc7e Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 26 Mar 2018 12:02:57 -0700 Subject: [PATCH 2/3] :memo: change log --- news/1 Enhancements/1189.md | 1 + news/1 Enhancements/1190.md | 1 + news/3 Code Health/1198.md | 1 + 3 files changed, 3 insertions(+) create mode 100644 news/1 Enhancements/1189.md create mode 100644 news/1 Enhancements/1190.md create mode 100644 news/3 Code Health/1198.md diff --git a/news/1 Enhancements/1189.md b/news/1 Enhancements/1189.md new file mode 100644 index 000000000000..6d306e55189c --- /dev/null +++ b/news/1 Enhancements/1189.md @@ -0,0 +1 @@ +Add support for Django Template debugging in experimental debugger. diff --git a/news/1 Enhancements/1190.md b/news/1 Enhancements/1190.md new file mode 100644 index 000000000000..a1b144662fa5 --- /dev/null +++ b/news/1 Enhancements/1190.md @@ -0,0 +1 @@ +Add support for Flask Template debugging in experimental debugger. diff --git a/news/3 Code Health/1198.md b/news/3 Code Health/1198.md new file mode 100644 index 000000000000..b14083165f25 --- /dev/null +++ b/news/3 Code Health/1198.md @@ -0,0 +1 @@ +Change `DjangoDebugging` to `Django` in `debugOptions` of launch.json. From ba8cec509be811fd4fbbc45c594336cc4ae6d3f0 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 26 Mar 2018 14:26:12 -0700 Subject: [PATCH 3/3] Update to contain flask as default debug config [skip ci] --- package.json | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 132ce0adfcc5..c59ad5dfcea9 100644 --- a/package.json +++ b/package.json @@ -793,7 +793,7 @@ "description": "%python.snippet.launch.flask.description%", "body": { "name": "Flask", - "type": "python", + "type": "pythonExperimental", "request": "launch", "module": "flask", "env": { @@ -809,7 +809,7 @@ "Flask" ] } - }, + }, { "label": "Python Experimental: PySpark", "description": "%python.snippet.launch.pyspark.description%", @@ -983,6 +983,28 @@ "runserver", "--noreload", "--nothreading" + ], + "debugOptions": [ + "RedirectOutput", + "Django" + ] + }, + { + "label": "Python Experimental: Flask", + "type": "pythonExperimental", + "request": "launch", + "module": "flask", + "env": { + "FLASK_APP": "${workspaceFolder}/app.py" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "debugOptions": [ + "RedirectOutput", + "Flask" ] }, {