File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import * as fs from 'fs' ;
2+ import * as path from 'path' ;
23
34export function parseEnvFile ( envFile : string ) : any {
45 const buffer = fs . readFileSync ( envFile , 'utf8' ) ;
@@ -18,6 +19,19 @@ export function parseEnvFile(envFile: string): any {
1819
1920export function mergeEnvVariables ( newVariables : { [ key : string ] : string } , mergeWith : any = process . env ) : any {
2021 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+ }
2135 if ( ! newVariables [ setting ] ) {
2236 newVariables [ setting ] = mergeWith [ setting ] ;
2337 }
Original file line number Diff line number Diff line change @@ -518,9 +518,20 @@ function onConfigChanged() {
518518 getPathFromPythonCommand ( [ "-m" , "site" , "--user-site" ] ) ,
519519 ] ;
520520
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 ( ) ) ) ;
524535 }
525536 Promise . all < string > ( filePaths ) . then ( paths => {
526537 // Last item return a path, we need only the folder
You can’t perform that action at this time.
0 commit comments