Skip to content

Commit 933a787

Browse files
committed
refactor python path logic to generic function
1 parent a5725f6 commit 933a787

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ export class PythonShell extends EventEmitter{
235235
resolve(this.checkSyntaxFile(filePath));
236236
});
237237
});
238-
}
238+
}
239+
240+
static getPythonPath(){
241+
return this.defaultOptions.pythonPath ? this.defaultOptions.pythonPath : this.defaultPythonPath;
242+
}
239243

240244
/**
241245
* checks syntax without executing code
@@ -244,12 +248,8 @@ export class PythonShell extends EventEmitter{
244248
*/
245249
static async checkSyntaxFile(filePath:string){
246250

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}`
253253

254254
return new Promise<string>((resolve, reject) => {
255255
exec(compileCommand, (error, stdout, stderr) => {
@@ -296,13 +296,13 @@ export class PythonShell extends EventEmitter{
296296
};
297297

298298
static getVersion(pythonPath?:string){
299-
if(!pythonPath) pythonPath = this.defaultPythonPath
299+
if(!pythonPath) pythonPath = this.getPythonPath()
300300
const execPromise = promisify(exec)
301301
return execPromise(pythonPath + " --version");
302302
}
303303

304304
static getVersionSync(pythonPath?:string){
305-
if(!pythonPath) pythonPath = this.defaultPythonPath
305+
if(!pythonPath) pythonPath = this.getPythonPath()
306306
return execSync(pythonPath + " --version").toString()
307307
}
308308

0 commit comments

Comments
 (0)