Skip to content

Commit

Permalink
Apply feedback for the create env trigger prompts (#23258)
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored Apr 22, 2024
1 parent 577e64c commit 6aaca06
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 127 deletions.
22 changes: 4 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"stopOnEntry": false,
"smartStep": true,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*", "!${workspaceFolder}/**/node_modules**/*"],
Expand All @@ -31,19 +30,11 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}", "${workspaceFolder}/data"],
"stopOnEntry": false,
"smartStep": true,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*", "!${workspaceFolder}/**/node_modules**/*"],
"preLaunchTask": "Compile"
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Tests (Debugger, VS Code, *.test.ts)",
"type": "extensionHost",
Expand All @@ -55,7 +46,6 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"stopOnEntry": false,
"sourceMaps": true,
"smartStep": true,
"outFiles": ["${workspaceFolder}/out/**/*", "!${workspaceFolder}/**/node_modules**/*"],
Expand Down Expand Up @@ -83,7 +73,6 @@
"VSC_PYTHON_SMOKE_TEST": "1",
"TEST_FILES_SUFFIX": "smoke.test"
},
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
"preLaunchTask": "Compile",
Expand All @@ -103,7 +92,6 @@
"env": {
"VSC_PYTHON_CI_TEST_GREP": "" // Modify this to run a subset of the single workspace tests
},
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
"preLaunchTask": "Compile",
Expand All @@ -123,7 +111,6 @@
"env": {
"VSC_PYTHON_CI_TEST_GREP": "Language Server:"
},
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
"preLaunchTask": "preTestJediLSP",
Expand All @@ -140,7 +127,6 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"stopOnEntry": false,
"sourceMaps": true,
"smartStep": true,
"outFiles": ["${workspaceFolder}/out/**/*", "!${workspaceFolder}/**/node_modules**/*"],
Expand Down Expand Up @@ -236,19 +222,19 @@
"program": "${file}",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "pwa-node"
"type": "node"
},
{
"name": "Python: Current File",
"type": "python",
"type": "debugpy",
"justMyCode": true,
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}"
},
{
"name": "Listen",
"name": "Python: Attach Listen",
"type": "debugpy",
"request": "attach",
"listen": { "host": "localhost", "port": 5678 },
Expand All @@ -267,7 +253,7 @@
"compounds": [
{
"name": "Debug Test Discovery",
"configurations": ["Listen", "Extension"]
"configurations": ["Python: Attach Listen", "Extension"]
}
]
}
2 changes: 0 additions & 2 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,6 @@ export namespace CreateEnv {
'A virtual environment is not currently selected for your Python interpreter. Would you like to create a virtual environment?',
);
export const createEnvironment = l10n.t('Create');
export const disableCheck = l10n.t('Disable');
export const disableCheckWorkspace = l10n.t('Disable (Workspace)');

export const globalPipInstallTriggerMessage = l10n.t(
'You may have installed Python packages into your global environment, which can cause conflicts between package versions. Would you like to create a virtual environment to isolate your dependencies?',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PVSC_EXTENSION_ID } from '../../../common/constants';
import { PythonExtension } from '../../../api/types';
import { traceVerbose } from '../../../logging';
import { getConfiguration } from '../../../common/vscodeApis/workspaceApis';
import { getWorkspaceStateValue, updateWorkspaceStateValue } from '../../../common/persistentState';
import { getWorkspaceStateValue } from '../../../common/persistentState';

export const CREATE_ENV_TRIGGER_SETTING_PART = 'createEnvironment.trigger';
export const CREATE_ENV_TRIGGER_SETTING = `python.${CREATE_ENV_TRIGGER_SETTING_PART}`;
Expand Down Expand Up @@ -90,15 +90,6 @@ export function disableCreateEnvironmentTrigger(): void {
}
}

/**
* Sets trigger to 'off' in workspace persistent state. This disables trigger check
* for the current workspace only. In multi root case, it is disabled for all folders
* in the multi root workspace.
*/
export async function disableWorkspaceCreateEnvironmentTrigger(): Promise<void> {
await updateWorkspaceStateValue(CREATE_ENV_TRIGGER_SETTING, 'off');
}

let _alreadyCreateEnvCriteriaCheck = false;
/**
* Run-once wrapper function for the workspace check to prompt to create an environment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import {
shouldPromptToCreateEnv,
isCreateEnvWorkspaceCheckNotRun,
disableCreateEnvironmentTrigger,
disableWorkspaceCreateEnvironmentTrigger,
} from './common/createEnvTriggerUtils';
import { getWorkspaceFolder } from '../../common/vscodeApis/workspaceApis';
import { traceError, traceInfo, traceVerbose } from '../../logging';
import { hasPrefixCondaEnv, hasVenv } from './common/commonUtils';
import { showInformationMessage } from '../../common/vscodeApis/windowApis';
import { CreateEnv } from '../../common/utils/localize';
import { Common, CreateEnv } from '../../common/utils/localize';
import { executeCommand, registerCommand } from '../../common/vscodeApis/commandApis';
import { Commands } from '../../common/constants';
import { Resource } from '../../common/types';
Expand Down Expand Up @@ -77,8 +76,7 @@ async function createEnvironmentCheckForWorkspace(uri: Uri): Promise<void> {
const selection = await showInformationMessage(
CreateEnv.Trigger.workspaceTriggerMessage,
CreateEnv.Trigger.createEnvironment,
CreateEnv.Trigger.disableCheckWorkspace,
CreateEnv.Trigger.disableCheck,
Common.doNotShowAgain,
);

if (selection === CreateEnv.Trigger.createEnvironment) {
Expand All @@ -87,10 +85,8 @@ async function createEnvironmentCheckForWorkspace(uri: Uri): Promise<void> {
} catch (error) {
traceError('CreateEnv Trigger - Error while creating environment: ', error);
}
} else if (selection === CreateEnv.Trigger.disableCheck) {
} else if (selection === Common.doNotShowAgain) {
disableCreateEnvironmentTrigger();
} else if (selection === CreateEnv.Trigger.disableCheckWorkspace) {
disableWorkspaceCreateEnvironmentTrigger();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { CreateEnvOnPipInstallTrigger } from '../../common/experiments/groups';
import { inExperiment } from '../common/externalDependencies';
import {
disableCreateEnvironmentTrigger,
disableWorkspaceCreateEnvironmentTrigger,
isGlobalPythonSelected,
shouldPromptToCreateEnv,
} from './common/createEnvTriggerUtils';
import { getWorkspaceFolder, getWorkspaceFolders } from '../../common/vscodeApis/workspaceApis';
import { CreateEnv } from '../../common/utils/localize';
import { Common, CreateEnv } from '../../common/utils/localize';
import { traceError, traceInfo } from '../../logging';
import { executeCommand } from '../../common/vscodeApis/commandApis';
import { Commands, PVSC_EXTENSION_ID } from '../../common/constants';
Expand Down Expand Up @@ -46,8 +45,7 @@ export function registerTriggerForPipInTerminal(disposables: Disposable[]): void
const selection = await showWarningMessage(
CreateEnv.Trigger.globalPipInstallTriggerMessage,
CreateEnv.Trigger.createEnvironment,
CreateEnv.Trigger.disableCheckWorkspace,
CreateEnv.Trigger.disableCheck,
Common.doNotShowAgain,
);
if (selection === CreateEnv.Trigger.createEnvironment) {
try {
Expand All @@ -69,10 +67,8 @@ export function registerTriggerForPipInTerminal(disposables: Disposable[]): void
} catch (error) {
traceError('CreateEnv Trigger - Error while creating environment: ', error);
}
} else if (selection === CreateEnv.Trigger.disableCheck) {
} else if (selection === Common.doNotShowAgain) {
disableCreateEnvironmentTrigger();
} else if (selection === CreateEnv.Trigger.disableCheckWorkspace) {
disableWorkspaceCreateEnvironmentTrigger();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis';
import * as commandApis from '../../../client/common/vscodeApis/commandApis';
import { Commands } from '../../../client/common/constants';
import { CreateEnv } from '../../../client/common/utils/localize';
import { Common, CreateEnv } from '../../../client/common/utils/localize';

suite('Create Environment Trigger', () => {
let shouldPromptToCreateEnvStub: sinon.SinonStub;
Expand All @@ -29,7 +29,6 @@ suite('Create Environment Trigger', () => {
let getWorkspaceFolderStub: sinon.SinonStub;
let executeCommandStub: sinon.SinonStub;
let disableCreateEnvironmentTriggerStub: sinon.SinonStub;
let disableWorkspaceCreateEnvironmentTriggerStub: sinon.SinonStub;

const workspace1 = {
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace1')),
Expand All @@ -54,10 +53,6 @@ suite('Create Environment Trigger', () => {

executeCommandStub = sinon.stub(commandApis, 'executeCommand');
disableCreateEnvironmentTriggerStub = sinon.stub(triggerUtils, 'disableCreateEnvironmentTrigger');
disableWorkspaceCreateEnvironmentTriggerStub = sinon.stub(
triggerUtils,
'disableWorkspaceCreateEnvironmentTrigger',
);
});

teardown(() => {
Expand Down Expand Up @@ -208,7 +203,6 @@ suite('Create Environment Trigger', () => {

sinon.assert.notCalled(executeCommandStub);
sinon.assert.notCalled(disableCreateEnvironmentTriggerStub);
sinon.assert.notCalled(disableWorkspaceCreateEnvironmentTriggerStub);
});

test('Should show prompt if all conditions met: User clicks create', async () => {
Expand All @@ -232,18 +226,17 @@ suite('Create Environment Trigger', () => {

sinon.assert.calledOnceWithExactly(executeCommandStub, Commands.Create_Environment);
sinon.assert.notCalled(disableCreateEnvironmentTriggerStub);
sinon.assert.notCalled(disableWorkspaceCreateEnvironmentTriggerStub);
});

test('Should show prompt if all conditions met: User clicks disable global', async () => {
test("Should show prompt if all conditions met: User clicks don't show again", async () => {
shouldPromptToCreateEnvStub.returns(true);
hasVenvStub.resolves(false);
hasPrefixCondaEnvStub.resolves(false);
hasRequirementFilesStub.resolves(true);
hasKnownFilesStub.resolves(false);
isGlobalPythonSelectedStub.resolves(true);

showInformationMessageStub.resolves(CreateEnv.Trigger.disableCheck);
showInformationMessageStub.resolves(Common.doNotShowAgain);
await triggerCreateEnvironmentCheck(CreateEnvironmentCheckKind.Workspace, workspace1.uri);

sinon.assert.calledOnce(shouldPromptToCreateEnvStub);
Expand All @@ -256,30 +249,5 @@ suite('Create Environment Trigger', () => {

sinon.assert.notCalled(executeCommandStub);
sinon.assert.calledOnce(disableCreateEnvironmentTriggerStub);
sinon.assert.notCalled(disableWorkspaceCreateEnvironmentTriggerStub);
});

test('Should show prompt if all conditions met: User clicks disable workspace', async () => {
shouldPromptToCreateEnvStub.returns(true);
hasVenvStub.resolves(false);
hasPrefixCondaEnvStub.resolves(false);
hasRequirementFilesStub.resolves(true);
hasKnownFilesStub.resolves(false);
isGlobalPythonSelectedStub.resolves(true);

showInformationMessageStub.resolves(CreateEnv.Trigger.disableCheckWorkspace);
await triggerCreateEnvironmentCheck(CreateEnvironmentCheckKind.Workspace, workspace1.uri);

sinon.assert.calledOnce(shouldPromptToCreateEnvStub);
sinon.assert.calledOnce(hasVenvStub);
sinon.assert.calledOnce(hasPrefixCondaEnvStub);
sinon.assert.calledOnce(hasRequirementFilesStub);
sinon.assert.calledOnce(hasKnownFilesStub);
sinon.assert.calledOnce(isGlobalPythonSelectedStub);
sinon.assert.calledOnce(showInformationMessageStub);

sinon.assert.notCalled(executeCommandStub);
sinon.assert.notCalled(disableCreateEnvironmentTriggerStub);
sinon.assert.calledOnce(disableWorkspaceCreateEnvironmentTriggerStub);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as commandApis from '../../../client/common/vscodeApis/commandApis';
import * as extDepApi from '../../../client/pythonEnvironments/common/externalDependencies';
import { registerTriggerForPipInTerminal } from '../../../client/pythonEnvironments/creation/globalPipInTerminalTrigger';
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants';
import { CreateEnv } from '../../../client/common/utils/localize';
import { Common, CreateEnv } from '../../../client/common/utils/localize';

suite('Global Pip in Terminal Trigger', () => {
let shouldPromptToCreateEnvStub: sinon.SinonStub;
Expand All @@ -31,7 +31,6 @@ suite('Global Pip in Terminal Trigger', () => {
let showWarningMessageStub: sinon.SinonStub;
let executeCommandStub: sinon.SinonStub;
let disableCreateEnvironmentTriggerStub: sinon.SinonStub;
let disableWorkspaceCreateEnvironmentTriggerStub: sinon.SinonStub;
let onDidStartTerminalShellExecutionStub: sinon.SinonStub;
let handler: undefined | ((e: TerminalShellExecutionStartEvent) => Promise<void>);
let execEvent: typemoq.IMock<TerminalShellExecutionStartEvent>;
Expand Down Expand Up @@ -64,10 +63,6 @@ suite('Global Pip in Terminal Trigger', () => {
executeCommandStub.resolves({ path: 'some/python' });

disableCreateEnvironmentTriggerStub = sinon.stub(triggerUtils, 'disableCreateEnvironmentTrigger');
disableWorkspaceCreateEnvironmentTriggerStub = sinon.stub(
triggerUtils,
'disableWorkspaceCreateEnvironmentTrigger',
);

onDidStartTerminalShellExecutionStub = sinon.stub(windowApis, 'onDidStartTerminalShellExecution');
onDidStartTerminalShellExecutionStub.callsFake((cb) => {
Expand Down Expand Up @@ -270,16 +265,15 @@ suite('Global Pip in Terminal Trigger', () => {

sinon.assert.calledOnce(executeCommandStub);
sinon.assert.notCalled(disableCreateEnvironmentTriggerStub);
sinon.assert.notCalled(disableWorkspaceCreateEnvironmentTriggerStub);

shellIntegration.verify((s) => s.executeCommand(typemoq.It.isAnyString()), typemoq.Times.once());
});

test('Should disable create environment trigger if user selects to disable', async () => {
test("Should disable create environment trigger if user selects don't show again", async () => {
shouldPromptToCreateEnvStub.returns(true);
inExperimentStub.returns(true);
isGlobalPythonSelectedStub.returns(true);
showWarningMessageStub.resolves(CreateEnv.Trigger.disableCheck);
showWarningMessageStub.resolves(Common.doNotShowAgain);

const disposables: Disposable[] = [];
registerTriggerForPipInTerminal(disposables);
Expand Down Expand Up @@ -310,44 +304,5 @@ suite('Global Pip in Terminal Trigger', () => {

sinon.assert.notCalled(executeCommandStub);
sinon.assert.calledOnce(disableCreateEnvironmentTriggerStub);
sinon.assert.notCalled(disableWorkspaceCreateEnvironmentTriggerStub);
});

test('Should disable workspace create environment trigger if user selects to disable', async () => {
shouldPromptToCreateEnvStub.returns(true);
inExperimentStub.returns(true);
isGlobalPythonSelectedStub.returns(true);
showWarningMessageStub.resolves(CreateEnv.Trigger.disableCheckWorkspace);

const disposables: Disposable[] = [];
registerTriggerForPipInTerminal(disposables);

await handler?.({
terminal: ({} as unknown) as Terminal,
shellIntegration: shellIntegration.object,
execution: {
cwd: workspace1.uri,
commandLine: {
isTrusted: true,
value: 'pip install',
confidence: 0,
},
read: () =>
(async function* () {
yield Promise.resolve('pip install');
})(),
},
});

assert.strictEqual(disposables.length, 1);
sinon.assert.calledOnce(shouldPromptToCreateEnvStub);
sinon.assert.calledOnce(inExperimentStub);
sinon.assert.calledOnce(getWorkspaceFolderStub);
sinon.assert.calledOnce(isGlobalPythonSelectedStub);
sinon.assert.calledOnce(showWarningMessageStub);

sinon.assert.notCalled(executeCommandStub);
sinon.assert.notCalled(disableCreateEnvironmentTriggerStub);
sinon.assert.calledOnce(disableWorkspaceCreateEnvironmentTriggerStub);
});
});

0 comments on commit 6aaca06

Please sign in to comment.