Skip to content

Commit f855c11

Browse files
Cleanup
1 parent 06fc5bb commit f855c11

4 files changed

Lines changed: 21 additions & 61 deletions

File tree

src/extension/debugger/configuration/dynamicdebugConfigurationService.ts

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import * as path from 'path';
88
import { CancellationToken, DebugConfiguration, WorkspaceFolder } from 'vscode';
99
import { IDynamicDebugConfigurationService } from '../types';
1010
import { DebuggerTypeName } from '../../constants';
11-
import { getDjangoPaths, getFastApiPaths, getFlaskPaths, isFastApiCliAvailable } from './utils/configuration';
11+
import { getDjangoPaths, getFastApiPaths, getFlaskPaths } from './utils/configuration';
1212
import { sendTelemetryEvent } from '../../telemetry';
1313
import { EventName } from '../../telemetry/constants';
14-
import { replaceAll } from '../../common/stringUtils';
1514

1615
const workspaceFolderToken = '${workspaceFolder}';
1716

@@ -64,38 +63,22 @@ export class DynamicPythonDebugConfigurationService implements IDynamicDebugConf
6463

6564
const fastApiPaths = await getFastApiPaths(folder);
6665
if (fastApiPaths?.length) {
67-
const hasFastApiCli = await isFastApiCliAvailable(folder.uri);
68-
if (hasFastApiCli) {
69-
providers.push({
70-
name: 'Python Debugger: FastAPI',
71-
type: DebuggerTypeName,
72-
request: 'launch',
73-
module: 'fastapi',
74-
args: ['dev'],
75-
jinja: true,
76-
subProcess: true,
77-
});
78-
providers.push({
79-
name: 'Python Debugger: FastAPI File',
80-
type: DebuggerTypeName,
81-
request: 'launch',
82-
module: 'fastapi',
83-
args: ['dev', '${file}'],
84-
jinja: true,
85-
subProcess: true,
86-
});
87-
} else {
88-
// Legacy fallback when fastapi-cli is not available.
89-
const fastApiPath = replaceAll(path.relative(folder.uri.fsPath, fastApiPaths[0].fsPath), path.sep, '.').replace('.py', '');
90-
providers.push({
91-
name: 'Python Debugger: FastAPI',
92-
type: DebuggerTypeName,
93-
request: 'launch',
94-
module: 'uvicorn',
95-
args: [`${fastApiPath}:app`, '--reload'],
96-
jinja: true,
97-
});
98-
}
66+
providers.push({
67+
name: 'Python Debugger: FastAPI',
68+
type: DebuggerTypeName,
69+
request: 'launch',
70+
module: 'fastapi',
71+
args: ['run'],
72+
jinja: true,
73+
});
74+
providers.push({
75+
name: 'Python Debugger: FastAPI File',
76+
type: DebuggerTypeName,
77+
request: 'launch',
78+
module: 'fastapi',
79+
args: ['run', '${file}'],
80+
jinja: true,
81+
});
9982
}
10083

10184
sendTelemetryEvent(EventName.DEBUGGER_DYNAMIC_CONFIGURATION, undefined, { providers: providers });

src/extension/debugger/configuration/providers/fastapiLaunch.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ export async function buildFastAPILaunchDebugConfiguration(
2020
type: DebuggerTypeName,
2121
request: 'launch',
2222
module: 'fastapi',
23-
args: ['dev'],
23+
args: ['run'],
2424
jinja: true,
25-
subProcess: true,
2625
};
2726
sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, {
2827
configurationType: DebugConfigurationType.launchFastAPI,
@@ -39,9 +38,8 @@ export async function buildFastAPIWithFileLaunchDebugConfiguration(
3938
type: DebuggerTypeName,
4039
request: 'launch',
4140
module: 'fastapi',
42-
args: ['dev', '${file}'],
41+
args: ['run', '${file}'],
4342
jinja: true,
44-
subProcess: true,
4543
};
4644
sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, {
4745
configurationType: DebugConfigurationType.launchFastAPIWithFile,

src/extension/debugger/configuration/utils/configuration.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ import { AttachRequestArguments } from '../../../types';
1515
import { DebugConfigurationState, DebugConfigurationType } from '../../types';
1616
import { Uri, WorkspaceFolder, workspace } from 'vscode';
1717
import { asyncFilter } from '../../../common/utilities';
18-
import { getInterpreterDetails } from '../../../common/python';
19-
import { plainExec } from '../../../common/process/rawProcessApis';
2018

2119
const defaultPort = 5678;
22-
const fastApiCliCache = new Map<string, Promise<boolean>>();
2320

2421
export async function configurePort(
2522
input: MultiStepInput<DebugConfigurationState>,
@@ -84,22 +81,6 @@ export async function getFastApiPaths(folder: WorkspaceFolder | undefined) {
8481
return fastApiPaths;
8582
}
8683

87-
export async function isFastApiCliAvailable(resource?: Uri): Promise<boolean> {
88-
const interpreterDetails = await getInterpreterDetails(resource);
89-
const pythonPath = interpreterDetails?.path?.[0];
90-
if (!pythonPath) {
91-
return false;
92-
}
93-
if (fastApiCliCache.has(pythonPath)) {
94-
return fastApiCliCache.get(pythonPath)!;
95-
}
96-
const promise = plainExec(pythonPath, ['-c', 'import fastapi_cli'], { throwOnStdErr: false })
97-
.then(() => true)
98-
.catch(() => false);
99-
fastApiCliCache.set(pythonPath, promise);
100-
return promise;
101-
}
102-
10384
export async function getFlaskPaths(folder: WorkspaceFolder | undefined) {
10485
if (!folder) {
10586
return [];

src/test/unittest/configuration/providers/fastapiLaunch.unit.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ suite('Debugging - Configuration Provider FastAPI', () => {
3131
type: DebuggerTypeName,
3232
request: 'launch',
3333
module: 'fastapi',
34-
args: ['dev'],
34+
args: ['run'],
3535
jinja: true,
36-
subProcess: true,
3736
};
3837

3938
expect(state.config).to.be.deep.equal(config);
@@ -50,9 +49,8 @@ suite('Debugging - Configuration Provider FastAPI', () => {
5049
type: DebuggerTypeName,
5150
request: 'launch',
5251
module: 'fastapi',
53-
args: ['dev', '${file}'],
52+
args: ['run', '${file}'],
5453
jinja: true,
55-
subProcess: true,
5654
};
5755

5856
expect(state.config).to.be.deep.equal(config);

0 commit comments

Comments
 (0)