@@ -288,7 +288,9 @@ class PythonFinder {
288
288
) } " to get Python executable path`
289
289
)
290
290
291
- const result = await check . checkFunc . apply ( this , [ check ? check . arg : null ] )
291
+ const result = await check . checkFunc . apply ( this , [
292
+ check ? check . arg : null
293
+ ] )
292
294
fail = false
293
295
this . succeed ( result . path , result . version )
294
296
@@ -324,7 +326,10 @@ class PythonFinder {
324
326
}
325
327
326
328
return new Promise ( ( resolve , reject ) => {
327
- this . run ( exec , args , shell ) . then ( this . checkExecPath ) . then ( resolve ) . catch ( reject )
329
+ this . run ( exec , args , shell )
330
+ . then ( this . checkExecPath )
331
+ . then ( resolve )
332
+ . catch ( reject )
328
333
} )
329
334
}
330
335
@@ -361,6 +366,7 @@ class PythonFinder {
361
366
// to pass both path and version
362
367
return new Promise ( ( resolve , reject ) => {
363
368
this . log . verbose ( `- executing "${ execPath } " to get version` )
369
+
364
370
this . run ( execPath , this . argsVersion , false )
365
371
. then ( ( ver ) => {
366
372
// ? may be better code for version check
@@ -392,9 +398,11 @@ class PythonFinder {
392
398
colorizeOutput ( RED , 'THIS VERSION OF PYTHON IS NOT SUPPORTED' )
393
399
)
394
400
// object with error passed for conveniences
395
- // (becouse we can also pass stderr or some additional staff )
401
+ // (becouse we may want to pass also stderr or some additional stuff )
396
402
// eslint-disable-next-line prefer-promise-reject-errors
397
- reject ( { err : new Error ( `Found unsupported Python version ${ ver } ` ) } )
403
+ reject ( {
404
+ err : new Error ( `Found unsupported Python version ${ ver } ` )
405
+ } )
398
406
}
399
407
400
408
resolve ( { path : execPath , version : ver } )
@@ -422,6 +430,7 @@ class PythonFinder {
422
430
function ( resolve , reject ) {
423
431
const env = extend ( { } , this . env )
424
432
env . TERM = 'dumb'
433
+ /** @type cp.ExecFileOptionsWithStringEncoding */
425
434
const opts = { env : env , shell : shell }
426
435
427
436
this . log . verbose (
@@ -434,24 +443,27 @@ class PythonFinder {
434
443
)
435
444
this . log . silly ( 'execFile: opts = ' , JSON . stringify ( opts , null , 2 ) )
436
445
437
- //* assume that user use utf8 compatible termnal
438
-
439
- //* prosible outcomes with error messages (err.message, error.stack, stderr)
440
- //! on windows:
446
+ //* prosible outcomes with error messages on windows (err.message, error.stack?, stderr)
441
447
// issue of encoding (garbage in terminal ) when 866 or any other locale code
442
448
// page is setted
443
449
// possible solutions:
444
- // use "cmd" command with flag "/U" and "/C" (for more informatiom help cmd)
450
+ // 1. let it be as it is and just warn user that it should use utf8
451
+ // (already done in this.catchErros's info statement)
452
+ // 2. somehow determine user's terminal encdoing and use utils.TextDecoder
453
+ // with getting raw buffer from execFile.
454
+ // Requires to correct error.message becouse garbage persists there
455
+ // 3. Forse user's terminal to use utf8 encoding via e.g. run "chcp 65001". May broke some user's programs
456
+ // 4. use "cmd" command with flag "/U" and "/C" (for more informatiom run "help cmd")
445
457
// which "Causes the output of
446
- // internal commands to a pipe or file to be Unicode" (utf16le)
447
- //* note: find-python-script.py send output in utf8 then may become necessary
448
- //* to reencoded string with Buffer.from(stderr).toString() or something
458
+ // internal commands ... to be Unicode" (utf16le)
459
+ //* note: find-python-script.py already send output in utf8 then may become necessary
460
+ //* to reencode string with Buffer.from(stderr).toString() or something
449
461
//* similar (if needed)
450
- // for this solution all args should be passed as SINGLE string in quotes
451
- // becouse cmd has such signature: CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF]
452
- // [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string]
462
+ // for this solution all execFile call should look like execFile("cmd /U /C", [command to run, arg1, arg2, ...])
453
463
//* all pathes/commands and each argument must be in quotes becouse if they have
454
- //* spaces they will broke everything
464
+ //* spaces inside they will broke everything
465
+
466
+ //* assume that user use utf8 compatible terminal
455
467
this . execFile ( exec , args , opts , execFileCallback . bind ( this ) )
456
468
457
469
/**
@@ -470,7 +482,7 @@ class PythonFinder {
470
482
if ( err || stderr ) {
471
483
reject ( { err : err || null , stderr : stderr || null } )
472
484
} else {
473
- // trim function removing endings which couse bugs when comparing strings
485
+ // trim() function remove string endings that break string comparsion
474
486
const stdoutTrimed = stdout . trim ( )
475
487
resolve ( stdoutTrimed )
476
488
}
@@ -526,7 +538,9 @@ class PythonFinder {
526
538
this . log . silly ( err ? err . stack : '' )
527
539
528
540
if ( stderr ) {
529
- this . addLog ( `${ colorizeOutput ( RED , 'STDERR:' ) } ${ stderr ? stderr . trim ( ) : '' } ` )
541
+ this . addLog (
542
+ `${ colorizeOutput ( RED , 'STDERR:' ) } ${ stderr ? stderr . trim ( ) : '' } `
543
+ )
530
544
}
531
545
}
532
546
this . addLog ( '--------------------------------------------' )
@@ -563,7 +577,8 @@ class PythonFinder {
563
577
// X
564
578
const info = [
565
579
'**********************************************************' ,
566
- 'If you have non-displayed characters set "UTF-8" encoding.' ,
580
+ 'If you have non-displayed characters, please set "UTF-8"' ,
581
+ 'encoding.' ,
567
582
'You need to install the latest version of Python.' ,
568
583
'Node-gyp should be able to find and use Python. If not,' ,
569
584
'you can try one of the following options:' ,
0 commit comments