@@ -235,7 +235,11 @@ export class PythonShell extends EventEmitter{
235
235
resolve ( this . checkSyntaxFile ( filePath ) ) ;
236
236
} ) ;
237
237
} ) ;
238
- }
238
+ }
239
+
240
+ static getPythonPath ( ) {
241
+ return this . defaultOptions . pythonPath ? this . defaultOptions . pythonPath : this . defaultPythonPath ;
242
+ }
239
243
240
244
/**
241
245
* checks syntax without executing code
@@ -244,12 +248,8 @@ export class PythonShell extends EventEmitter{
244
248
*/
245
249
static async checkSyntaxFile ( filePath :string ) {
246
250
247
- let pythonPath :string ;
248
- if ( this . defaultOptions . pythonPath ) {
249
- pythonPath = this . defaultOptions . pythonPath ;
250
- } else pythonPath = this . defaultPythonPath ;
251
-
252
- let compileCommand = `${ pythonPath } -m py_compile ${ filePath } `
251
+ const pythonPath = this . getPythonPath ( )
252
+ const compileCommand = `${ pythonPath } -m py_compile ${ filePath } `
253
253
254
254
return new Promise < string > ( ( resolve , reject ) => {
255
255
exec ( compileCommand , ( error , stdout , stderr ) => {
@@ -296,13 +296,13 @@ export class PythonShell extends EventEmitter{
296
296
} ;
297
297
298
298
static getVersion ( pythonPath ?:string ) {
299
- if ( ! pythonPath ) pythonPath = this . defaultPythonPath
299
+ if ( ! pythonPath ) pythonPath = this . getPythonPath ( )
300
300
const execPromise = promisify ( exec )
301
301
return execPromise ( pythonPath + " --version" ) ;
302
302
}
303
303
304
304
static getVersionSync ( pythonPath ?:string ) {
305
- if ( ! pythonPath ) pythonPath = this . defaultPythonPath
305
+ if ( ! pythonPath ) pythonPath = this . getPythonPath ( )
306
306
return execSync ( pythonPath + " --version" ) . toString ( )
307
307
}
308
308
0 commit comments