@@ -20,6 +20,7 @@ import { DebugProtocol } from 'vscode-debugprotocol';
2020import '../../client/common/extensions' ;
2121import { createDeferred , Deferred , sleep } from '../../utils/async' ;
2222import { noop } from '../../utils/misc' ;
23+ import { EXTENSION_ROOT_DIR } from '../common/constants' ;
2324import { isNotInstalledError } from '../common/helpers' ;
2425import { IFileSystem } from '../common/platform/types' ;
2526import { IProcessServiceFactory } from '../common/process/types' ;
@@ -123,11 +124,23 @@ export class PythonDebugger extends DebugSession {
123124 this . sendErrorResponse ( response , { format : message , id : 1 } , undefined , undefined , ErrorDestination . User ) ;
124125 } ) ;
125126 }
127+ /**
128+ * Checks the validity of the executable.
129+ * Do not use `<python> --version` as the output in 2.7 comes in stderr.
130+ * Do not use `<python> -c print('1')` as the executable could be pyspark.
131+ * Use `<python> xyz.py` to check output as this is absolutely necessary for debugger to start.
132+ * @private
133+ * @param {DebugProtocol.LaunchResponse } response
134+ * @param {LaunchRequestArguments } args
135+ * @returns {Promise<boolean> }
136+ * @memberof PythonDebugger
137+ */
126138 private async validatePythonPath ( response : DebugProtocol . LaunchResponse , args : LaunchRequestArguments ) : Promise < boolean > {
127139 const pythonPath = typeof args . pythonPath === 'string' && args . pythonPath . length > 0 ? args . pythonPath : 'python' ;
128140 const processFactory = this . serviceContainer . get < IProcessServiceFactory > ( IProcessServiceFactory ) ;
129141 const processService = await processFactory . create ( ) ;
130- const valid = await processService . exec ( pythonPath , [ '-c' , 'print("1")' ] )
142+ const pythonFile = path . join ( EXTENSION_ROOT_DIR , 'pythonFiles' , 'printOne.py' ) ;
143+ const valid = await processService . exec ( pythonPath , [ pythonFile ] )
131144 . then ( output => output . stdout . trim ( ) === '1' || ( output . stderr || '' ) . trim ( ) === '1' )
132145 . catch ( ( ) => false ) ;
133146 if ( ! valid ) {
0 commit comments