Skip to content

Commit e8bb6f3

Browse files
Kartik Rajwesm
Kartik Raj
authored andcommitted
Temporarily expose PYTHONPATH for Pylance (microsoft/vscode-python#19899)
Done temporarily on request of Pylance so they can begin testing.
1 parent 9603b6d commit e8bb6f3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

extensions/positron-python/src/client/api.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
'use strict';
55

66
import { noop } from 'lodash';
7+
import { Uri, Event } from 'vscode';
78
import { IExtensionApi } from './apiTypes';
89
import { isTestExecution } from './common/constants';
910
import { IConfigurationService, Resource } from './common/types';
11+
import { IEnvironmentVariablesProvider } from './common/variables/types';
1012
import { getDebugpyLauncherArgs, getDebugpyPackagePath } from './debugger/extension/adapter/remoteLaunchers';
1113
import { IInterpreterService } from './interpreter/contracts';
1214
import { IServiceContainer, IServiceManager } from './ioc/types';
@@ -22,7 +24,17 @@ export function buildApi(
2224
const interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
2325
serviceManager.addSingleton<JupyterExtensionIntegration>(JupyterExtensionIntegration, JupyterExtensionIntegration);
2426
const jupyterIntegration = serviceContainer.get<JupyterExtensionIntegration>(JupyterExtensionIntegration);
25-
const api: IExtensionApi = {
27+
const envService = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
28+
const api: IExtensionApi & {
29+
/**
30+
* @deprecated Temporarily exposed for Pylance until we expose this API generally. Will be removed in an
31+
* iteration or two.
32+
*/
33+
pylance: {
34+
getPythonPathVar: (resource?: Uri) => Promise<string | undefined>;
35+
readonly onDidEnvironmentVariablesChange: Event<Uri | undefined>;
36+
};
37+
} = {
2638
// 'ready' will propagate the exception, but we must log it here first.
2739
ready: ready.catch((ex) => {
2840
traceError('Failure during activation.', ex);
@@ -65,6 +77,13 @@ export function buildApi(
6577
? jupyterIntegration.showDataViewer.bind(jupyterIntegration)
6678
: (noop as any),
6779
},
80+
pylance: {
81+
getPythonPathVar: async (resource?: Uri) => {
82+
const envs = await envService.getEnvironmentVariables(resource);
83+
return envs.PYTHONPATH;
84+
},
85+
onDidEnvironmentVariablesChange: envService.onDidEnvironmentVariablesChange,
86+
},
6887
};
6988

7089
// In test environment return the DI Container.

extensions/positron-python/src/test/api.functional.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { buildApi } from '../client/api';
1212
import { ConfigurationService } from '../client/common/configuration/service';
1313
import { EXTENSION_ROOT_DIR } from '../client/common/constants';
1414
import { IConfigurationService } from '../client/common/types';
15+
import { IEnvironmentVariablesProvider } from '../client/common/variables/types';
1516
import { IInterpreterService } from '../client/interpreter/contracts';
1617
import { InterpreterService } from '../client/interpreter/interpreterService';
1718
import { ServiceContainer } from '../client/ioc/container';
@@ -27,16 +28,21 @@ suite('Extension API', () => {
2728
let serviceManager: IServiceManager;
2829
let configurationService: IConfigurationService;
2930
let interpreterService: IInterpreterService;
31+
let environmentVariablesProvider: IEnvironmentVariablesProvider;
3032

3133
setup(() => {
3234
serviceContainer = mock(ServiceContainer);
3335
serviceManager = mock(ServiceManager);
3436
configurationService = mock(ConfigurationService);
3537
interpreterService = mock(InterpreterService);
38+
environmentVariablesProvider = mock<IEnvironmentVariablesProvider>();
3639

3740
when(serviceContainer.get<IConfigurationService>(IConfigurationService)).thenReturn(
3841
instance(configurationService),
3942
);
43+
when(serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider)).thenReturn(
44+
instance(environmentVariablesProvider),
45+
);
4046
when(serviceContainer.get<IInterpreterService>(IInterpreterService)).thenReturn(instance(interpreterService));
4147
});
4248

0 commit comments

Comments
 (0)