Skip to content

Commit 1077342

Browse files
Add flask debug config (#19536)
* Add get flask path function * Add flask provider * Make filter function async
1 parent 771fed0 commit 1077342

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/client/debugger/extension/configuration/dynamicdebugConfigurationService.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ export class DynamicPythonDebugConfigurationService implements IDynamicDebugConf
4545
});
4646
}
4747

48+
const flaskPath = await this.getFlaskPath(folder);
49+
if (flaskPath) {
50+
providers.push({
51+
name: 'Dynamic Python: Flask',
52+
type: DebuggerTypeName,
53+
request: 'launch',
54+
module: 'flask',
55+
env: {
56+
FLASK_APP: path.relative(folder.uri.fsPath, flaskPath),
57+
FLASK_ENV: 'development',
58+
},
59+
args: ['run', '--no-debugger'],
60+
jinja: true,
61+
justMyCode: true,
62+
});
63+
}
64+
4865
let fastApiPath = await this.getFastApiPath(folder);
4966
if (fastApiPath) {
5067
fastApiPath = path
@@ -74,6 +91,23 @@ export class DynamicPythonDebugConfigurationService implements IDynamicDebugConf
7491
private async getFastApiPath(folder: WorkspaceFolder) {
7592
const possiblePaths = await this.getPossiblePaths(folder, ['main.py', 'app.py', '*/main.py', '*/app.py']);
7693
const regExpression = /app\s*=\s*FastAPI\(/;
94+
const fastApiPaths = await asyncFilter(possiblePaths, async (possiblePath) =>
95+
regExpression.exec((await this.fs.readFile(possiblePath)).toString()),
96+
);
97+
98+
return fastApiPaths.length ? fastApiPaths[0] : null;
99+
}
100+
101+
private async getFlaskPath(folder: WorkspaceFolder) {
102+
const possiblePaths = await this.getPossiblePaths(folder, [
103+
'__init__.py',
104+
'app.py',
105+
'wsgi.py',
106+
'*/__init__.py',
107+
'*/app.py',
108+
'*/wsgi.py',
109+
]);
110+
const regExpression = /app(?:lication)?\s*=\s*(?:flask\.)?Flask\(|def\s+(?:create|make)_app\(/;
77111
const flaskPaths = await asyncFilter(possiblePaths, async (possiblePath) =>
78112
regExpression.exec((await this.fs.readFile(possiblePath)).toString()),
79113
);

0 commit comments

Comments
 (0)