@@ -345,23 +345,11 @@ export const promptInstallVenv = (
345
345
if ( selection === DialogResponses . YES ) {
346
346
return installPythonVenv ( context , pythonExecutable ) ;
347
347
} else {
348
- return vscode . window
349
- . showInformationMessage (
350
- CONSTANTS . INFO . ARE_YOU_SURE ,
351
- DialogResponses . INSTALL_NOW ,
352
- DialogResponses . DONT_INSTALL
353
- )
354
- . then ( ( installChoice : vscode . MessageItem | undefined ) => {
355
- if ( installChoice === DialogResponses . INSTALL_NOW ) {
356
- return installPythonVenv ( context , pythonExecutable ) ;
357
- } else {
358
- // return an empty string, notifying the caller
359
- // that the user was unwilling to create venv
360
- // and by default, this will trigger the extension to
361
- // try using pythonExecutable
362
- return "" ;
363
- }
364
- } ) ;
348
+ // return pythonExecutable, notifying the caller
349
+ // that the user was unwilling to create venv
350
+ // and by default, this will trigger the extension to
351
+ // try using pythonExecutable
352
+ return pythonExecutable ;
365
353
}
366
354
} ) ;
367
355
} ;
@@ -410,22 +398,7 @@ export const installPythonVenv = async (
410
398
return pythonExecutable ;
411
399
}
412
400
413
- if ( ! ( await installDependencies ( context , pythonPath ) ) ) {
414
- vscode . window
415
- . showErrorMessage (
416
- `${ CONSTANTS . ERROR . DEPENDENCY_DOWNLOAD_ERROR } Using original interpreter at: ${ pythonExecutable } .` ,
417
- DialogResponses . READ_INSTALL_MD
418
- )
419
- . then ( ( selection : vscode . MessageItem | undefined ) => {
420
- if ( selection === DialogResponses . READ_INSTALL_MD ) {
421
- open ( CONSTANTS . LINKS . INSTALL ) ;
422
- }
423
- } ) ;
424
-
425
- return pythonExecutable ;
426
- }
427
-
428
- return pythonPath ;
401
+ return installDependenciesWrapper ( context , pythonPath , pythonExecutable ) ;
429
402
} ;
430
403
431
404
export const areDependenciesInstalled = async (
@@ -481,6 +454,30 @@ export const installDependencies = async (
481
454
}
482
455
} ;
483
456
457
+ export const installDependenciesWrapper = async (
458
+ context : vscode . ExtensionContext ,
459
+ pythonPath : string ,
460
+ backupPythonPath : string = ""
461
+ ) => {
462
+ let errMessage = CONSTANTS . ERROR . DEPENDENCY_DOWNLOAD_ERROR ;
463
+ if ( backupPythonPath !== "" ) {
464
+ errMessage = `${ errMessage } Using original interpreter at: ${ backupPythonPath } .` ;
465
+ }
466
+ if ( ! ( await installDependencies ( context , pythonPath ) ) ) {
467
+ vscode . window
468
+ . showErrorMessage (
469
+ CONSTANTS . ERROR . DEPENDENCY_DOWNLOAD_ERROR ,
470
+ DialogResponses . READ_INSTALL_MD
471
+ )
472
+ . then ( ( selection : vscode . MessageItem | undefined ) => {
473
+ if ( selection === DialogResponses . READ_INSTALL_MD ) {
474
+ open ( CONSTANTS . LINKS . INSTALL ) ;
475
+ }
476
+ } ) ;
477
+ return backupPythonPath ;
478
+ }
479
+ return pythonPath ;
480
+ } ;
484
481
export const getCurrentPythonExecutableName = async ( ) => {
485
482
let originalPythonExecutableName = "" ;
486
483
@@ -549,40 +546,22 @@ export const setupEnv = async (
549
546
let pythonExecutableName = originalPythonExecutableName ;
550
547
551
548
if ( ! ( await areDependenciesInstalled ( context , pythonExecutableName ) ) ) {
549
+ const pythonExecutableNameVenv = await getPythonVenv ( context ) ;
552
550
// environment needs to install dependencies
553
551
if ( ! ( await checkIfVenv ( context , pythonExecutableName ) ) ) {
554
- pythonExecutableName = await getPythonVenv ( context ) ;
555
552
if ( await hasVenv ( context ) ) {
556
553
// venv in extention exists with wrong dependencies
557
554
if (
558
555
! ( await areDependenciesInstalled (
559
556
context ,
560
- pythonExecutableName
557
+ pythonExecutableNameVenv
561
558
) )
562
559
) {
563
- if (
564
- ! ( await installDependencies (
565
- context ,
566
- pythonExecutableName
567
- ) )
568
- ) {
569
- vscode . window
570
- . showErrorMessage (
571
- `${ CONSTANTS . ERROR . DEPENDENCY_DOWNLOAD_ERROR } Using original interpreter at: ${ pythonExecutableName } .` ,
572
- DialogResponses . READ_INSTALL_MD
573
- )
574
- . then (
575
- ( selection : vscode . MessageItem | undefined ) => {
576
- if (
577
- selection ===
578
- DialogResponses . READ_INSTALL_MD
579
- ) {
580
- open ( CONSTANTS . LINKS . INSTALL ) ;
581
- }
582
- }
583
- ) ;
584
- return pythonExecutableName ;
585
- }
560
+ pythonExecutableName = await installDependenciesWrapper (
561
+ context ,
562
+ pythonExecutableNameVenv ,
563
+ pythonExecutableName
564
+ ) ;
586
565
}
587
566
} else {
588
567
pythonExecutableName = await promptInstallVenv (
@@ -591,8 +570,14 @@ export const setupEnv = async (
591
570
) ;
592
571
}
593
572
}
594
-
595
- if ( pythonExecutableName === originalPythonExecutableName ) {
573
+ if ( pythonExecutableName === pythonExecutableNameVenv ) {
574
+ vscode . window . showInformationMessage (
575
+ CONSTANTS . INFO . UPDATED_TO_EXTENSION_VENV
576
+ ) ;
577
+ vscode . workspace
578
+ . getConfiguration ( )
579
+ . update ( CONFIG . PYTHON_PATH , pythonExecutableName ) ;
580
+ } else if ( pythonExecutableName === originalPythonExecutableName ) {
596
581
// going with original interpreter, either because
597
582
// already in venv or error in creating custom venv
598
583
if ( checkConfig ( CONFIG . SHOW_DEPENDENCY_INSTALL ) ) {
@@ -607,47 +592,38 @@ export const setupEnv = async (
607
592
installChoice : vscode . MessageItem | undefined
608
593
) => {
609
594
if ( installChoice === DialogResponses . INSTALL_NOW ) {
610
- if (
611
- ! ( await installDependencies (
612
- context ,
613
- pythonExecutableName
614
- ) )
615
- ) {
616
- vscode . window
617
- . showErrorMessage (
618
- CONSTANTS . ERROR
619
- . DEPENDENCY_DOWNLOAD_ERROR ,
620
- DialogResponses . READ_INSTALL_MD
621
- )
622
- . then (
623
- (
624
- selection :
625
- | vscode . MessageItem
626
- | undefined
627
- ) => {
628
- if (
629
- selection ===
630
- DialogResponses . READ_INSTALL_MD
631
- ) {
632
- open (
633
- CONSTANTS . LINKS . INSTALL
634
- ) ;
635
- }
595
+ await installDependenciesWrapper (
596
+ context ,
597
+ pythonExecutableName
598
+ ) ;
599
+ } else {
600
+ await vscode . window
601
+ . showInformationMessage (
602
+ CONSTANTS . INFO . ARE_YOU_SURE ,
603
+ DialogResponses . INSTALL_NOW ,
604
+ DialogResponses . DONT_INSTALL
605
+ )
606
+ . then (
607
+ async (
608
+ installChoice2 :
609
+ | vscode . MessageItem
610
+ | undefined
611
+ ) => {
612
+ if (
613
+ installChoice2 ===
614
+ DialogResponses . INSTALL_NOW
615
+ ) {
616
+ await installDependenciesWrapper (
617
+ context ,
618
+ pythonExecutableName
619
+ ) ;
636
620
}
637
- ) ;
638
- return pythonExecutableName ;
639
- }
621
+ }
622
+ ) ;
640
623
}
641
624
}
642
625
) ;
643
626
}
644
- } else {
645
- vscode . window . showInformationMessage (
646
- CONSTANTS . INFO . UPDATED_TO_EXTENSION_VENV
647
- ) ;
648
- vscode . workspace
649
- . getConfiguration ( )
650
- . update ( CONFIG . PYTHON_PATH , pythonExecutableName ) ;
651
627
}
652
628
} else if ( needsResponse ) {
653
629
vscode . window . showInformationMessage (
0 commit comments