Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use env variables from python extension #379

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/common/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ export function checkVersion(resolved: ResolvedEnvironment | undefined): boolean
traceError('Supported versions are 3.7 and above.');
return false;
}

export async function getPythonEnvVariables(resource?: Uri): Promise<NodeJS.ProcessEnv> {
const api = await getPythonExtensionAPI();
const newEnv = { ...process.env };
const pythonEnv = api?.environments.getEnvironmentVariables(resource);
return { ...newEnv, ...pythonEnv };
}
6 changes: 3 additions & 3 deletions src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as fsapi from 'fs-extra';
import { Disposable, env, LogOutputChannel } from 'vscode';
import { Disposable, env, LogOutputChannel, Uri } from 'vscode';
import { State } from 'vscode-languageclient';
import {
LanguageClient,
Expand All @@ -12,7 +12,7 @@ import {
} from 'vscode-languageclient/node';
import { DEBUG_SERVER_SCRIPT_PATH, SERVER_SCRIPT_PATH } from './constants';
import { traceError, traceInfo, traceVerbose } from './logging';
import { getDebuggerPath } from './python';
import { getDebuggerPath, getPythonEnvVariables } from './python';
import {
getExtensionSettings,
getGlobalSettings,
Expand All @@ -35,7 +35,7 @@ async function createServer(
const cwd = settings.cwd;

// Set debugger path needed for debugging python code.
const newEnv = { ...process.env };
const newEnv = await getPythonEnvVariables(Uri.parse(settings.workspace));
const debuggerPath = await getDebuggerPath();
const isDebugScript = await fsapi.pathExists(DEBUG_SERVER_SCRIPT_PATH);
if (newEnv.USE_DEBUGPY && debuggerPath) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { ConfigurationChangeEvent, ConfigurationScope, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
import { ConfigurationChangeEvent, ConfigurationScope, Uri, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
import { traceLog } from './logging';
import { getInterpreterDetails } from './python';
import { getConfiguration, getWorkspaceFolders } from './vscodeapi';
Expand Down Expand Up @@ -164,7 +164,7 @@ export async function getGlobalSettings(namespace: string, includeInterpreter?:

const setting = {
cwd: process.cwd(),
workspace: process.cwd(),
workspace: Uri.file(process.cwd()).toString(),
args: getGlobalValue<string[]>(config, 'args', []),
severity: getGlobalValue<Record<string, string>>(config, 'severity', DEFAULT_SEVERITY),
path: getGlobalValue<string[]>(config, 'path', []),
Expand Down
Loading