Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73b5937

Browse files
authored
Don't prompt to update inheritEnv when on Windows (#7901)
* Don't prompt inheritEnv on windows * Add verification for undefined workspace config * Why did i commit that formatting change
1 parent 5288cbd commit 73b5937

File tree

4 files changed

+103
-11
lines changed

4 files changed

+103
-11
lines changed

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"Experiments.inGroup": "User belongs to experiment group '{0}'",
127127
"Interpreters.RefreshingInterpreters": "Refreshing Python Interpreters",
128128
"Interpreters.LoadingInterpreters": "Loading Python Interpreters",
129-
"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?",
129+
"Interpreters.condaInheritEnvMessage": "We noticed you're using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we recommend that you let the Python extension change \"terminal.integrated.inheritEnv\" to false in your user settings.",
130130
"Logging.CurrentWorkingDirectory": "cwd:",
131131
"Common.doNotShowAgain": "Do not show again",
132132
"Common.reload": "Reload",

src/client/common/utils/localize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export namespace Experiments {
6161
export namespace Interpreters {
6262
export const loading = localize('Interpreters.LoadingInterpreters', 'Loading Python Interpreters');
6363
export const refreshing = localize('Interpreters.RefreshingInterpreters', 'Refreshing Python Interpreters');
64-
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?');
64+
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 recommend that you let the Python extension change \"terminal.integrated.inheritEnv\" to false in your user settings.');
6565
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?');
6666
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');
6767
}

src/client/interpreter/virtualEnvs/condaInheritEnvPrompt.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ConfigurationTarget, Uri } from 'vscode';
66
import { IExtensionActivationService } from '../../activation/types';
77
import { IApplicationShell, IWorkspaceService } from '../../common/application/types';
88
import { traceDecorators, traceError } from '../../common/logger';
9+
import { IPlatformService } from '../../common/platform/types';
910
import { IBrowserService, IPersistentStateFactory } from '../../common/types';
1011
import { Common, InteractiveShiftEnterBanner, Interpreters } from '../../common/utils/localize';
1112
import { sendTelemetryEvent } from '../../telemetry';
@@ -22,8 +23,9 @@ export class CondaInheritEnvPrompt implements IExtensionActivationService {
2223
@inject(IBrowserService) private browserService: IBrowserService,
2324
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
2425
@inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory,
26+
@inject(IPlatformService) private readonly platformService: IPlatformService,
2527
@optional() public hasPromptBeenShownInCurrentSession: boolean = false
26-
) { }
28+
) {}
2729

