@@ -45,6 +45,23 @@ export class DynamicPythonDebugConfigurationService implements IDynamicDebugConf
45
45
} ) ;
46
46
}
47
47
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
+
48
65
let fastApiPath = await this . getFastApiPath ( folder ) ;
49
66
if ( fastApiPath ) {
50
67
fastApiPath = path
@@ -74,6 +91,23 @@ export class DynamicPythonDebugConfigurationService implements IDynamicDebugConf
74
91
private async getFastApiPath ( folder : WorkspaceFolder ) {
75
92
const possiblePaths = await this . getPossiblePaths ( folder , [ 'main.py' , 'app.py' , '*/main.py' , '*/app.py' ] ) ;
76
93
const regExpression = / a p p \s * = \s * F a s t A P I \( / ;
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 = / a p p (?: l i c a t i o n ) ? \s * = \s * (?: f l a s k \. ) ? F l a s k \( | d e f \s + (?: c r e a t e | m a k e ) _ a p p \( / ;
77
111
const flaskPaths = await asyncFilter ( possiblePaths , async ( possiblePath ) =>
78
112
regExpression . exec ( ( await this . fs . readFile ( possiblePath ) ) . toString ( ) ) ,
79
113
) ;
0 commit comments