Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1c04a2

Browse files
committed
fix #832
1 parent 1306f63 commit f1c04a2

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/client/common/envFileParser.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs';
2+
import * as path from 'path';
23

34
export function parseEnvFile(envFile: string): any {
45
const buffer = fs.readFileSync(envFile, 'utf8');
@@ -18,6 +19,19 @@ export function parseEnvFile(envFile: string): any {
1819

1920
export 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
}

src/client/providers/jediProxy.ts

+14-3
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)