2830
public async activate(resource: Uri): Promise<void> {
2931
this.initializeInBackground(resource).ignoreErrors();
@@ -65,6 +67,9 @@ export class CondaInheritEnvPrompt implements IExtensionActivationService {
6567
if (this.hasPromptBeenShownInCurrentSession) {
6668
return false;
6769
}
70+
if (this.platformService.isWindows) {
71+
return false;
72+
}
6873
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
6974
if (!interpreter || interpreter.type !== InterpreterType.Conda) {
7075
return false;

src/test/interpreters/virtualEnvs/condaInheritEnvPrompt.unit.test.ts

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as TypeMoq from 'typemoq';
1010
import { ConfigurationTarget, Uri, WorkspaceConfiguration } from 'vscode';
1111
import { IApplicationShell, IWorkspaceService } from '../../../client/common/application/types';
1212
import { PersistentStateFactory } from '../../../client/common/persistentState';
13+
import { IPlatformService } from '../../../client/common/platform/types';
1314
import { IBrowserService, IPersistentState, IPersistentStateFactory } from '../../../client/common/types';
1415
import { createDeferred, createDeferredFromPromise, sleep } from '../../../client/common/utils/async';
1516
import { Common, InteractiveShiftEnterBanner, Interpreters } from '../../../client/common/utils/localize';
@@ -24,6 +25,7 @@ suite('Conda Inherit Env Prompt', async () => {
2425
let workspaceService: TypeMoq.IMock<IWorkspaceService>;
2526
let appShell: TypeMoq.IMock<IApplicationShell>;
2627
let interpreterService: TypeMoq.IMock<IInterpreterService>;
28+
let platformService: TypeMoq.IMock<IPlatformService>;
2729
let browserService: TypeMoq.IMock<IBrowserService>;
2830
let persistentStateFactory: IPersistentStateFactory;
2931
let notificationPromptEnabled: TypeMoq.IMock<IPersistentState<any>>;
@@ -41,10 +43,26 @@ suite('Conda Inherit Env Prompt', async () => {
4143
browserService = TypeMoq.Mock.ofType<IBrowserService>();
4244
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
4345
persistentStateFactory = mock(PersistentStateFactory);
44-
condaInheritEnvPrompt = new CondaInheritEnvPrompt(interpreterService.object, workspaceService.object, browserService.object, appShell.object, instance(persistentStateFactory));
46+
platformService = TypeMoq.Mock.ofType<IPlatformService>();
47+
condaInheritEnvPrompt = new CondaInheritEnvPrompt(
48+
interpreterService.object,
49+
workspaceService.object,
50+
browserService.object,
51+
appShell.object,
52+
instance(persistentStateFactory),
53+
platformService.object
54+
);
4555
});
4656
test('Returns false if prompt has already been shown in the current session', async () => {
47-
condaInheritEnvPrompt = new CondaInheritEnvPrompt(interpreterService.object, workspaceService.object, browserService.object, appShell.object, instance(persistentStateFactory), true);
57+
condaInheritEnvPrompt = new CondaInheritEnvPrompt(
58+
interpreterService.object,
59+
workspaceService.object,
60+
browserService.object,
61+
appShell.object,
62+
instance(persistentStateFactory),
63+
platformService.object,
64+
true
65+
);
4866
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
4967
interpreterService
5068
.setup(is => is.getActiveInterpreter(resource))
@@ -59,11 +77,25 @@ suite('Conda Inherit Env Prompt', async () => {
5977
expect(condaInheritEnvPrompt.hasPromptBeenShownInCurrentSession).to.equal(true, 'Should be true');
6078
verifyAll();
6179
});
80+
test('Returns false if on Windows', async () => {
81+
platformService
82+
.setup(ps => ps.isWindows)
83+
.returns(() => true)
84+
.verifiable(TypeMoq.Times.once());
85+
const result = await condaInheritEnvPrompt.shouldShowPrompt(resource);
86+
expect(result).to.equal(false, 'Prompt should not be shown');
87+
expect(condaInheritEnvPrompt.hasPromptBeenShownInCurrentSession).to.equal(false, 'Should be false');
88+
verifyAll();
89+
});
6290
test('Returns false if active interpreter is not of type Conda', async () => {
6391
const interpreter = {
6492
type: InterpreterType.Pipenv
6593
};
6694
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
95+
platformService
96+
.setup(ps => ps.isWindows)
97+
.returns(() => false)
98+
.verifiable(TypeMoq.Times.once());
6799
interpreterService
68100
.setup(is => is.getActiveInterpreter(resource))
69101
.returns(() => Promise.resolve(interpreter) as any)
@@ -79,6 +111,10 @@ suite('Conda Inherit Env Prompt', async () => {
79111
});
80112
test('Returns false if no active interpreter is present', async () => {
81113
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
114+
platformService
115+
.setup(ps => ps.isWindows)
116+
.returns(() => false)
117+
.verifiable(TypeMoq.Times.once());
82118
interpreterService
83119
.setup(is => is.getActiveInterpreter(resource))
84120
.returns(() => Promise.resolve(undefined))
@@ -97,6 +133,10 @@ suite('Conda Inherit Env Prompt', async () => {
97133
type: InterpreterType.Conda
98134
};
99135
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
136+
platformService
137+
.setup(ps => ps.isWindows)
138+
.returns(() => false)
139+
.verifiable(TypeMoq.Times.once());
100140
interpreterService
101141
.setup(is => is.getActiveInterpreter(resource))
102142
.returns(() => Promise.resolve(interpreter) as any)
@@ -107,7 +147,8 @@ suite('Conda Inherit Env Prompt', async () => {
107147
.verifiable(TypeMoq.Times.once());
108148
workspaceConfig
109149
.setup(ws => ws.inspect<boolean>('integrated.inheritEnv'))
110-
.returns(() => undefined);
150+
.returns(() => undefined)
151+
.verifiable(TypeMoq.Times.once());
111152
const result = await condaInheritEnvPrompt.shouldShowPrompt(resource);
112153
expect(result).to.equal(false, 'Prompt should not be shown');
113154
expect(condaInheritEnvPrompt.hasPromptBeenShownInCurrentSession).to.equal(false, 'Should be false');
@@ -144,6 +185,10 @@ suite('Conda Inherit Env Prompt', async () => {
144185
type: InterpreterType.Conda
145186
};
146187
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
188+
platformService
189+
.setup(ps => ps.isWindows)
190+
.returns(() => false)
191+
.verifiable(TypeMoq.Times.once());
147192
interpreterService
148193
.setup(is => is.getActiveInterpreter(resource))
149194
.returns(() => Promise.resolve(interpreter) as any)
@@ -171,6 +216,10 @@ suite('Conda Inherit Env Prompt', async () => {
171216
workspaceFolderValue: undefined
172217
};
173218
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
219+
platformService
220+
.setup(ps => ps.isWindows)
221+
.returns(() => false)
222+
.verifiable(TypeMoq.Times.once());
174223
interpreterService
175224
.setup(is => is.getActiveInterpreter(resource))
176225
.returns(() => Promise.resolve(interpreter) as any)
@@ -196,6 +245,7 @@ suite('Conda Inherit Env Prompt', async () => {
196245
browserService = TypeMoq.Mock.ofType<IBrowserService>();
197246
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
198247
persistentStateFactory = mock(PersistentStateFactory);
248+
platformService = TypeMoq.Mock.ofType<IPlatformService>();
199249
});
200250

201251
teardown(() => {
@@ -206,7 +256,14 @@ suite('Conda Inherit Env Prompt', async () => {
206256
const initializeInBackgroundDeferred = createDeferred<void>();
207257
initializeInBackground = sinon.stub(CondaInheritEnvPrompt.prototype, 'initializeInBackground');
208258
initializeInBackground.callsFake(() => initializeInBackgroundDeferred.promise);
209-
condaInheritEnvPrompt = new CondaInheritEnvPrompt(interpreterService.object, workspaceService.object, browserService.object, appShell.object, instance(persistentStateFactory));
259+
condaInheritEnvPrompt = new CondaInheritEnvPrompt(
260+
interpreterService.object,
261+
workspaceService.object,
262+
browserService.object,
263+
appShell.object,
264+
instance(persistentStateFactory),
265+
platformService.object
266+
);
210267

211268
const promise = condaInheritEnvPrompt.activate(resource);
212269
const deferred = createDeferredFromPromise(promise);
@@ -223,7 +280,14 @@ suite('Conda Inherit Env Prompt', async () => {
223280
test('Ignores errors raised by initializeInBackground()', async () => {
224281
initializeInBackground = sinon.stub(CondaInheritEnvPrompt.prototype, 'initializeInBackground');
225282
initializeInBackground.rejects(new Error('Kaboom'));
226-
condaInheritEnvPrompt = new CondaInheritEnvPrompt(interpreterService.object, workspaceService.object, browserService.object, appShell.object, instance(persistentStateFactory));
283+
condaInheritEnvPrompt = new CondaInheritEnvPrompt(
284+
interpreterService.object,
285+
workspaceService.object,
286+
browserService.object,
287+
appShell.object,
288+
instance(persistentStateFactory),
289+
platformService.object
290+
);
227291
await condaInheritEnvPrompt.activate(resource);
228292
assert.ok(initializeInBackground.calledOnce);
229293
});
@@ -238,6 +302,7 @@ suite('Conda Inherit Env Prompt', async () => {
238302
browserService = TypeMoq.Mock.ofType<IBrowserService>();
239303
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
240304
persistentStateFactory = mock(PersistentStateFactory);
305+
platformService = TypeMoq.Mock.ofType<IPlatformService>();
241306
});
242307

243308
teardown(() => {
@@ -249,7 +314,14 @@ suite('Conda Inherit Env Prompt', async () => {
249314
shouldShowPrompt.callsFake(() => Promise.resolve(true));
250315
promptAndUpdate = sinon.stub(CondaInheritEnvPrompt.prototype, 'promptAndUpdate');
251316
promptAndUpdate.callsFake(() => Promise.resolve(undefined));
252-
condaInheritEnvPrompt = new CondaInheritEnvPrompt(interpreterService.object, workspaceService.object, browserService.object, appShell.object, instance(persistentStateFactory));
317+
condaInheritEnvPrompt = new CondaInheritEnvPrompt(
318+
interpreterService.object,
319+
workspaceService.object,
320+
browserService.object,
321+
appShell.object,
322+
instance(persistentStateFactory),
323+
platformService.object
324+
);
253325
await condaInheritEnvPrompt.initializeInBackground(resource);
254326
assert.ok(shouldShowPrompt.calledOnce);
255327
assert.ok(promptAndUpdate.calledOnce);
@@ -260,7 +332,14 @@ suite('Conda Inherit Env Prompt', async () => {
260332
shouldShowPrompt.callsFake(() => Promise.resolve(false));
261333
promptAndUpdate = sinon.stub(CondaInheritEnvPrompt.prototype, 'promptAndUpdate');
262334
promptAndUpdate.callsFake(() => Promise.resolve(undefined));
263-
condaInheritEnvPrompt = new CondaInheritEnvPrompt(interpreterService.object, workspaceService.object, browserService.object, appShell.object, instance(persistentStateFactory));
335+
condaInheritEnvPrompt = new CondaInheritEnvPrompt(
336+
interpreterService.object,
337+
workspaceService.object,
338+
browserService.object,
339+
appShell.object,
340+
instance(persistentStateFactory),
341+
platformService.object
342+
);
264343
await condaInheritEnvPrompt.initializeInBackground(resource);
265344
assert.ok(shouldShowPrompt.calledOnce);
266345
assert.ok(promptAndUpdate.notCalled);
@@ -276,8 +355,16 @@ suite('Conda Inherit Env Prompt', async () => {
276355
persistentStateFactory = mock(PersistentStateFactory);
277356
browserService = TypeMoq.Mock.ofType<IBrowserService>();
278357
notificationPromptEnabled = TypeMoq.Mock.ofType<IPersistentState<any>>();
358+
platformService = TypeMoq.Mock.ofType<IPlatformService>();
279359
when(persistentStateFactory.createGlobalPersistentState(condaInheritEnvPromptKey, true)).thenReturn(notificationPromptEnabled.object);
280-
condaInheritEnvPrompt = new CondaInheritEnvPrompt(interpreterService.object, workspaceService.object, browserService.object, appShell.object, instance(persistentStateFactory));
360+
condaInheritEnvPrompt = new CondaInheritEnvPrompt(
361+
interpreterService.object,
362+
workspaceService.object,
363+
browserService.object,
364+
appShell.object,
365+
instance(persistentStateFactory),
366+
platformService.object
367+
);
281368
});
282369

283370
test('Does not display prompt if it is disabled', async () => {

0 commit comments

Comments
 (0)