in src/debugging/python/PythonDebugHelper.ts [63:126]
public async resolveDebugConfiguration(context: DockerDebugContext, debugConfiguration: PythonDockerDebugConfiguration): Promise<ResolvedDebugConfiguration | undefined> {
const pyExt = await PythonExtensionHelper.getPythonExtension();
if (!pyExt) {
return undefined;
}
const containerName = inferContainerName(debugConfiguration, context, context.folder.name);
const projectType = debugConfiguration.python.projectType;
const pythonRunTaskOptions = (context.runDefinition as PythonRunTaskDefinition)?.python || {};
const dockerServerReadyAction =
resolveDockerServerReadyAction(
debugConfiguration,
{
containerName: containerName,
pattern: this.getServerReadyPattern(projectType),
uriFormat: '%s://localhost:%s'
},
true);
const args = [...(debugConfiguration.python.args || pythonRunTaskOptions.args || []), dockerExePath(context.actionContext), containerName];
const launcherPath = path.join(ext.context.asAbsolutePath('resources'), 'python', 'launcher.py');
return {
...{ ...debugConfiguration, python: undefined }, // Get the original debug configuration, minus the "python" property which belongs to the Docker launch config and confuses the Python extension
type: 'python',
request: 'launch',
pathMappings: debugConfiguration.python.pathMappings,
justMyCode: debugConfiguration.python.justMyCode ?? true,
django: debugConfiguration.python.django || projectType === 'django',
fastapi: debugConfiguration.python.fastapi || projectType === 'fastapi',
jinja: debugConfiguration.python.jinja || projectType === 'flask',
dockerOptions: {
containerName: containerName,
dockerServerReadyAction: dockerServerReadyAction,
removeContainerAfterDebug: debugConfiguration.removeContainerAfterDebug
},
debugLauncherPath: debugConfiguration.debugLauncherPath || launcherPath,
debugAdapterHost: debugConfiguration.debugAdapterHost || await this.getDebugAdapterHost(context) || '172.17.0.1', // 172.17.0.1 is the default gateway for the bridge network
console: debugConfiguration.console || "integratedTerminal",
internalConsoleOptions: debugConfiguration.internalConsoleOptions || "openOnSessionStart",
module: debugConfiguration.module || pythonRunTaskOptions.module,
program: debugConfiguration.file || pythonRunTaskOptions.file,
redirectOutput: debugConfiguration.redirectOutput as boolean | undefined ?? true,
args: args,
cwd: '.',
/* eslint-disable no-template-curly-in-string */
// These settings control what Python interpreter gets used in what circumstance.
// debugAdapterPython controls the interpreter used by the Python extension to start the debug adapter, on the local client
// We want it to use what it would normally use for local Python debugging, i.e. the chosen local interpreter
debugAdapterPython: '${command:python.interpreterPath}',
// debugLauncherPython controls the interpreter used by the debug adapter to start the launcher, also on the local client
// We want it to use what it would normally use for local Python debugging, i.e. the chosen local interpreter
// This actually launches our launcher in resources/python/launcher.py, which uses `docker exec -d <containerId> python3 /debugpy/launcher ...` to launch the real debugpy launcher in the container
debugLauncherPython: '${command:python.interpreterPath}',
/* eslint-enable no-template-curly-in-string */
// python controls the interpreter used by the launcher to start the application itself
// Since this is in the container it should always use `python3`
python: 'python3',
};
}