@@ -35,6 +35,7 @@ function extend(obj:{}, ...args) {
3535function getRandomInt ( ) {
3636 return Math . floor ( Math . random ( ) * 10000000000 ) ;
3737}
38+ const execPromise = promisify ( exec )
3839
3940export interface Options extends SpawnOptions {
4041 /**
@@ -235,6 +236,7 @@ export class PythonShell extends EventEmitter{
235236
236237 /**
237238 * checks syntax without executing code
239+ <<<<<<< HEAD
238240 * @returns {Promise } rejects w/ stderr if syntax failure
239241 */
240242 static async checkSyntax ( code :string ) {
@@ -253,12 +255,26 @@ export class PythonShell extends EventEmitter{
253255 static getPythonPath ( ) {
254256 return this . defaultOptions . pythonPath ? this . defaultOptions . pythonPath : this . defaultPythonPath ;
255257 }
258+ === === =
259+ * @returns rejects promise w / string error output if syntax failure
260+ * /
261+ static async checkSyntax ( code :string ) {
262+ let randomInt = PythonShell . getRandomInt ( ) ;
263+ let filePath = tmpdir ( ) + sep + `pythonShellSyntaxCheck${ randomInt } .py`
264+ 265+ const writeFilePromise = promisify ( writeFile )
266+ return writeFilePromise ( filePath , code ) . then ( ( ) => {
267+ return this . checkSyntaxFile ( filePath )
268+ } )
269+ }
270+ > >>> >>> checkSyntax now uses promises
256271
257272 /**
258273 * checks syntax without executing code
259274 * @returns {Promise } rejects w/ stderr if syntax failure
260275 */
261276 static async checkSyntaxFile ( filePath :string ) {
277+ < < < << << HEAD
262278
263279 const pythonPath = this. getPythonPath ( )
264280 const compileCommand = `${pythonPath } -m py_compile ${filePath } `
@@ -269,6 +285,10 @@ export class PythonShell extends EventEmitter{
269285 else reject ( stderr )
270286 } )
271287 } )
288+ === = ===
289+ let compileCommand = `${ this . defaultPythonPath } -m py_compile ${ filePath } `
290+ return execPromise ( compileCommand )
291+ >>> > >>> checkSyntax now uses promises
272292 }
273293
274294 /**
@@ -307,8 +327,12 @@ export class PythonShell extends EventEmitter{
307327 } ;
308328
309329 static getVersion ( pythonPath ?:string) {
330+ << < < < << HEAD
310331 if ( ! pythonPath ) pythonPath = this . getPythonPath ( )
311332 const execPromise = promisify ( exec )
333+ === = ===
334+ if ( ! pythonPath ) pythonPath = this . defaultPythonPath
335+ >>> > >>> checkSyntax now uses promises
312336 return execPromise ( pythonPath + " --version" ) ;
313337 }
314338
0 commit comments