Skip to content

Commit 5ac31c2

Browse files
committed
adding getVersion w/ promise
1 parent 3fb3078 commit 5ac31c2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {EOL as newline, tmpdir} from 'os';
44
import {join, sep} from 'path'
55
import {Readable,Writable} from 'stream'
66
import { writeFile, writeFileSync } from 'fs';
7+
import { promisify } from 'util';
78

89
function toArray<T>(source?:T|T[]):T[] {
910
if (typeof source === 'undefined' || source === null) {
@@ -290,6 +291,12 @@ export class PythonShell extends EventEmitter{
290291
return PythonShell.run(filePath, options, callback);
291292
};
292293

294+
static getVersion(pythonPath?:string){
295+
if(!pythonPath) pythonPath = this.defaultPythonPath
296+
const execPromise = promisify(exec)
297+
return execPromise(pythonPath + " --version");
298+
}
299+
293300
static getVersionSync(pythonPath?:string){
294301
if(!pythonPath) pythonPath = this.defaultPythonPath
295302
return execSync(pythonPath + " --version").toString()

test/test-python-shell.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ describe('PythonShell', function () {
7878
})
7979
})
8080

81+
describe("#getVersion", function(){
82+
it('should return a string', function(done){
83+
PythonShell.getVersion().then((out)=>{
84+
const version = out.stdout
85+
version.should.be.a.String();
86+
version.length.should.be.greaterThan(0)
87+
done()
88+
})
89+
})
90+
})
91+
8192
describe("#getVersionSync", function(){
8293
it('should return a string', function(){
8394
const version = PythonShell.getVersionSync()

0 commit comments

Comments
 (0)