forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure Python environment defined in
python.defaultInterpreterPath
…
…is returned via discovery API (#22389) Closes #22268 Even when it is not the active interpreter for any workspace, it's still a known environment which users could consider selecting.
- Loading branch information
Kartik Raj
authored
Oct 31, 2023
1 parent
7aefb21
commit 473de33
Showing
6 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/client/pythonEnvironments/base/locators/lowLevel/customWorkspaceLocator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { PythonEnvKind } from '../../info'; | ||
import { BasicEnvInfo, IPythonEnvsIterator } from '../../locator'; | ||
import { FSWatchingLocator } from './fsWatchingLocator'; | ||
import { getPythonSetting, onDidChangePythonSetting } from '../../../common/externalDependencies'; | ||
import '../../../../common/extensions'; | ||
import { traceVerbose } from '../../../../logging'; | ||
import { DEFAULT_INTERPRETER_SETTING } from '../../../../common/constants'; | ||
|
||
export const DEFAULT_INTERPRETER_PATH_SETTING_KEY = 'defaultInterpreterPath'; | ||
|
||
/** | ||
* Finds and resolves custom virtual environments that users have provided. | ||
*/ | ||
export class CustomWorkspaceLocator extends FSWatchingLocator { | ||
public readonly providerId: string = 'custom-workspace-locator'; | ||
|
||
constructor(private readonly root: string) { | ||
super( | ||
() => [], | ||
async () => PythonEnvKind.Unknown, | ||
); | ||
} | ||
|
||
protected async initResources(): Promise<void> { | ||
this.disposables.push( | ||
onDidChangePythonSetting(DEFAULT_INTERPRETER_PATH_SETTING_KEY, () => this.fire(), this.root), | ||
); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
protected doIterEnvs(): IPythonEnvsIterator<BasicEnvInfo> { | ||
const iterator = async function* (root: string) { | ||
traceVerbose('Searching for custom workspace envs'); | ||
const filename = getPythonSetting<string>(DEFAULT_INTERPRETER_PATH_SETTING_KEY, root); | ||
if (!filename || filename === DEFAULT_INTERPRETER_SETTING) { | ||
// If the user has not set a custom interpreter, our job is done. | ||
return; | ||
} | ||
yield { kind: PythonEnvKind.Unknown, executablePath: filename }; | ||
traceVerbose(`Finished searching for custom workspace envs`); | ||
}; | ||
return iterator(this.root); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters