Skip to content

Commit 7e30acb

Browse files
authored
Auto select Python Interpreter prior to validation of interpreters (#3371)
For #3326
1 parent d987489 commit 7e30acb

13 files changed

Lines changed: 43 additions & 31 deletions

File tree

.github/test_plan.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
- Make sure that you do not have `python.pythonPath` specified in your `settings.json` when testing automatic detection
4545
- Do note that the `Select Interpreter` drop-down window scrolls
4646

47-
- [ ] Detected a single virtual environment at the top-level of the workspace folder (if you created this _after_ opening VS Code, then run `Reload Window` to pick up the new environment)
47+
- [ ] Detected a single virtual environment at the top-level of the workspace folder on Mac when when `python` command points to default Mac Python installation or `python` command fails in the terminal.
48+
- [ ] Appropriate suffix label specified in status bar (e.g. `(venv)`)
49+
- [ ] Detected a single virtual environment at the top-level of the workspace folder on Windows when `python` fails in the terminal.
50+
- [ ] Appropriate suffix label specified in status bar (e.g. `(venv)`)
51+
- [ ] Detected a single virtual environment at the top-level of the workspace folder
4852
- [ ] Appropriate suffix label specified in status bar (e.g. `(venv)`)
4953
- [ ] [`Create Terminal`](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) works
5054
- [ ] Steals focus

news/2 Fixes/3326.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Auto select `Python Interpreter` prior to validation of interpreters and changes to messages displayed.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"activationEvents": [
6464
"onLanguage:python",
6565
"onDebugResolve:python",
66-
"onDebugResolve:python",
6766
"onCommand:python.execInTerminal",
6867
"onCommand:python.sortImports",
6968
"onCommand:python.runtests",

package.nls.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,23 @@
8484
"DataScience.startingJupyter": "Starting Jupyter Server",
8585
"Interpreters.RefreshingInterpreters": "Refreshing Python Interpreters",
8686
"Interpreters.LoadingInterpreters": "Loading Python Interpreters",
87-
"DataScience.restartKernelMessage" : "Do you want to restart the Jupter kernel? All variables will be lost.",
88-
"DataScience.restartKernelMessageYes" : "Restart",
89-
"DataScience.restartKernelMessageNo" : "Cancel",
87+
"DataScience.restartKernelMessage": "Do you want to restart the Jupter kernel? All variables will be lost.",
88+
"DataScience.restartKernelMessageYes": "Restart",
89+
"DataScience.restartKernelMessageNo": "Cancel",
9090
"DataScienceSurveyBanner.bannerMessage": "Can you please take 2 minutes to tell us how the Python Data Science features are working for you?",
9191
"DataScienceSurveyBanner.bannerLabelYes": "Yes, take survey now",
9292
"DataScienceSurveyBanner.bannerLabelNo": "No, thanks",
93-
"DataScience.restartingKernelStatus" : "Restarting Jupyter Kernel",
94-
"DataScience.executingCode" : "Executing Cell",
95-
"DataScience.collapseAll" : "Collapse all cell inputs",
96-
"DataScience.expandAll" : "Expand all cell inputs",
97-
"DataScience.export" : "Export as Jupyter Notebook",
98-
"DataScience.restartServer" : "Restart iPython Kernel",
99-
"DataScience.undo" : "Undo",
100-
"DataScience.redo" : "Redo",
101-
"DataScience.clearAll" : "Remove All Cells",
102-
"DataScience.pythonVersionHeader" : "Python Version:",
103-
"DataScience.pythonVersionHeaderNoPyKernel" : "Python Version may not match, no ipykernel found:",
104-
"DataScience.pythonRestartHeader" : "Restarted Kernel:"
93+
"DataScience.restartingKernelStatus": "Restarting Jupyter Kernel",
94+
"DataScience.executingCode": "Executing Cell",
95+
"DataScience.collapseAll": "Collapse all cell inputs",
96+
"DataScience.expandAll": "Expand all cell inputs",
97+
"DataScience.export": "Export as Jupyter Notebook",
98+
"DataScience.restartServer": "Restart iPython Kernel",
99+
"DataScience.undo": "Undo",
100+
"DataScience.redo": "Redo",
101+
"DataScience.clearAll": "Remove All Cells",
102+
"DataScience.pythonVersionHeader": "Python Version:",
103+
"DataScience.pythonVersionHeaderNoPyKernel": "Python Version may not match, no ipykernel found:",
104+
"DataScience.pythonRestartHeader": "Restarted Kernel:",
105+
"Linter.InstalledButNotEnabled": "Linter {0} is installed but not enabled."
105106
}

src/client/activation/languageServer/languageServer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { PythonSettings } from '../../common/configSettings';
2020
// tslint:disable-next-line:ordered-imports
2121
import { isTestExecution, STANDARD_OUTPUT_CHANNEL } from '../../common/constants';
22+
import { Logger } from '../../common/logger';
2223
import { IFileSystem, IPlatformService } from '../../common/platform/types';
2324
import {
2425
BANNER_NAME_LS_SURVEY, DeprecatedFeatureInfo, IConfigurationService,
@@ -225,7 +226,7 @@ export class LanguageServerExtensionActivator implements IExtensionActivator {
225226
const interpreterDataService = new InterpreterDataService(this.context, this.services);
226227
interpreterData = await interpreterDataService.getInterpreterData();
227228
} catch (ex) {
228-
this.appShell.showWarningMessage('Unable to determine path to the Python interpreter. IntelliSense will be limited.');
229+
Logger.error('Unable to determine path to the Python interpreter. IntelliSense will be limited.', ex);
229230
}
230231

231232
this.interpreterHash = interpreterData ? interpreterData.hash : '';

src/client/common/utils/localize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export namespace Interpreters {
1919
export const refreshing = localize('Interpreters.RefreshingInterpreters', 'Refreshing Python Interpreters');
2020
}
2121

22+
export namespace Linters {
23+
export const installedButNotEnabled = localize('Linter.InstalledButNotEnabled', 'Linter {0} is installed but not enabled.');
24+
}
25+
2226
export namespace DataScienceSurveyBanner {
2327
export const bannerMessage = localize('DataScienceSurveyBanner.bannerMessage', 'Can you please take 2 minutes to tell us how the Python Data Science features are working for you?');
2428
export const bannerLabelYes = localize('DataScienceSurveyBanner.bannerLabelYes', 'Yes, take survey now');

src/client/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ export async function activate(context: ExtensionContext): Promise<IExtensionApi
7777
registerServices(context, serviceManager, serviceContainer);
7878
initializeServices(context, serviceManager, serviceContainer);
7979

80+
const interpreterManager = serviceContainer.get<IInterpreterService>(IInterpreterService);
81+
await interpreterManager.autoSetInterpreter();
82+
8083
// When testing, do not perform health checks, as modal dialogs can be displayed.
8184
if (!isTestExecution()) {
8285
const appDiagnostics = serviceContainer.get<IApplicationDiagnostics>(IApplicationDiagnostics);
8386
await appDiagnostics.performPreStartupHealthCheck();
8487
}
8588

86-
const interpreterManager = serviceContainer.get<IInterpreterService>(IInterpreterService);
87-
await interpreterManager.autoSetInterpreter();
88-
8989
serviceManager.get<ITerminalAutoActivation>(ITerminalAutoActivation).register();
9090
const configuration = serviceManager.get<IConfigurationService>(IConfigurationService);
9191
const pythonSettings = configuration.getSettings();

src/client/interpreter/contracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const IInterpreterLocatorService = Symbol('IInterpreterLocatorService');
2929

3030
export interface IInterpreterLocatorService extends Disposable {
3131
readonly onLocating: Event<Promise<PythonInterpreter[]>>;
32-
getInterpreters(resource?: Uri): Promise<PythonInterpreter[]>;
32+
getInterpreters(resource?: Uri, ignoreCache?: boolean): Promise<PythonInterpreter[]>;
3333
}
3434

3535
export type CondaInfo = {

src/client/interpreter/interpreterService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ export class InterpreterService implements Disposable, IInterpreterService {
6666
}
6767
// Check pipenv first.
6868
const pipenvService = this.serviceContainer.get<IInterpreterLocatorService>(IInterpreterLocatorService, PIPENV_SERVICE);
69-
let interpreters = await pipenvService.getInterpreters(activeWorkspace.folderUri);
69+
let interpreters = await pipenvService.getInterpreters(activeWorkspace.folderUri, true);
7070
if (interpreters.length > 0) {
7171
await this.pythonPathUpdaterService.updatePythonPath(interpreters[0].path, activeWorkspace.configTarget, 'load', activeWorkspace.folderUri);
7272
return;
7373
}
7474
// Now check virtual environments under the workspace root
7575
const virtualEnvInterpreterProvider = this.serviceContainer.get<IInterpreterLocatorService>(IInterpreterLocatorService, WORKSPACE_VIRTUAL_ENV_SERVICE);
76-
interpreters = await virtualEnvInterpreterProvider.getInterpreters(activeWorkspace.folderUri);
76+
interpreters = await virtualEnvInterpreterProvider.getInterpreters(activeWorkspace.folderUri, true);
7777
const workspacePathUpper = activeWorkspace.folderUri.fsPath.toUpperCase();
7878

7979
const interpretersInWorkspace = interpreters.filter(interpreter => Uri.file(interpreter.path).fsPath.toUpperCase().startsWith(workspacePathUpper));

src/client/interpreter/locators/services/cacheableLocatorService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export abstract class CacheableLocatorService implements IInterpreterLocatorServ
2929
return this.locating.event;
3030
}
3131
public abstract dispose();
32-
public async getInterpreters(resource?: Uri): Promise<PythonInterpreter[]> {
32+
public async getInterpreters(resource?: Uri, ignoreCache?: boolean): Promise<PythonInterpreter[]> {
3333
const cacheKey = this.getCacheKey(resource);
3434
let deferred = this.promisesPerResource.get(cacheKey);
3535

36-
if (!deferred) {
36+
if (!deferred || ignoreCache) {
3737
deferred = createDeferred<PythonInterpreter[]>();
3838
this.promisesPerResource.set(cacheKey, deferred);
3939

0 commit comments

Comments
 (0)