File tree 2 files changed +28
-3
lines changed
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 1
1
import * as fs from 'fs' ;
2
+ import * as path from 'path' ;
2
3
3
4
export function parseEnvFile ( envFile : string ) : any {
4
5
const buffer = fs . readFileSync ( envFile , 'utf8' ) ;
@@ -18,6 +19,19 @@ export function parseEnvFile(envFile: string): any {
18
19
19
20
export function mergeEnvVariables ( newVariables : { [ key : string ] : string } , mergeWith : any = process . env ) : any {
20
21
for ( let setting in mergeWith ) {
22
+ if ( setting === 'PYTHONPATH' ) {
23
+ let PYTHONPATH : string = newVariables [ 'PYTHONPATH' ] ;
24
+ if ( typeof PYTHONPATH !== 'string' ) {
25
+ PYTHONPATH = '' ;
26
+ }
27
+ if ( mergeWith [ 'PYTHONPATH' ] ) {
28
+ PYTHONPATH += ( PYTHONPATH . length > 0 ? + path . delimiter : '' ) + mergeWith [ 'PYTHONPATH' ] ;
29
+ }
30
+ if ( PYTHONPATH . length > 0 ) {
31
+ newVariables [ setting ] = PYTHONPATH ;
32
+ }
33
+ continue ;
34
+ }
21
35
if ( ! newVariables [ setting ] ) {
22
36
newVariables [ setting ] = mergeWith [ setting ] ;
23
37
}
Original file line number Diff line number Diff line change @@ -518,9 +518,20 @@ function onConfigChanged() {
518
518
getPathFromPythonCommand ( [ "-m" , "site" , "--user-site" ] ) ,
519
519
] ;
520
520
521
- const pythonPath : string = process . env [ 'PYTHONPATH' ] ;
522
- if ( typeof pythonPath === 'string' && pythonPath . length > 0 ) {
523
- filePaths . push ( Promise . resolve ( pythonPath . trim ( ) ) ) ;
521
+ let PYTHONPATH : string = process . env [ 'PYTHONPATH' ] ;
522
+ if ( typeof PYTHONPATH !== 'string' ) {
523
+ PYTHONPATH = '' ;
524
+ }
525
+ let customEnvironmentVars = getCustomEnvVars ( ) ;
526
+ if ( customEnvironmentVars && customEnvironmentVars [ 'PYTHONPATH' ] ) {
527
+ let PYTHONPATHFromEnvFile = customEnvironmentVars [ 'PYTHONPATH' ] as string ;
528
+ if ( ! path . isAbsolute ( PYTHONPATHFromEnvFile ) && typeof vscode . workspace . rootPath === 'string' ) {
529
+ PYTHONPATHFromEnvFile = path . resolve ( vscode . workspace . rootPath , PYTHONPATHFromEnvFile ) ;
530
+ }
531
+ PYTHONPATH += ( PYTHONPATH . length > 0 ? + path . delimiter : '' ) + PYTHONPATHFromEnvFile ;
532
+ }
533
+ if ( typeof PYTHONPATH === 'string' && PYTHONPATH . length > 0 ) {
534
+ filePaths . push ( Promise . resolve ( PYTHONPATH . trim ( ) ) ) ;
524
535
}
525
536
Promise . all < string > ( filePaths ) . then ( paths => {
526
537
// Last item return a path, we need only the folder
You can’t perform that action at this time.
0 commit comments