10000 Fix for running `pet` only in trusted workspaces (#24429) · microsoft/vscode-python@488401a · GitHub
[go: up one dir, main page]

Skip to content

Commit 488401a

Browse files
authored
Fix for running pet only in trusted workspaces (#24429)
Cherry picking fix for #24428
1 parent 7889127 commit 488401a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { EXTENSION_ROOT_DIR } from '../../../../constants';
1212
import { createDeferred, createDeferredFrom } from '../../../../common/utils/async';
1313
import { DisposableBase, DisposableStore } from '../../../../common/utils/resourceLifecycle';
1414
import { noop } from '../../../../common/utils/misc';
15-
import { getConfiguration, getWorkspaceFolderPaths } from '../../../../common/vscodeApis/workspaceApis';
15+
import { getConfiguration, getWorkspaceFolderPaths, isTrusted } from '../../../../common/vscodeApis/workspaceApis';
1616
import { CONDAPATH_SETTING_KEY } from '../../../common/environmentManagers/conda';
1717
import { VENVFOLDERS_SETTING_KEY, VENVPATH_SETTING_KEY } from '../lowLevel/customVirtualEnvLocator';
1818
import { getUserHomeDir } from '../../../../common/utils/platform';
@@ -22,6 +22,7 @@ import { NativePythonEnvironmentKind } from './nativePythonUtils';
2222
import type { IExtensionContext } from '../../../../common/types';
2323
import { StopWatch } from '../../../../common/utils/stopWatch';
2424
import { untildify } from '../../../../common/helpers';
25+
import { traceError } from '../../../../logging';
2526

2627
const PYTHON_ENV_TOOLS_PATH = isWindows()
2728
? path.join(EXTENSION_ROOT_DIR, 'python-env-tools', 'bin', 'pet.exe')
@@ -440,6 +441,25 @@ function getPythonSettingAndUntildify<T>(name: string, scope?: Uri): T | undefin
440441

441442
let _finder: NativePythonFinder | undefined;
442443
export function getNativePythonFinder(context?: IExtensionContext): NativePythonFinder {
444+
if (!isTrusted()) {
445+
return {
446+
async *refresh() {
447+
traceError('Python discovery not supported in untrusted workspace');
448+
yield* [];
449+
},
450+
async resolve() {
451+
traceError('Python discovery not supported in untrusted workspace');
452+
return {};
453+
},
454+
async getCondaInfo() {
455+
traceError('Python discovery not supported in untrusted workspace');
456+
return ({} as unknown) as NativeCondaInfo;
457+
},
458+
dispose() {
459+
// do nothing
460+
},
461+
};
462+
}
443463
if (!_finder) {
444464
const cacheDirectory = context ? getCacheDirectory(context) : undefined;
445465
_finder = new NativePythonFinderImpl(cacheDirectory);

0 commit comments

Comments
 (0)
0