File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import {EOL as newline, tmpdir} from 'os';
44import { join , sep } from 'path'
55import { Readable , Writable } from 'stream'
66import { writeFile , writeFileSync } from 'fs' ;
7+ import { promisify } from 'util' ;
78
89function 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 ( )
Original file line number Diff line number Diff 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 ( )
You can’t perform that action at this time.
0 commit comments