Skip to content

Added prompt to flip "inheritEnv" setting to false to fix conda activation issue #7633

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

Merged
merged 7 commits into from
Oct 2, 2019
Merged
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
1 change: 1 addition & 0 deletions news/2 Fixes/7607.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added prompt to flip "inheritEnv" setting to false to fix conda activation issue
5 changes: 3 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"Experiments.inGroup": "User belongs to experiment group '{0}'",
"Interpreters.RefreshingInterpreters": "Refreshing Python Interpreters",
"Interpreters.LoadingInterpreters": "Loading Python Interpreters",
"Interpreters.condaInheritEnvMessage": "We noticed you're using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we suggest the \"terminal.integrated.inheritEnv\" setting to be changed to false. Would you like to update this setting?",
"Logging.CurrentWorkingDirectory": "cwd:",
"Common.doNotShowAgain": "Do not show again",
"Common.reload": "Reload",
Expand Down Expand Up @@ -367,6 +368,6 @@
"DataScience.untitledNotebookMessage": "Your changes will be lost if you don't save them.",
"DataScience.untitledNotebookYes": "Save",
"DataScience.untitledNotebookNo": "Cancel",
"DataScience.noInterpreter" : "No python selected",
"DataScience.notebookNotFound" : "python -m jupyter notebook --version is not running"
"DataScience.noInterpreter": "No python selected",
"DataScience.notebookNotFound": "python -m jupyter notebook --version is not running"
}
1 change: 1 addition & 0 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export namespace Experiments {
export namespace Interpreters {
export const loading = localize('Interpreters.LoadingInterpreters', 'Loading Python Interpreters');
export const refreshing = localize('Interpreters.RefreshingInterpreters', 'Refreshing Python Interpreters');
export const condaInheritEnvMessage = localize('Interpreters.condaInheritEnvMessage', 'We noticed you\'re using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we suggest the \"terminal.integrated.inheritEnv\" setting to be changed to false. Would you like to update this setting?');
export const environmentPromptMessage = localize('Interpreters.environmentPromptMessage', 'We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?');
export const selectInterpreterTip = localize('Interpreters.selectInterpreterTip', 'Tip: you can change the Python interpreter used by the Python extension by clicking on the Python version in the status bar');
}
Expand Down
2 changes: 2 additions & 0 deletions src/client/interpreter/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import { WindowsStoreInterpreter } from './locators/services/windowsStoreInterpr
import { WorkspaceVirtualEnvironmentsSearchPathProvider, WorkspaceVirtualEnvService } from './locators/services/workspaceVirtualEnvService';
import { WorkspaceVirtualEnvWatcherService } from './locators/services/workspaceVirtualEnvWatcherService';
import { IPipEnvServiceHelper, IPythonInPathCommandProvider } from './locators/types';
import { CondaInheritEnvPrompt } from './virtualEnvs/condaInheritEnvPrompt';
import { VirtualEnvironmentManager } from './virtualEnvs/index';
import { IVirtualEnvironmentManager } from './virtualEnvs/types';
import { VirtualEnvironmentPrompt } from './virtualEnvs/virtualEnvPrompt';
Expand Down Expand Up @@ -135,6 +136,7 @@ export function registerTypes(serviceManager: IServiceManager) {

serviceManager.addSingleton<IEnvironmentActivationService>(IEnvironmentActivationService, EnvironmentActivationService);

serviceManager.addSingleton<IExtensionActivationService>(IExtensionActivationService, CondaInheritEnvPrompt);
serviceManager.addSingleton<WindowsStoreInterpreter>(WindowsStoreInterpreter, WindowsStoreInterpreter);
serviceManager.addSingleton<InterpreterHashProvider>(InterpreterHashProvider, InterpreterHashProvider);
serviceManager.addSingleton<InterpeterHashProviderFactory>(InterpeterHashProviderFactory, InterpeterHashProviderFactory);
Expand Down
80 changes: 80 additions & 0 deletions src/client/interpreter/virtualEnvs/condaInheritEnvPrompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { inject, injectable, optional } from 'inversify';
import { ConfigurationTarget, Uri } from 'vscode';
import { IExtensionActivationService } from '../../activation/types';
import { IApplicationShell, IWorkspaceService } from '../../common/application/types';
import { traceDecorators, traceError } from '../../common/logger';
import { IPersistentStateFactory } from '../../common/types';
import { InteractiveShiftEnterBanner, Interpreters } from '../../common/utils/localize';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { IInterpreterService, InterpreterType } from '../contracts';

export const condaInheritEnvPromptKey = 'CONDA_INHERIT_ENV_PROMPT_KEY';

@injectable()
export class CondaInheritEnvPrompt implements IExtensionActivationService {
constructor(
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
@inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory,
@optional() public hasPromptBeenShownInCurrentSession: boolean = false
) { }

public async activate(resource: Uri): Promise<void> {
this.initializeInBackground(resource).ignoreErrors();
}

@traceDecorators.error('Failed to intialize conda inherit env prompt')
public async initializeInBackground(resource: Uri): Promise<void> {
const show = await this.shouldShowPrompt(resource);
if (!show) {
return;
}
await this.promptAndUpdate();
}

@traceDecorators.error('Failed to display conda inherit env prompt')
public async promptAndUpdate() {
const notificationPromptEnabled = this.persistentStateFactory.createGlobalPersistentState(condaInheritEnvPromptKey, true);
if (!notificationPromptEnabled.value) {
return;
}
const prompts = [InteractiveShiftEnterBanner.bannerLabelYes(), InteractiveShiftEnterBanner.bannerLabelNo()];
const telemetrySelections: ['Yes', 'No'] = ['Yes', 'No'];
const selection = await this.appShell.showInformationMessage(Interpreters.condaInheritEnvMessage(), ...prompts);
sendTelemetryEvent(EventName.CONDA_INHERIT_ENV_PROMPT, undefined, { selection: selection ? telemetrySelections[prompts.indexOf(selection)] : undefined });
if (!selection) {
return;
}
if (selection === prompts[0]) {
await this.workspaceService.getConfiguration('terminal').update('integrated.inheritEnv', false, ConfigurationTarget.Global);
} else if (selection === prompts[1]) {
await notificationPromptEnabled.updateValue(false);
}
}

@traceDecorators.error('Failed to check whether to display prompt for conda inherit env setting')
public async shouldShowPrompt(resource: Uri): Promise<boolean> {
if (this.hasPromptBeenShownInCurrentSession) {
return false;
}
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
if (!interpreter || interpreter.type !== InterpreterType.Conda) {
return false;
}
const setting = this.workspaceService.getConfiguration('terminal', resource).inspect<boolean>('integrated.inheritEnv');
if (!setting) {
traceError('WorkspaceConfiguration.inspect returns `undefined` for setting `terminal.integrated.inheritEnv`');
return false;
}
if (setting.globalValue !== undefined || setting.workspaceValue !== undefined || setting.workspaceFolderValue !== undefined) {
return false;
}
this.hasPromptBeenShownInCurrentSession = true;
return true;
}
}
1 change: 1 addition & 0 deletions src/client/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum EventName {
PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL = 'PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL',
TERMINAL_SHELL_IDENTIFICATION = 'TERMINAL_SHELL_IDENTIFICATION',
PYTHON_INTERPRETER_ACTIVATE_ENVIRONMENT_PROMPT = 'PYTHON_INTERPRETER_ACTIVATE_ENVIRONMENT_PROMPT',
CONDA_INHERIT_ENV_PROMPT = 'CONDA_INHERIT_ENV_PROMPT',
INSIDERS_RELOAD_PROMPT = 'INSIDERS_RELOAD_PROMPT',
INSIDERS_PROMPT = 'INSIDERS_PROMPT',
OPT_INTO_INSIDERS_AGAIN_PROMPT = 'OPT_INTO_INSIDERS_AGAIN_PROMPT',
Expand Down
11 changes: 11 additions & 0 deletions src/client/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,17 @@ export interface IEventNamePropertyMapping {
*/
interpreters?: number;
};
/**
* Telemetry event sent with details when user clicks the prompt with the following message
* `Prompt message` :- 'We noticed you're using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we suggest the "terminal.integrated.inheritEnv" setting to be changed to false. Would you like to update this setting?'
*/
[EventName.CONDA_INHERIT_ENV_PROMPT]: {
/**
* `Yes` When 'Yes' option is selected
* `No` When 'No' option is selected
*/
selection: 'Yes' | 'No' | undefined;
};
/**
* Telemetry event sent with details when user clicks a button in the virtual environment prompt.
* `Prompt message` :- 'We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?'
Expand Down
2 changes: 2 additions & 0 deletions src/test/interpreters/serviceRegistry.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { WorkspaceVirtualEnvWatcherService } from '../../client/interpreter/loca
import { IPipEnvServiceHelper, IPythonInPathCommandProvider } from '../../client/interpreter/locators/types';
import { registerTypes } from '../../client/interpreter/serviceRegistry';
import { VirtualEnvironmentManager } from '../../client/interpreter/virtualEnvs';
import { CondaInheritEnvPrompt } from '../../client/interpreter/virtualEnvs/condaInheritEnvPrompt';
import { IVirtualEnvironmentManager } from '../../client/interpreter/virtualEnvs/types';
import { VirtualEnvironmentPrompt } from '../../client/interpreter/virtualEnvs/virtualEnvPrompt';
import { ServiceManager } from '../../client/ioc/serviceManager';
Expand Down Expand Up @@ -142,6 +143,7 @@ suite('Interpreters - Service Registry', () => {
[IInterpreterAutoSelectionService, InterpreterAutoSelectionService],

[IEnvironmentActivationService, EnvironmentActivationService],
[IExtensionActivationService, CondaInheritEnvPrompt],

[WindowsStoreInterpreter, WindowsStoreInterpreter],
[InterpreterHashProvider, InterpreterHashProvider],
Expand Down
Loading